Forum Home
Press F1
 
Thread ID: 24760 2002-09-18 08:08:00 Visual basic "Val function Nigel Thomson (629) Press F1
Post ID Timestamp Content User
80639 2002-09-18 08:08:00 hello people
The problem is this how do i use the val function in VB to throw up an error if the input variable is a letter instead of a number as it seems to convert it to its ascii equivalent.
In delphi the val function throws out an error message if the input variable is a letter instead of a number.
I am a student and the system here does not have the VB helpfiles so I can't find anything about the val function apart from the very basics.

thanks in advance
Nigel Thomson (629)
80640 2002-09-18 08:53:00 Hi Nigel, you will first need to do an if statement using IsNumric to see if its a number or not.

Example, with error produced and focus turned to invalid field

If IsNumeric(FieldName) = false then
msgbox "Must be numeric"
FieldName.SetFocus
exit sub
else val(FieldName)
end if

cheers
Parry
parry (27)
80641 2002-09-18 09:18:00 Thankyou parry, I had just found the isnumeric function on w3 schools so thankyou for your help. Nigel Thomson (629)
80642 2002-09-18 09:28:00 My pleasure. Must be a real pain without the help files. If you have MSOffice you could ltry looking in the VB editor and go to help there as the statements and syntax are pretty much the same. :-) parry (27)
1