Using MessageBox with Visual Basic 2008 Express

technicaltrader
technicaltrader used Ask the Experts™
on
Below is an small piece of the code for a project of mine. It is the first calculation in the code that sets up the entire calculation and if the data in one of two text boxes happens to not be entered then I want it to throw a warning using a MessageBox.

Now I accomplish that event but I would like it to stop the calculation and place the curser within the text box that data input is missing once "OK" is clicked on the message box. Then once that data is added, the user can then hit the "Total_Click" button to start the calculation over again.

Right now it throws the event, but once you hit "OK" then it continues the calculation. (Which throws an exception because this beginning data input is missing)

Hope that makes sense. Thanks in advance!
Private Sub Total_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Total.Click
        'All the following CALCULATES when the "Risk/Reward" button is clicked.
        '
        'The following calculates the total dollar share amount.
        If Not String.IsNullOrEmpty(_SharesTextBox.Text) And Not String.IsNullOrEmpty(EntryTextBox.Text) Then
            TotalDollarShareAmount.Text = Format(Math.Round(CType(EntryTextBox.Text, Double) * CType(_SharesTextBox.Text, Double), 2), "#,###,###.00")
        Else
            Dim iResponce As Integer
            iResponce = MsgBox("Field is empty")
        End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Break your if statements into two if's.
Then insert exit sub after the messagebox to halt the execution of the sub routine.

See example code below.
Private Sub Total_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Total.Click
        'All the following CALCULATES when the "Risk/Reward" button is clicked.
        '
        'The following calculates the total dollar share amount.
        If Not String.IsNullOrEmpty(_SharesTextBox.Text.trim) then
	   If Not String.IsNullOrEmpty(EntryTextBox.Text.Trim) Then
            TotalDollarShareAmount.Text = Format(Math.Round(CType(EntryTextBox.Text, Double) * CType(_SharesTextBox.Text, Double), 2), "#,###,###.00")
	   Else
	    MsgBox("Entry Textbox is empty. Please input a value.")
            Exit sub 
	   End If
        Else
            MsgBox("SharesTextBox is empty. Please input a value.")
            Exit Sub
        End If

Open in new window

Author

Commented:
Excellent!!! That works terrific! Thank you very much...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial