If-Then statements and validating events in VB.net
This is my first post.....
I have created a solution that is one form. It is a project designed to calculate the area of a cube. I have the calculations correct but need to validate the entries that are in my text boxes (width, height, and length). Only entries that have positive numbers (numbers > 0) will be allowed. If the txt entry is incorrect when the user leaves that particular text box, the text entry should turn red. If the user attempts to calculate the cube area, then an error window should pop up when the calculate_click event occurs. I know I am supposed to use If then statements in the validate event but am unsure of how to do it. Can anyone help????
I know it will be good to include the code and I have done so in a text file. If I can post the whole project folder (.sln, .vb, .vbproj files, etc) and that is better then I will. Hopefully this text file will suffice.
Thanks ahead of time and I look foward to suggestions
My brain does not operate along the lines of the question setter and I would approach the solution much more simply but if you HAVE to stick to the framework of functions provided I will not be of much help to you.
I would do something like:
VB Code:
Private Sub Test_Text_Validity(objTXT as TextBox)
if val(objTXT.Text)<=0 then objTXT.Forecolor=Color.Red
end sub
Private Sub txtWidth_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt1.LostFocus
Test_Text_Validity(txtWidth)
End Sub
Repeat the calling routine for each textbox and use the same approach,for checking the range of measurements, using multiple parameters for the appropriate ranges, using Select Case for the comparison of values.
Last edited by taxes; Apr 29th, 2004 at 06:31 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
The first sub function you posted turns my txt box entries red if the entry is less then zero.
What I also need is a validating event for a button. The button performs the muliplication of the 3 text box entries to get the answer. If any of these three entries are less then zero, I need to return an pop up error window..... any ideas?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strMessage as String="Invalid Value in "
select case true
case val(txtHeight.text)<=0
strMessage=strMessage & "txtHeight"
case val(txtWidth.text)<=0
strMessage=strMessage & "txtWidth"
case val(txtDepth.text)<=0
strMessage=strMessage & "txtDepth"
case else
(Here call the sub which performs the calculation etc)
exit sub
end select
Messagebox.show(strMessage)
End Sub
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.