Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Crashing if User Does not Enter Value In Box

Status
Not open for further replies.

RoccoSiffredi

Technical User
Nov 10, 2010
16
GB
Hi All

The following VBA adds an integer to another integer, if a value is entered in the textbox. If the user does not enter a value in the box i.e. it is left blank and the User Change button is clicked the VBA freezes - I'm using Visual Basic Express. What statement do I need to enter to enter in this sub to prevent crashing?

Private Sub btnUChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUChange.Click
Dim AddNum As Integer
AddNum = txtInput.Text
NumberValue = NumberValue + AddNum
lblOutput.Text = "The Number Value has a Value of " & NumberValue
End Sub
 
In VBA:
AddNum = Val(txtInput.Text & "")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top