|
Same here, all in one file. I typically twiddle with enums much less, and it cuts down on the clutter in the project.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hi Guys. I am trying to match some input from a text box to an if statement. Now, I am doing this from following some ARL code and I get a build error. Error message is "Operator '>=' cannot be applied to operands of type 'string' and 'string'"
The ARL code looks something like this.
if ws_holder_pcode >= 4731 and ws_holder_pcode <= 6499
begin
move 1 to ws_holder_province
finish
end
What I have written in the button click event.
private void btnValidate_Click(object sender, EventArgs e)
{
if (txtboxPcode.Text >= "4731" && txtboxPcode.Text <= "6499")
{
MessageBox.Show("Eastern Cape");
}
}
How can I do this correctly? Any suggestions would be greatly appreciated.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
To compare strings, try the String.Compare() method.
private void btnValidate_Click(object sender, EventArgs e)<br />
{<br />
<br />
if (String.Compare(txtboxPcode.Text,"4731") == 0 && String.Compare(txtboxPcode.Text,"6499") == 0)<br />
{<br />
MessageBox.Show("Eastern Cape");<br />
}<br />
}
Just because we can; does not mean we should.
|
|
|
|
|
Thanks mate. I actualy want to check that the value entered falls in the range of 4731 and 6499.
KaptinKrunch wrote: if (String.Compare(txtboxPcode.Text,"4731") == 0 && String.Compare(txtboxPcode.Text,"6499") == 0)
I have tried the suggestion that you made but I keep getting "Invalid Pcode" message returned from the else statement meaning that I am not making a match. So, what I want to do is something like this.
if (txtboxPcode.Text >= 4731 && txtboxPcode.Text <= 6499)
{
MessageBox.Show("Eastern Cape");
}
Any further suggestions appreciated.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You could change your strings "6499" to Int32's and convert the contents of your text boxes to int's by Int32.Parse(box.Text);
and don't forget to put in the IFormatProvider to the Parse method.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Keep in mind too that your if logic is stating that your textbox value needs to equal both 4731 and 6499. If you need to match one or the other, change the operator to "||"(OR) vs "&&"(AND).
Just because we can; does not mean we should.
|
|
|
|
|
If the value entered falls within the range of 4731 and 6499 i.e. the user enters 5000 then a amtch is made. Maybe I am writing it wrong. If the value entered falls anywhere inbetween then we have match.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
private void btnValidate_Click(object sender, EventArgs e)
{
int pcode = 0;
if (int.TryParse(txtboxPcode.Text) == false)
{
MessageBox.Show("Invalid Integer!");
return;
}
if ((pcode >= 4731) && (pcode <= 6499))
{
MessageBox.Show("Eastern Cape");
return;
}
MessageBox.Show("Unknown Cape!");
}
|
|
|
|
|
Ed.Poore wrote: if (int.TryParse(txtboxPcode.Text) == false)
Thanx Ed.Poore. You however left out the out portion of the statment. I amended it to look like this and it worked fine.
private void btnValidate_Click(object sender, EventArgs e)
{
int pcode = 0;
if (int.TryParse(txtboxPcode.Text, out pcode) == false)
{
MessageBox.Show("Invalid Integer!");
return;
}
if((pcode >= 4731) && (pcode <=6499))
{
MessageBox.Show("Eastern Cape");
}
Thanks for the help mate. Greatly appreciated.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
hy everyone!
sorry for me asking again, but i encountered two additional problems during realizing my parser:
problem number one:
after i finished parsing, there might be some fields which weren't replaced by it's values. they are of a special format
< format|varname|format >
in this example format has to be replaced by a format value which i defined myself.
*) there could be 0 to n "#" which define the fieldlength and right- or leftalignment (e.g. <###|varname|> for rightalignment of a filed with length 3 - because of 3 #s) <|varname|###> would be the counterpart but leftalignment.
*) there could be a formatstring on the right e.g. <|varname|{#,##0.00}>
*) there could be 0 to n "~" which define the string to be centered and define the fieldlength e.g. <|varname|~~~> for fieldlength 3 and centering
*) and there could be either a sign "]" or "[" on the right which define on which page the variable should be replaced by it's value or by an empty string. e.g <|varname|[>
and (which makes it even harder and causes my second problem) a combination of the formatings above (except left-, rightalignment and center at the same time!) in not defined order (but not mixed!). e.g. <###|varname|{##0.00}[> (but not e.g. <|varname|~~[~~> etc.)
so i have to replace strings between < and > without knowing whats inbetween by an "empty" string (but of defined length, if # or { is found!).
my solution would be to search the final parsed string for an occurence of "<" and then parse in the string until the ">" is found. then do the formating for # and ~ but ignoring all other formatings).
but if i have to do this more often then this could be of bad performance because the more often i do change a string the longer it will take (i guess even when using a stringbuilder).
problem number 2:
well but this is not my only problem. my other problem is to do the formating in general if there are more than one format value on one side.
i allowed # to be on the left and right but all other values just to be on the right. so the left side is easy. but the right is not.
so my idea would be to first parse from the index i get for the start of the variable (e.g. |varname|) and then parse to the left until i reach the "<" sign. this info will be stored in a variable called e.g. string leftformat. then i do the same at the right by parsing from index + lengthofvariable (so from the first sign after |varname|) again until i reach the ">" this time. well, this side is tricky, because i have to check for more possible signs: "#" or "~", a format string {...} and a sign "[" or "]" (the ors are exclusive in this case so either this or that but not at the same time!). then i would put the right side into a loop until the rightformat string is parsed (empty, or length index). in this loop i would check for all possible signs, which could be there. but i do not know in which order they might occur, that's why i do the loop. because i could check for the sign sequentially. so if the last if is the one then i have to repeat the check for the next signs.
example for the right side: #####{##0.00}[
(note that the #s in the formatstring are treated differently, because they are sourounded by "{" and "}"!!).
so my could would look like (pseudocode!)
while (string not empty or i < length)
{
if char == "#" { while still "#" replace this one }
if char == "~" { check needed if "#" was alreaday used!
while still "~" replace this one}
if char == "{" { parse until the "}" sign is reached }
if char == "[" { do the operation }
if char == "]" { check if not already "[" and do the operation }
}
well i hope i did describe my problems well enough but not to long on the other hand side
what do you think about this? from my point of view i am not sure if this doesn't slow down my parser too much. that's why i posted it here for discussion and further ideas.
so if anyone of you has comments or any better solution to handle this, please let me know by replying to my post.
thanks.
stephan.
modified on Thursday, April 24, 2008 12:54 PM
|
|
|
|
|
I think regular expressions are about to become your new best friend.
Just because we can; does not mean we should.
|
|
|
|
|
I don't think reg expressions become anyones best freind. I see it more like an annoying tenant that won't move out, yet gives you lots of money at the end of the month. If you see what i mean.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
what is the main class in C#.net from which all the classes are
derived?
please someone answer my question i am new to C#.thanks
aayzgroup
|
|
|
|
|
Please, don't fill up the forum with lots of simple questions, you could have used one post to ask all of them.
Also, you can easily use google to find the answers you are looking for, and it would probably be quicker as well.
Since you are asking these questions i recommend that you buy a beginners book, and if you don't want to spend any money, start working through a set of online tutorials - there are plenty available.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
SK Genius wrote: don't fill up the forum with lots of simple questions, you could have used one post to ask all of them.
It depends on your preference. I prefer each thread to contain only one question.
|
|
|
|
|
Yep, I was gonna say that too, but you know, when you're preparing for an interview where you plan to say you know a language you don't know... it's best not to waste too much time on that...
|
|
|
|
|
A@YZ wrote: what is the main class in C#.net from which all the classes are
derived?
If by "main" you mean "base" then it is object . All classes are, eventually, derived from object .
|
|
|
|
|
"In the beginning there was the class , and the class was object ."
|
|
|
|
|
PIEBALDconsult wrote: "In the beginning there was the class, and the class was object."
"6. Then Hejlsberg said, "Let there be an expanse in the midst of the types, and let it separate the types from the types." 7. Hejlsberg made the expanse, and separated the types which were in the heap from the types which were outside the heap; and it was so. 8. Hejlsberg called the expanse ValueType. And there was evening and there was morning, a second day."
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Simply brilliant.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
what is meant by Interface in C#?
please someone answer my question i am new to C#.thanks
aayzgroup
|
|
|
|
|
Interfaces in C# are a way of abstraction. For instance lets say we create an interface called IAnimal. The IAnimal interface defines a contract that all classes which implement the IAnimal interface must abide by. The IAnimal interface defines several properties such as int NumberOfLegs, bool HasFur and so on. Now you want to create a calls that implements this interface you would do so by
public class Dog : IAnimal
{
}
When you implement the IAnimal interface you MUST implement all of the items the interface defines so you would need to do this:
public class Dog : IAnimal
{
public int NumberOfLegs
{
get { return 4; }
}
public bool HasFur
{
get { return true; }
}
}
now you can not only refer to the instance of the Dog class as a Dog but you would also refer to this object as an IAnimal.
Dog dog = new Dog();
int legs = dog.NumberOfLegs;
or
IAnimal animal = new Dog();
int legs = animal.NumberOfLegs;
Hope this helps.
You can always find more at www.johnnycantcode.com
Scott "Johnny" Smith
www.johnnycantcode.com
|
|
|
|
|
|
Multiple Inheritance is possible in C# are not?
please answer my question i am new to C#.thanks
aayzgroup
|
|
|
|
|