Results 1 to 5 of 5

Thread: [RESOLVED] Error Checking

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Resolved [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:
    1. Do
    2.    
    3.         strMonths = InputBox("Please enter the number of months over which you wish the loan to be repaid. It must be a natural number", "Months")
    4.        
    5.         If StrPtr(strMonths) = 0 Then
    6.        
    7.             Exit Sub
    8.            
    9.         End If
    10.        
    11.         If strMonths = "" Or IsNumeric(strMonths) = False Then
    12.        
    13.             MsgBox "Please enter numbers only", , "Months Error - Numbers Only"
    14.            
    15.         End If
    16.            
    17.         If strMonths <> "" And IsNumeric(strMonths) = True Then
    18.                        
    19.             If lngMonths Mod 1 <> 0 Then
    20.        
    21.                 MsgBox "Please enter natural numbers only", vbCritical, "Months Error - Natural Numbers Only"
    22.        
    23.             End If
    24.            
    25.         End If
    26.        
    27.     Loop Until strMonths <> "" And IsNumeric(strMonths) = True And Val(strMonths) Mod 1 = 0
    Hey... If you found this post helpful please rate it.

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Error Checking

    Check for a decimal point
    VB Code:
    1. If InStr(1, strMonths, ".") Then
    2.    MsgBox "Must Be Whole Numbers"
    3. Else
    4.    MsgBox "Number is good"
    5. End If

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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
  •  



Click Here to Expand Forum to Full Width