注册 登录
编程论坛 VB6论坛

下面这段小程序,编译时出现变量未定义怎么解决

yigererenren 发布于 2017-03-09 12:20, 1373 次点击
Option Explicit
Private WithEvents NewButton As CommandButton

Private Sub NewButton_Click()
    MsgBox ″您选中的是动态增加的按钮!″
    End Sub

Private Sub Command1_Click()


If NewButton Is Nothing Then
NewButton.Move Command1.Left + Command1.Width + 240, Command1.Top
    NewButton.Caption = ″新增的按钮″
    NewButton.Visible = True
    End If
Set NewButton = Controls.Add(″″, ″cmdNew″, Me)

End Sub

Private Sub Command2_Click()


If NewButton Is Nothing Then
    Else
    Controls.Remove NewButton
    Set NewButton = Nothing
    End If

End Sub
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
2 回复
#2
ZHRXJR2017-03-09 12:59
NewButton.Caption = ″新增的按钮″  你这个语句的双引号好像不是英文的双引号,程序没有按字符串处理,而是按变量处理了,应该修改为英文的双引号,如下:
NewButton.Caption = "新增的按钮"    看到与你原来代码的区别了吗?
MsgBox ″您选中的是动态增加的按钮!″   这个好像也存在这个问题。
Set NewButton = Controls.Add(″″, ″cmdNew″, Me)  同样双引号也有问题。
#3
yigererenren2017-03-10 09:34
回答详细谢谢
1