-
April 30th, 2003, 06:53 PM
#1
Member
vb data validation
I'm trying to make sure that the data given by 2 text fields is no more than 60, but when i enter 10 in the first (txthoursworked) and 5 in the second (txtovertime) it returns true. The code below is what i`m using.
'check numeric data
If (txthoursworked.Text + txtovertime.Text > 60) Then
MsgBox "An employee cannot work over 60 hours"
End
End If
I`ve tried storing txthoursworked.Text + txtovertime.Text in a variable and using that but its the same, i tried moving around the brackets but that did nothing either, what's wrong? How can 5+10 equal > 60 ?
-
April 30th, 2003, 07:20 PM
#2
Maybe I am reading this wrong, but, 10 + 5 = 15, 15 is less than 60 therefore your code is working is it not?
Try puting in 50 in one field and 20 in the other and see what happens.
Cheers:
-
April 30th, 2003, 08:05 PM
#3
I gforgot the conversion...but are the feilds storeing as a string rather then a integer if so you need to convert to integers for the math there is a simple function to do this.
DJM you reversed the sign 15!>60 so the code isnt working
Who is more trustworthy then all of the gurus or Buddha’s?
-
April 30th, 2003, 08:21 PM
#4
Member
uhm, they're not being stored as anything because i`m reading them from field box state, not reading it from a variable.
And if my code was working this post wouldn`t exist.
-
April 30th, 2003, 08:38 PM
#5
right...but If i rember correctly the text box is a string...you are adding the asci reprsentation of 5 to the asci represintation of 15 (or perhaps concatinating..don't remember how vb handles a + in strings/charicters) and then checking to see if its > the asci representation of 60. what you want to do I think is
If (CLng(txthoursworked.Text) +CLng (txtovertime.Text) > 60) Then
check the syntax on that though as I am a VB hack. More of a Perl/C++ guy.
Who is more trustworthy then all of the gurus or Buddha’s?
-
April 30th, 2003, 11:04 PM
#6
Member
thanks alot, it seems to work.
only problem is it gets an error if the user enters a string and not a letter, do you know how to test for prescense of a string? Or how to test with an IF statement for failure, i.e if(isnot(string), microsoft nor google can tell me a way to test for prescense of a string or how to test for if something is not something.
-
May 1st, 2003, 12:21 AM
#7
Use IsNumeric...
put your if statement inside another if statement
If IsNumeric(txtHoursWorked.text) and IsNumeric(txtOvertime.text) Then
<Previous If Statement>
Else
Msgbox("Please Enter a Numeric Value")
End If
-
May 1st, 2003, 12:40 AM
#8
Member
Thank you very much for your help.
I hate VB and have to pretend to know it for college, but it's the only programming language the teachers know so we get lumbered with it too.
Once again thank you for everyone who's helped me out.
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
|
|