VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to make If statement check 2 txt boxes Posted by rgray06 on 22 Mar 2004 at 4:49 AM
How do you use if to check 2 txt box to confirm that there is something wriiten in them
I am using
If (txtpo.txt="")then
call poerror()
else
call save()
end If
This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing

Thanks for any help
Rgray

Report
Re: How to make If statement check 2 txt boxes Posted by kainsworth on 22 Mar 2004 at 8:14 AM
There's a new operator now available in VB.Net - "andalso". In your scenario, you can use it like this:
If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
            poerror
        Else
            save
        End If


==================================


: How do you use if to check 2 txt box to confirm that there is something wriiten in them
: I am using
: If (txtpo.txt="")then
: call poerror()
: else
: call save()
: end If
: This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing
:
: Thanks for any help
: Rgray
:
:

Report
Re: How to make If statement check 2 txt boxes Posted by rgray06 on 23 Mar 2004 at 5:45 PM
I must have something missing in my program. I can not make this work
The button click does nothing with this code.

Thanks for the help
I will keep digging

Regards
RGray

: There's a new operator now available in VB.Net - "andalso". In your scenario, you can use it like this:
:
: If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
:             poerror
:         Else
:             save
:         End If
: 

:
: ==================================
:
:
: : How do you use if to check 2 txt box to confirm that there is something wriiten in them
: : I am using
: : If (txtpo.txt="")then
: : call poerror()
: : else
: : call save()
: : end If
: : This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing
: :
: : Thanks for any help
: : Rgray
: :
: :
:
:

Report
Re: How to make If statement check 2 txt boxes Posted by kainsworth on 24 Mar 2004 at 12:16 AM
My guess would be that the problem will be with either or both of the two procedures you are calling - poerror or save. What code do you have in there?
I've tested the If/Then/Else logic and it definitely reacts correctly to any combination of text content in the two textboxes I used. Did you replace the names TextBox1 and TextBox2 in my code snippet with the correct names for your two boxes?
I hope I understood your original question correctly - this code snippet will call "poerror" if both boxes are empty at the same time. It will call "save" if either box has some text in it (even if the other one is empty).
One way to test the logic of the If/Then snippet is to replace the procedure calls with a simple messagebox. You can then write and delete code in the two textboxes, click the button and the message will tell you how the code has interpreted the textbox text status.
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
            MessageBox.Show(" poerror")
        Else
            MessageBox.Show(" save")
        End If
    End Sub

If you need to call poerror if either textbox is left empty, then use this alternative:
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MessageBox.Show(" poerror")
        Else
            MessageBox.Show(" save")
        End If
    End Sub

Without more info on your code there's not much else I can help you with at this stage.

Ged
====================================================================


: I must have something missing in my program. I can not make this work
: The button click does nothing with this code.
:
: Thanks for the help
: I will keep digging
:
: Regards
: RGray
:
: : There's a new operator now available in VB.Net - "andalso". In your scenario, you can use it like this:
: :
: : If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
: :             poerror
: :         Else
: :             save
: :         End If
: : 

: :
: : ==================================
: :
: :
: : : How do you use if to check 2 txt box to confirm that there is something wriiten in them
: : : I am using
: : : If (txtpo.txt="")then
: : : call poerror()
: : : else
: : : call save()
: : : end If
: : : This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing
: : :
: : : Thanks for any help
: : : Rgray
: : :
: : :
: :
: :
:
:

Report
Re: How to make If statement check 2 txt boxes Posted by rgray06 on 24 Mar 2004 at 5:52 PM
Thanks for the help.Your code works perfect I found were I was my code was putting a blank space in the txtbox so the system was thinking something was there

Thanks Again for your help
Regards
RGray


: My guess would be that the problem will be with either or both of the two procedures you are calling - poerror or save. What code do you have in there?
: I've tested the If/Then/Else logic and it definitely reacts correctly to any combination of text content in the two textboxes I used. Did you replace the names TextBox1 and TextBox2 in my code snippet with the correct names for your two boxes?
: I hope I understood your original question correctly - this code snippet will call "poerror" if both boxes are empty at the same time. It will call "save" if either box has some text in it (even if the other one is empty).
: One way to test the logic of the If/Then snippet is to replace the procedure calls with a simple messagebox. You can then write and delete code in the two textboxes, click the button and the message will tell you how the code has interpreted the textbox text status.
:
:  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
:         If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
:             MessageBox.Show(" poerror")
:         Else
:             MessageBox.Show(" save")
:         End If
:     End Sub
: 

