Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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;
	}

C#
  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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;}
		}
	}

C#
  • *Experts*
Posted

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

"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
Posted
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.
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...