Re: InputErrorHandler - school assignment


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Re: InputErrorHandler - school assignment

  1. #1
    Walt Guest

    Re: InputErrorHandler - school assignment


    "Jim Pragit" <James.Pragit@BakerNet.com> wrote:
    >
    >"Jim Pragit" James. wrote:
    >>if this is an assignment for school?

    >
    >I meant, "is this an assignment for school?".
    >
    >- Jim




    Yes this is an assignment, There are a list of about 20 items of which we
    were to incorporate as many
    as possible in a project.

    David

  2. #2
    Jim Pragit Guest

    Re: InputErrorHandler - school assignment


    Do you have to use an input box and a loop? If so, things get a quite tricky.
    First, the user can press either the OK button or the Cancel button. You
    have to watch for that. Second, just because the user pressed the OK button,
    doesn't mean they actually typed anything in. You have to look for that as
    well.

    Here's a code snippet that performs these checks:

    Dim strUsersInput As String

    strUsersInput = InputBox("Enter Last Name:")

    'check to see if user pressed OK button
    If StrPtr(strUsersInput) > 0 Then
    'check to see if user typed something in
    If Len(strUsersInput) > 0 Then
    'data is valid, you can add it to your array here
    Else
    MsgBox "User pressed OK button but didn't type anything in", vbExclamation
    End If
    Else
    MsgBox "User pressed Cancel button", vbExclamation
    End If

    StrPtr is an undocumented function that returns a pointer to a string. I'm
    not sure how much detail you need or want to know about why this works, so
    for now suffice it to say that if StrPtr(strUsersInput) is 0, then the user
    pressed the Cancel button.

    Here's a code snippet that asks for the user's input. Note that there are
    even more things you need to check:

    strUsersInput = InputBox("Enter SSN:")

    'check to see if user pressed OK button
    If StrPtr(strUsersInput) > 0 Then
    'check to see if user user typed something in
    If Len(strUsersInput) > 0 Then
    'check to see if user's input is numeric
    If IsNumeric(strUsersInput) = True Then
    'check to see if user's input is 9 digits long
    If Len(strUsersInput) = 9 Then
    'data is valid, you can add it to your array here
    Else
    MsgBox "User didn't type in 9 numbers.", vbExclamation
    End If
    Else
    MsgBox "User's input isn't numeric.", vbExclamation
    End If
    Else
    MsgBox "User pressed OK button but didn't type anything in", vbExclamation
    End If
    Else
    MsgBox "User pressed Cancel button", vbExclamation
    End If

    Hopefully, this gives you an idea of what's involved. The hard part is re-prompting
    the user if their input is invalid. This involves using GoTos or multiple
    loops.

    - Jim


  3. #3
    Walt Guest

    Re: InputErrorHandler - school assignment


    "Jim Pragit" <James.Pragit@BakerNet.com> wrote:
    >
    >Do you have to use an input box and a loop? If so, things get a quite tricky.
    > First, the user can press either the OK button or the Cancel button. You
    >have to watch for that. Second, just because the user pressed the OK button,
    >doesn't mean they actually typed anything in. You have to look for that

    as
    >well.
    >
    >Here's a code snippet that performs these checks:
    >
    > Dim strUsersInput As String
    >
    > strUsersInput = InputBox("Enter Last Name:")
    >
    > 'check to see if user pressed OK button
    > If StrPtr(strUsersInput) > 0 Then
    > 'check to see if user typed something in
    > If Len(strUsersInput) > 0 Then
    > 'data is valid, you can add it to your array here
    > Else
    > MsgBox "User pressed OK button but didn't type anything in", vbExclamation
    > End If
    > Else
    > MsgBox "User pressed Cancel button", vbExclamation
    > End If
    >
    >StrPtr is an undocumented function that returns a pointer to a string.

    I'm
    >not sure how much detail you need or want to know about why this works,

    so
    >for now suffice it to say that if StrPtr(strUsersInput) is 0, then the user
    >pressed the Cancel button.
    >
    >Here's a code snippet that asks for the user's input. Note that there are
    >even more things you need to check:
    >
    > strUsersInput = InputBox("Enter SSN:")
    >
    > 'check to see if user pressed OK button
    > If StrPtr(strUsersInput) > 0 Then
    > 'check to see if user user typed something in
    > If Len(strUsersInput) > 0 Then
    > 'check to see if user's input is numeric
    > If IsNumeric(strUsersInput) = True Then
    > 'check to see if user's input is 9 digits long
    > If Len(strUsersInput) = 9 Then
    > 'data is valid, you can add it to your array here
    > Else
    > MsgBox "User didn't type in 9 numbers.", vbExclamation
    > End If
    > Else
    > MsgBox "User's input isn't numeric.", vbExclamation
    > End If
    > Else
    > MsgBox "User pressed OK button but didn't type anything in", vbExclamation
    > End If
    > Else
    > MsgBox "User pressed Cancel button", vbExclamation
    > End If
    >
    >Hopefully, this gives you an idea of what's involved. The hard part is

    re-prompting
    >the user if their input is invalid. This involves using GoTos or multiple
    >loops.
    >
    >- Jim
    >


    Jim:

    Thanks for your input on the three responses, esp for your code snippets,
    very helpful for a newbie to
    see how the code tests can be strung together.

    Regards,

    Walt



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center