: If you need to call poerror if either textbox is left empty, then use this alternative:
:
:   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
:         If TextBox1.Text = "" Or TextBox2.Text = "" Then
:             MessageBox.Show(" poerror")
:         Else
:             MessageBox.Show(" save")
:         End If
:     End Sub
: 

: Without more info on your code there's not much else I can help you with at this stage.
:
: Ged
: ====================================================================
:
:
: : I must have something missing in my program. I can not make this work
: : The button click does nothing with this code.
: :
: : Thanks for the help
: : I will keep digging
: :
: : Regards
: : RGray
: :
: : : There's a new operator now available in VB.Net - "andalso". In your scenario, you can use it like this:
: : :
: : : If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
: : :             poerror
: : :         Else
: : :             save
: : :         End If
: : : 

: : :
: : : ==================================
: : :
: : :
: : : : How do you use if to check 2 txt box to confirm that there is something wriiten in them
: : : : I am using
: : : : If (txtpo.txt="")then
: : : : call poerror()
: : : : else
: : : : call save()
: : : : end If
: : : : This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing
: : : :
: : : : Thanks for any help
: : : : Rgray
: : : :
: : : :
: : :
: : :
: :
: :
:
:

Report
Re: How to make If statement check 2 txt boxes Posted by kainsworth on 25 Mar 2004 at 12:45 AM
Always happy to help.
Just for info (in case you didn't find this out yet) you can force VB to strip out any blank spaces at either end of a string of text by using Trim eg:
If Trim(TextBox1.Text) = "" Then 
:  '  whatever

This would then make it read " " as "", or "Hello " as "Hello" and so on.
Cheers
Ged



: Thanks for the help.Your code works perfect I found were I was my code was putting a blank space in the txtbox so the system was thinking something was there
:
: Thanks Again for your help
: Regards
: RGray
:
:
: : My guess would be that the problem will be with either or both of the two procedures you are calling - poerror or save. What code do you have in there?
: : I've tested the If/Then/Else logic and it definitely reacts correctly to any combination of text content in the two textboxes I used. Did you replace the names TextBox1 and TextBox2 in my code snippet with the correct names for your two boxes?
: : I hope I understood your original question correctly - this code snippet will call "poerror" if both boxes are empty at the same time. It will call "save" if either box has some text in it (even if the other one is empty).
: : One way to test the logic of the If/Then snippet is to replace the procedure calls with a simple messagebox. You can then write and delete code in the two textboxes, click the button and the message will tell you how the code has interpreted the textbox text status.
: :
: :  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
: :         If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
: :             MessageBox.Show(" poerror")
: :         Else
: :             MessageBox.Show(" save")
: :         End If
: :     End Sub
: : 

: : If you need to call poerror if either textbox is left empty, then use this alternative:
: :
: :   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
: :         If TextBox1.Text = "" Or TextBox2.Text = "" Then
: :             MessageBox.Show(" poerror")
: :         Else
: :             MessageBox.Show(" save")
: :         End If
: :     End Sub
: : 

: : Without more info on your code there's not much else I can help you with at this stage.
: :
: : Ged
: : ====================================================================
: :
: :
: : : I must have something missing in my program. I can not make this work
: : : The button click does nothing with this code.
: : :
: : : Thanks for the help
: : : I will keep digging
: : :
: : : Regards
: : : RGray
: : :
: : : : There's a new operator now available in VB.Net - "andalso". In your scenario, you can use it like this:
: : : :
: : : : If TextBox1.Text = "" AndAlso TextBox2.Text = "" Then
: : : :             poerror
: : : :         Else
: : : :             save
: : : :         End If
: : : : 

: : : :
: : : : ==================================
: : : :
: : : :
: : : : : How do you use if to check 2 txt box to confirm that there is something wriiten in them
: : : : : I am using
: : : : : If (txtpo.txt="")then
: : : : : call poerror()
: : : : : else
: : : : : call save()
: : : : : end If
: : : : : This works for 1 or the other but how can I make it work for both. I have tried setting up a second sub for the other txt box and changed the call save to second sub then the program does nothing
: : : : :
: : : : : Thanks for any help
: : : : : Rgray
: : : : :
: : : : :
: : : :
: : : :
: : :
: : :
: :
: :
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.