PDA

View Full Version : vba example



zulfahmi
12-05-2018, 01:19 AM
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.

大灰狼1976
12-05-2018, 09:53 PM
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.:)

Kenneth Hobs
12-06-2018, 10:02 AM
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.