|
-
Sep 19th, 2006, 05:08 PM
#1
Thread Starter
Hyperactive Member
[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
Hey... If you found this post helpful please rate it.

-
Sep 19th, 2006, 05:19 PM
#2
PowerPoster
Re: Error Checking
Natural number? You mean whole number? try "if int(lngmonths) = lngmonths then" as int() returns the integer value (so if you did int(10.4) you'd get 10)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 20th, 2006, 10:21 AM
#3
Thread Starter
Hyperactive Member
Re: Error Checking
Well... I don't really want to convert it into an integer. I want to display and error message when the user doesn't enter a whole number.
Khanjan
Hey... If you found this post helpful please rate it.

-
Sep 20th, 2006, 10:41 AM
#4
Re: Error Checking
Check for a decimal point
VB Code:
If InStr(1, strMonths, ".") Then
MsgBox "Must Be Whole Numbers"
Else
MsgBox "Number is good"
End If
-
Sep 20th, 2006, 10:42 AM
#5
Thread Starter
Hyperactive Member
Re: Error Checking
Thanx hax... Actually I just thought of that and I was just about to post that I had found a solution. Anyways thanx for your help guys. I appreciate it a lot.
Khanjan
Hey... If you found this post helpful please rate it.

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
|
Click Here to Expand Forum to Full Width
|