Results 1 to 3 of 3

Thread: Basic Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Location
    Bismarck
    Posts
    2
    I am new to vb, obviously. I have a book and typed in an example, which appears below. You don't have to read it all, but this is all the book gave me. What I don't understand is that I typed it into a new modulw (not attached to a form) because I thought that the message box function would bring up a messagebox. Why does nothing come up when I run it? What code should I add, or should I enclose this in a subroutine, and call it? I tried to call it, but I get errors. A stupid question, but I just don't understand.

    Thanks for any help


    [email protected]



    Dim STRAGE As String
    Dim intage As Integer
    Dim intpress As Integer

    ' Get the age in a string variable
    STRAGE = InputBox("How old are you?", "age Ask")
    ' Check for the cancel command button
    If (STRAGE = "") Then
    End 'Terminates the application
    End If
    ' Cancel was not pressed, so convert Age to integer
    ' The Val() function converts strings to integers
    intage = Val(STRAGE)

    'Loop if the age is not in the correct range
    Do While ((intage < 10) Or (intage > 99))
    ' The user's age is out of range
    intpress = MsgBox("Your Age must be between " & _
    "10 and 99", vbExclamation, "error!")
    STRAGE = InputBox("How old are you?", "Age Ask")

    ' Check for the Cancel command button
    If (STRAGE = "") Then
    End 'Treminate the program
    End If
    intage = Val(STRAGE)
    Loop

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Put that code in a public function, then open the immediate window and type the name of the function and hit enter.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'I altered your code a litte..just open a new app and copy
    'and paste this code into the general declarations and press run.
    'don't use End...use unload as end is a problem child that will cause problems later when your code evolves
    
    
    Option Explicit
    
    Private Sub Form_Load()
        Form1.Visible = False
        Dim STRAGE As String
        Dim intage As Integer
        Dim intpress As Integer
        
        ' Get the age in a string variable
        STRAGE = InputBox("How old are you?", "age Ask")
        ' Check for the cancel command button
        If STRAGE = "" Then
             Unload Me
             Exit Sub
        End If
        ' Cancel was not pressed, so convert Age to integer
        ' The Val() function converts strings to integers
        intage = Val(STRAGE)
        
        'Loop if the age is not in the correct range
        Do While ((intage < 10) Or (intage > 99))
        ' The user's age is out of range
        intpress = MsgBox("Your Age must be between " & _
        "10 and 99", vbExclamation, "error!")
        STRAGE = InputBox("How old are you?", "Age Ask")
        intage = Val(STRAGE)
        Loop
        MsgBox "You have told me that your are " & intage & " years old.", vbInformation, "Age Factor"
        Unload Me  'quit app
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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