Consulting

Results 1 to 3 of 3

Thread: vba example

  1. #1

    vba example

    Dim studentName(10) As String
    Dim num As Integer
    Private Sub addName()
    For num = 1 To 10
    studentName(num) = InputBox("Enter the student name", "Enter Name", "", 1500, 4500)
    If studentName(num) <> "" Then
    Form1.Print studentName(num)
    Else
    End
    End If
    Next
    End Sub
    Private Sub Exit_Click()
    End
    End Sub
    Private Sub Start_Click()
    Form1.Cls
    addName
    End Sub

    Here in this code what does "Form1.cls" mean,whether it is userform or module or classmodule.what does ".cls" mean.I found this code in one of vba pdf online.If i paste this code in userform1 and run this code (start_click) userform1 shows up and when i press start it delivers run time error 424 object recquired error message.Please help.

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    This is vb code not vba code.
    Form1.Cls = "Clear the printed content on the form" ==>from Baidu Translate
    I am not good at English, Sorry!
    I hope that would be useful for you.

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Cls would mean a Class in VBA. You did not post code for the class object.

    It is usually best to Compile your project before running the code. Then you would see the errors. If you run code, to debug, you can run each line by F8.

    addName was not defined either so that would have to be posted as well.

    For the Form1.Print, you probably should use:
    Debug.Print studentName(num)
    That prints the value(s) to the VBE's Immediate Window.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •