b-man

I have an application where the user has to fill in some textboxes and then click the next button, but if a textbox isn't filled in it crashes the program!

I would like to use this method:

Code Snippet

If TextBox1.Text = "" OrElse TextBox2.Text = "" OrElse TextBox3.Text = "" Then

MessageBox.Show("You must enter data in each textbox")

Else

build code

End If

This is where i run into my problem. There are several steps in my application.

the user has to choose between two options via radio buttons

then the user has to choose between two more options via more radio buttons.

I need the code to react to a situation like this:

if button1 and button 3 are chosen then check and see if these textboxes have text entered in them. If they do then continue to run the code.

or

if button 2 and button 4 are chosen then check and see if these other textboxes have text entered in them. If they do then continue to run the code.

I am really confused as to how to do this.

Any help would be greatly appericiated,

Thanks,

B-Man




Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

Solitaire

Here is one approach:

Dim incomplete As Boolean = False
Do
If Button1.Checked = True And Button3.Checked = True Then
If TextBox1.Text = "" Or TextBox3.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 1 and 3")
End If
ElseIf Button2.Checked = True And Button4.Checked = True Then
If TextBox2.Text = "" Or TextBox4.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 2 and 4")
End If
End If
Loop While incomplete = True






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

This cought the error and kept it from crashing but it goes into an endless loop of showing the error message and wont let you fill in the rest of the information. So i tried changing "loop while incomplete = True" to false... this only showed the error message once but then the application crashed immediately because the text box wasn't filled in.

Also, when all of the textboxes are filled in. The program goes unresponsive but displays no error message at all in visual basic.






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

Dim incomplete As Boolean = False
Do
If Button1.Checked And Button3.Checked Then
If TextBox1.Text = "" Or TextBox3.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 1 and 3")

else complete = true
End If
ElseIf Button2.Checked And Button4.Checked Then
If TextBox2.Text = "" Or TextBox4.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 2 and 4")

else

complete = true
End If
End If
Loop While incomplete = True






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

when i added "complete = true" it said complete isnt declared.

I am not sure how i would declare that.

Also... would this resolve the problem with the error message opening in an endless loop






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

whoops make that incomplete = true

And if you don't know how to declare a variable.... there are many good VB books for you to read.






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

Ok, i got it defined, i just needed a refresher. Everything works but I still have the problem where the error dialog wont go away. When i click the ok button the error dialog just instantly reopens and it does this in an endless loop. When i try setting incomplete = true to false the dialog only opens once but the application still crashes.




Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

we have no idea what is crashing it without seeing the code.




Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

here is the code i used:

Code Snippet

Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click

'Checks to see if all required fields are filled in.

Dim incomplete As Boolean = False

Do

If MaleRBtn.Checked = True And ThreeRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or ChestBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

End If

ElseIf MaleRBtn.Checked = True And SevenRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or TriBox.Text = "" Or ChestBox.Text = "" Or MidBox.Text = "" Or SubBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

End If

ElseIf FemRBtn.Checked = True And ThreeRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or TriBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

ElseIf FemRBtn.Checked = True And SevenRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or TriBox.Text = "" Or ChestBox.Text = "" Or MidBox.Text = "" Or SubBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

End If

Loop While incomplete = True






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

Instead of else : incomplete = true

replace that with else : exit loop.






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

Solitaire

Sorry, I haven't followed the rest of the posts. But here is a correction to the code I posted previously. The Boolean variable should have been reinitialized to False at the beginning of each iteration so it doesn't go into an endless loop. Please try it again this way.

Dim incomplete As Boolean
Do

incomplete = False
If Button1.Checked = True And Button3.Checked = True Then
If TextBox1.Text = "" Or TextBox3.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 1 and 3")
End If
ElseIf Button2.Checked = True And Button4.Checked = True Then
If TextBox2.Text = "" Or TextBox4.Text = "" Then
incomplete = True
MessageBox.Show("Please enter data in textboxes 2 and 4")
End If
End If
Loop While incomplete = True






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

ok, it works but I am still having the problem where the message box wont close. When i click the close button it wont let me go back and fill in the empty fields. It just reopens the message box again and again in an endless loop.






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

WHose solution are you you using What code are you executing




Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

b-man

I am using this code:

Code Snippet

Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click

'Checks to see if all required fields are filled in.

Dim incomplete As Boolean

Do

incomplete = False

If MaleRBtn.Checked = True And ThreeRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or ChestBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

ElseIf MaleRBtn.Checked = True And SevenRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or TriBox.Text = "" Or ChestBox.Text = "" Or MidBox.Text = "" Or SubBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

ElseIf FemRBtn.Checked = True And ThreeRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or TriBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

ElseIf FemRBtn.Checked = True And SevenRBtn.Checked = True Then

If TextBox1.Text = "" Or AgeBox.Text = "" Or AbBox.Text = "" Or TriBox.Text = "" Or ChestBox.Text = "" Or MidBox.Text = "" Or SubBox.Text = "" Or SupBox.Text = "" Or ThighBox.Text = "" Then

incomplete = True

MessageBox.Show("Please fill in all information to continue.")

Else : complete = True

End If

End If

Loop While incomplete = True

and i am executing a bunch of math equations






Re: Visual Basic Express Edition Keeping program from crashing when fields aren't filled in.

ReneeC

Did you try the Else Exit Loop