|
hi,
Here the senario is you want to check whether any of the string which is there in your first array exists on second array.
upto my level best i didn't found any keyword 'exists' in C#.
You can do this logic insted of your logic.
foreach(string Str in ab)
{
foreach(string Str2 in bc)
{
if(Str.Equals(Str2))
Console.WriteLine("String Found");
else
continue;
}
}
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Thanks for the reply. i had done something very similar to this previously (i did if( Str == Str2) in the same format. what happens, though is that if you have 4 objects in each array, it returns 16 results, 3/4 12, etc. what i am attempting to do is a comaprison of the two, and for any matches, print "yes", and for any that are in one strin but not the other, print "no". for example:
string 1 is red*blue*yellow*green*black
string 2 is green*red*blue*pink
the results i am looking for are
red = yes
green = yes
blue = yes
pink = no
black = no
in regards to your other post, i hit the tab key when typing the original message and accidentally made a gibberish post.
Yes, I am the highly suggestable type.
|
|
|
|
|
hi,
I gave the idea and now you are asking for logic. We won't encourage developers by giving logic. It is upto you to structure your program to get required result.
Apart from that i don't have enough time to sit and code for you. But Still if i get time i will do that. Ok.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
hi,
Ok. Don't repeat this anymore. That's is don't ask supporters for code block.
string[] ab=new string[5];
string[] bc=new string[4];
string[] cd=new string[5];
int ctr,ctr1=-1;
ab[0]="red";
ab[1]="blue";
ab[2]="yellow";
ab[3]="green";
ab[4]="black";
bc[0]="green";
bc[1]="red";
bc[2]="blue";
bc[3]="pink";
foreach(string Str in ab)
{
ctr=0;
ctr1++;
foreach(string Str2 in bc)
{
if(Str.Equals(Str2))
{
ctr++;
}
else
continue;
}
if(ctr!=0)
cd[ctr1]=Str+"|Yes";
else
cd[ctr1]=Str+"|No";
}
foreach(string str in cd)
{
string[] part=str.Split('|');
Console.WriteLine(part[0]+"="+part[1]);
}
}
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I am bangin my head against the
Yes, I am the highly suggestable type.
|
|
|
|
|
Hi @all,
I can't fix the following problem:
I have an ArrayList filled with data (from a self joined table) that should be the names of the nodes of a TreeView:
{"0", "Categories",
"Categories", "Music",
"Categories", "Videos",
"Music", "Audio-CD",
"Videos", "SVCD",
"Videos", "MPEG"}
The first is the parent node and the second is the child. The data pair, which contains "0" and "Categories" is the root.
The TreeView should looks like
+Categories
-Music
*Audio-CD
-Videos
*SVCD
*MPEG
I tried a lot without success. Please help me!
Thank you!
Sebastian.
|
|
|
|
|
I haven't tested it but I think something like this should work.
Hashtable table = new Hashtable();
for(int i = 0; i < arrayList.Count; i++)
{
treeView.Items.Add(arrayList[i].ToString());
table.Add(arrayList[i].ToString(), table.Count);
i++;
}
int index;
for(int i = 1; i < arrayList.Count; i++)
{
index = table[arrayList[i-1].ToString()];
treeView.Items[index].Add(arrayList[i].ToString());
i++;
}
|
|
|
|
|
Hey...
thank you for your reply...
The problem is that the keys are not definite. That's why I had to exchange key and value.
But how can I get the keys for the values now ?
Greetings
S.
|
|
|
|
|
Hi,
I am trying to get the duration of a wmv/wma file, without playing that pleasea anyone can suggest me how to find this .
Vaibhav
Vaibhavgupta28@gmail.com
|
|
|
|
|
hi,
you can use Duration property of your Media Control.
Eg:
OpenFileDialog fld=new OpenFileDialog();
fld.ShowDialog();
axMediaPlayer1.FileName=fld.FileName;
double Due=axMediaPlayer1.Duration;
Here i am getting the duration of movie file without playing it.
**************************
S r e e j i t h N a i r
**************************;)
|
|
|
|
|
Hi Sreejith,
I tried this code, but i am not getting the right output,
Please help me Regarding this.
I am using::::
using MediaPlayer;
{
MediaPlayer.MediaPlayerClass axMediaPlayer1= new MediaPlayer.MediaPlayerClass();
OpenFileDialog fld=new OpenFileDialog();
fld.ShowDialog();
axMediaPlayer1.FileName=fld.FileName;
double Due=axMediaPlayer1.Duration;
}
Vaibhav
|
|
|
|
|
hi,
Tell me what is your real problem ?
1) You are not getting the required result or getting any error message ?
2) How you are using the MediaPlayer conponent ?
Your wrote :
using MediaPlayer;
MediaPlayer.MediaPlayerClass axMediaPlayer1= new MediaPlayer.MediaPlayerClass();
What you mean by this ?
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi,
I want to get the duration of a movie while DRM encryption. As per sreejith's suggestion i added one com object mediaplayer, and tried to use that.
I am getting result as 0.0 for any wma/wmv file.
I am adding com component "Msdxm.ocx".
I am stuck in thic can you help me in this.
Thanks
Vaibhav
|
|
|
|
|
Hi,
I didn't get you properly. Tell me , Your development is for Desktop PC or Smart Devices ?
If it is for Desktop PC then your .ocx file is wrong. That is you mentioned 'msdxm.ocx' but it is 'wmp.ocx'
msdxm.ocx is Microsoft NetShow player.
wmp.ocx ios Windows Media Player.
If your development is for any smart device then my previous post won't serve you neatly. And i am not much sure about the Microsoft NetShow Player (that is your msdxm.ocx file ) and it's usage.
If you want to know the movie duration without playing the movie in desktop then you can follow this steps.
Right click your tool bar and choose add/remove Items.
From there choose the COM tab and try to select Windows Media Player.
Once you choose the option then click ok to add that COM component in your application toolbar.
Drag Media control which may apper at the end of toolbar list (forms control list) into your application.
If you see the editior window then you can view the control declaration like this
private AxMediaPlayer.AxMediaPlayer axMediaPlayer1;
And then write this much logic where ever you wish.
private void Form1_Load(object sender, System.EventArgs e)
{
OpenFileDialog Open=new OpenFileDialog();
axMediaPlayer1=new AxMediaPlayer.AxMediaPlayer();
if(Open.ShowDialog()!=DialogResult.Cancel)
{
axMediaPlayer1.FileName=Open.FileName;
Double Dur = axMediaPlayer1.Duration;
MessageBox.Show("Selected Movie Is Of : "+Dur.ToString()+" Second Duration");
}
}
This code block will open a movie file from your specified location and will give you the duration of that perticular movie without playing.
This my logic only works in Desktop. If you are expecting something else from this then someother supporter will help you out.
thanks
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi sreejith,
I am able to read the duration of a movie now. thanks a lot.
I used
{
WMPLib.WindowsMediaPlayerClass sss=new WMPLib.WindowsMediaPlayerClass();
string str= @"my Path";
sss.URL=str;
sss.currentMedia.name=str;
double dur =sss.currentMedia.duration;
}
I am getting the duration here
Thanks
Vaibhav
|
|
|
|
|
Hi,
I have a textbox in a Form, which the user enters a dollar amount.
I use a try/catch statement to make sure they only entered numbers,
but I also want to stop the user from entering a number past two decimal places. In other words, if user entered 15.758, an error message (messagebox) would appear.
Ron
|
|
|
|
|
There is probably a better way but I have been using the System.Text.Regularexpressions namespace to handle the basic validation for my UI's. I create a validation object where I have different types of validation patterns that I enumerate and return true or false. I am not sure of the correct name but I believe they are called predicates. It looks like this.
I
f(validate.vString(textbox1.Text, vType.Money)
{
Do what ever I need;
}
Else
{
Notify User and handle any rollback;
}
The method will have
The regularexpresion validator takes an expression like the following.
Regex re = new Regex(@"^(?!\u00a2)\p{Sc}?(?!0,?\d)(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?"); (I pulled this off the web a few months ago and I cannot remember who wrote it but they did a good job) and then is returned by the ismatch method.
One of the features I like about this is the number of resources available to me on the web to get patterns. Since I tend to write business apps it is pretty important to me to have a flexible means of validating the inputs (decimal places, sku's, email and addresses) and so far this has worked.
Hope it helps. If you find a better way be sure and share since I am always looking to improve my apps.
It looks complicated for validation but after you get use to it and the expressions it works real well.
|
|
|
|
|
Thanks KevinMac,
I'm new to programming, so I'll have to study up on Regex.
I suppose I shouldn't use Convert.ToDecimal(txb_Tendered.Text);
for validation either.
|
|
|
|
|
hi,
For your first requirement you can use this logic on keypress event of your textbox control.
This won't take any value which is not of the numeric type.
private void txtbox_KeyPress_1(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
try
{
if (Char.IsDigit(e.KeyChar))
e.Handled=false;
else
e.Handled=true;
}
catch(Exception Ex)
{
MessageBox.Show("Invalid Entry Found","Error Description",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
And your next requirement is not professional in nature. According to me, here you are trying to force the user to do this much. You need to know one thing we can't force the user to do something that we expect. Our software need to make his life simpler. (This is only my humble suggection. And it is upto you to deside what you want.)
Why don't you do onething, after getting the user input try to format it as what ever format you want. Here is the logic for that.
textBox1.Text=Convert.ToString(float.Parse(textBox1.Text).ToString("#,##.##"));
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi sreejith ss nair,
first requirement:
I tried your first code, it works well except it doesn't allow user to use "." for the decimal place.
second requirement:
If the user enters 12.897, it would be an error (working with currency). Auto formating (rounding or triming) might not give the correct end result (did they want 12.89 or 12.87?).
|
|
|
|
|
hi,
Please refer Math class for how to round the values. Please gothrough the static members of Maths class.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I think this article[^] here on codeproject is what you search for. Or at least it's a good starting point.
www.troschuetz.de
|
|
|
|
|
Thanks Stefan!!!
This is what I came up with (using your link).
try
{
//Test if string will convert to a decimal
Convert.ToDecimal(txb_Tendered.Text);
//Count char. to the left of "."
int pos = txb_Tendered.Text.IndexOf(".");
if(pos != -1)// -1 would mean that no "." was entered
{
//Count characters to the right of (and including) "."
if (txb_Tendered.Text.Substring(pos).Length > 3)
{
MessageBox.Show("Don't enter more than two decimal places to the right ","Decimal Place Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
catch
{
MessageBox.Show("You must enter a valid amount for tendered (no $) ","Tendered Amount",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
|
|
|
|
|
Hi,
In C, I can code:
#define RETAIL 42
if (StoreType == RETAIL)
How do I do the same thing in C#. I find the #define but you can't assign a value to the symbol.
I suppose I could define all the StoreTypes as constants or as a property to class. Then I could say if (StoreType == StoreType.RETAIL), not sure which is the best way to go. Suggestions?
Thanks,
Glenn
|
|
|
|
|
hi,
#define ENT
#define WPK
#if ENT
// Do what ever you want
#if WPK
//do what ever you want
#endif
#elif
there is no much difference here in C# for pre-processive directives. Try to view MSDN for much reference.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|