[RESOLVED] Error Checking
Hey,
I am making a program where I am checking for invalid inputs from inputboxes.
I want to user to enter the amount of months for a loan into an inputbox. However, I am not being able to successfully check the problem. I tried the following but it did not work. I was hooping if someone could help me.
What I am doing is that I am check if the input is numbers or not... If it isn't a number then I ask the user to enter it again... However Once I get a number, I want to be able to check if it is a natural number or not. This is where I am having a problem. I am using the mod function, I am modding by 1 and checking if the remainder is 0, which it shouldn't be if the number is a decimal, however for some reason it is providing the number 0. Could someone help please.
VB Code:
Do
strMonths = InputBox("Please enter the number of months over which you wish the loan to be repaid. It must be a natural number", "Months")
If StrPtr(strMonths) = 0 Then
Exit Sub
End If
If strMonths = "" Or IsNumeric(strMonths) = False Then
MsgBox "Please enter numbers only", , "Months Error - Numbers Only"
End If
If strMonths <> "" And IsNumeric(strMonths) = True Then
If lngMonths Mod 1 <> 0 Then
MsgBox "Please enter natural numbers only", vbCritical, "Months Error - Natural Numbers Only"
End If
End If
Loop Until strMonths <> "" And IsNumeric(strMonths) = True And Val(strMonths) Mod 1 = 0