Results 1 to 4 of 4

Thread: Variable not holding value?

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Variable not holding value?

    Why do dots always print when the bool value should be set to true after one dot?

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

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    What are you trying to do? with the method?

  3. #3

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I am just practicing right now.

    This should not execute if check2 is true:

    else if (dummy=='.' && check2==false) {check2=true; return true;}

    But for some reason the dots always print. I only want one dot to print and I can't figure out why that does not work right.

  4. #4
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    Can you show us the input to the method?
    I think your logic might be off a little bit.
    -scott
    he he he

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width