“用户定义的类型未定义”错误

时间:2015-04-17 18:41:03

标签: vb6

您好我正在尝试创建一个涉及对象和类内的简单程序 VB 6.0。

我得到的错误信息是:"用户定义的类型未定义"

VB怀疑突出显示的代码是" Dim Bob As Ball"

我定义的课程如下:

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

我项目中唯一表单的代码是:

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

我不确定为什么可疑的代码行不正确,但任何帮助都将不胜感激!

1 个答案:

答案 0 :(得分:0)

VB6不使用您编码的代码样式。 您必须遵循这些方法才能使代码与您的意图一致。 1.制作课程模块 2.设置名称' Ball' 3.将此代码粘贴到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. 在表单上粘贴代码

    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
    
  2. 此外,VB6不支持

    这样的风格
    Sub A()
        Sub B()
        End Sub
    End Sub