-1

Hi im trying to create a simple program involving an object and a class within VB 6.0.

The error message i get is: "User-defined type not defined"

The highlighted code that VB suspects is "Dim Bob As Ball"

My defined class is as follows:

Dim Bob As Object

Public Sub Ball()

Dim Circlex As Integer
Dim Circley As Integer

Public Sub makeBall()
 Circlex = 3000
 Circley = 3000
End Sub

Private Sub moveBall()
 Circle (Circlex, Circley), 200
End Sub

End Sub

My code for the only form in my project is:

Private Sub Command1_Click()
 Command1.Visible = False
 Command1.Enabled = False
 vbalProgressBar1.Visible = True
 Timer1.Enabled = True
 Beep
End Sub

Private Sub Form_Load()
 Form1.Width = 6000
 Form1.Height = 6000
 Dim Bob As Ball
 Dim Bob As New Ball
End Sub

Private Sub Form_Unload(Cancel As Integer)
 If MsgBox("Are you sure you want to be a quitter?!"
 , vbYesNo,"Quit?") = vbYes Then  
 Unload Me
 Set Form1 = Nothing
Else
 Cancel = 1
End If
End Sub

Private Sub Timer1_Timer()
 Bob = moveBall(Circlex, Circley)
End Sub

Im not sure why the suspected line of code is incorrect, but any help would be appreciated!

1 Answers1

0

VB6 doesn't use code style that you coded. You have to follow these method to make code work with your intention. 1. make classmodule 2. set its name 'Ball' 3. paste this code on classmodule

Dim Circlex As Integer
Dim Circley As Integer

Public Sub makeBall()
 Circlex = 3000
 Circley = 3000
End Sub

Private Sub moveBall()
 Circle (Circlex, Circley), 200
End Sub
  1. paste code on your form

    Private Sub Command1_Click()
    Command1.Visible = False
    Command1.Enabled = False
    vbalProgressBar1.Visible = True
    Timer1.Enabled = True
    Beep
    
    End Sub
    
    Private Sub Form_Load()
     Form1.Width = 6000
     Form1.Height = 6000
     Dim Bob As New Ball
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
     If MsgBox("Are you sure you want to be a quitter?!"
     , vbYesNo,"Quit?") = vbYes Then  
     Unload Me
     Set Form1 = Nothing
    Else
     Cancel = 1
    End If
    End Sub
    
    Private Sub Timer1_Timer()
     Bob.moveBall(Circlex, Circley)
    End Sub
    

Additionally, VB6 doesn't support style like

Sub A()
    Sub B()
    End Sub
End Sub
Ux5
  • 19
  • 5