-
Apr 8th, 2015, 06:36 AM
#1
Thread Starter
Addicted Member
using return in sub = exit sub
if return in sub = exit sub
example
Code:
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "empty")
Return
Else
ErrorProvider1.SetError(TextBox1, "")
End If
-
Apr 8th, 2015, 06:48 AM
#2
Re: using return in sub = exit sub
Yes... Return in a sub is the same as an Exit Sub... it's debateable if one is better over the other.
BUT...
as I mentioned in your other thread http://www.vbforums.com/showthread.p...-Provider-tool don't just set the errorprovider one at a time like that. If there are 5 fields that are in error, MARK THEM ALL ... don't make me hit hte button 5 times and report just one at a time. I find that annoying and I'm sure others do to.
But, if you insist on doing it that way, then just use the if...elseif you originally had.
-tg
-
Apr 8th, 2015, 07:05 AM
#3
Thread Starter
Addicted Member
Re: using return in sub = exit sub
Originally Posted by techgnome
Yes... Return in a sub is the same as an Exit Sub... it's debateable if one is better over the other.
BUT...
as I mentioned in your other thread http://www.vbforums.com/showthread.p...-Provider-tool don't just set the errorprovider one at a time like that. If there are 5 fields that are in error, MARK THEM ALL ... don't make me hit hte button 5 times and report just one at a time. I find that annoying and I'm sure others do to.
But, if you insist on doing it that way, then just use the if...elseif you originally had.
-tg
Code:
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "empty")
Return
ElseIf TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "empty")
Return
Else
ErrorProvider1.Clear()
End If
if i use elseif
how to clear ErrorProvider1 so the ErrorProvider1 not appear for first textbox
-
Apr 8th, 2015, 07:09 AM
#4
Re: using return in sub = exit sub
Clear first... then set...
-tg
-
Apr 8th, 2015, 07:18 AM
#5
Thread Starter
Addicted Member
Re: using return in sub = exit sub
Originally Posted by techgnome
Clear first... then set...
-tg
work with me
is this ok now
Code:
ErrorProvider1.Clear()
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "empty")
Return
ElseIf TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "empty")
Return
End If
-
Apr 8th, 2015, 09:58 AM
#6
Re: using return in sub = exit sub
you tell me... if it works, and is what you want, then great. it's not how I would do it.
-tg
-
Apr 8th, 2015, 10:07 AM
#7
Re: using return in sub = exit sub
The point of using the If ElseIf is that you don't need the Returns really, because once one of the cases was true, it would skip the rest.
Code:
ErrorProvider1.Clear()
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "empty")
ElseIf TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "empty")
End If
-
Apr 9th, 2015, 07:59 AM
#8
Re: using return in sub = exit sub
Originally Posted by passel
The point of using the If ElseIf is that you don't need the Returns really, because once one of the cases was true, it would skip the rest.
Code:
ErrorProvider1.Clear()
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "empty")
ElseIf TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "empty")
End If
He should be checking all of them and flagging all of them each time anyways, using individual If's (not the ElseIf's):
vb Code:
ErrorProvider1.Clear()
If TextBox1.Text.Trim = String.Empty Then
ErrorProvider1.SetError(TextBox1, "empty")
End If
If TextBox2.Text.Trim = String.Empty Then
ErrorProvider1.SetError(TextBox2, "empty")
End If
Or do it with a simple loop:
vb Code:
ErrorProvider1.Clear()
Dim tb As TextBox
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox Then
tb = DirectCast(ctrl, TextBox)
If tb.Text.Trim = String.Empty Then ErrorProvider1.SetError(tb, "empty")
End If
Next
-
Apr 9th, 2015, 09:35 AM
#9
Re: using return in sub = exit sub
Originally Posted by JuggaloBrotha
He should be checking all of them and flagging all of them each time anyways, using individual If's (not the ElseIf's):
vb Code:
ErrorProvider1.Clear() If TextBox1.Text.Trim = String.Empty Then ErrorProvider1.SetError(TextBox1, "empty") End If If TextBox2.Text.Trim = String.Empty Then ErrorProvider1.SetError(TextBox2, "empty") End If
Or do it with a simple loop:
vb Code:
ErrorProvider1.Clear() Dim tb As TextBox For Each ctrl As Control In Me.Controls If TypeOf ctrl Is TextBox Then tb = DirectCast(ctrl, TextBox) If tb.Text.Trim = String.Empty Then ErrorProvider1.SetError(tb, "empty") End If Next
Exactly! that's what I said in the other thread as well... but for what ever reason, he's hell bent on doing it this way. I've given up... something about horses and water.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|