aewarnick Posted February 2, 2003 Posted February 2, 2003 Why do dots always print when the bool value should be set to true after one dot? private void do3() { if(TorF(TB1.Text)) RTB2.Text=TB1.Text; } bool check2=false; public bool TorF(string str) { char[] chr = str.ToCharArray(); foreach (char dummy in chr) { if (char.IsDigit(dummy)) return true; else if (dummy=='.'&& check2==false) {check2=true; return true;} } return false; } Quote C#
*Gurus* divil Posted February 2, 2003 *Gurus* Posted February 2, 2003 The way that is coded, you are continuing the loop if it finds a dot and check2 is true. I guess if it finds another digit after that, it'll return true. What you probably want to do is add another clause to your tests, so if it finds a dot and check2 is true, to return false. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 4, 2003 Author Posted February 4, 2003 I tried and tried till I could try no more!! So I just changed it completely: //do3 public void do3() { TB1.Focus(); TB1.SelectAll(); check2(TB1.Text); RTB2.Text=y; } bool b=false; string y=""; void check2(string text) { char[] chrarray = text.ToCharArray(); foreach (char x in chrarray) { if (char.IsDigit(x)) y+=x; else if (x=='.' && b==false) {b=true; y+=x;} } } Quote C#
*Experts* Nerseus Posted February 5, 2003 *Experts* Posted February 5, 2003 What exactly are you trying to do with your do3 and check2 functions? If you're trying to validate a string, you might do better to just use regular expressions. From the function names, I can't tell anything and I'm too lazy to read through the code to see what you want to do :) -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
aewarnick Posted February 5, 2003 Author Posted February 5, 2003 I'm with you. I don't feel like figuring it out either. It works now, so I am happy. Actually I have a subscripted array problem now that should be simple but is giving me trouble. I'll post that elsewhere. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.