一个送分题...对象变量或 With 块变量未设置,大家来研究研究...
代码如下,位于模块中,提示"对象变量或 With 块变量未设置"错误
Dim picToolBarHot As PictureBox
With picToolBarHot
.Picture = LoadPicture(App.Path & "\rescore\" & filename & ".bmp")
End With
后来看了相关帖子,说是仅仅定义了,没有实例化
将程序改成
Dim picToolBarHot As PictureBox
Set picToolBarHot = New PictureBox '不知道这样可以实例化对象否
With picToolBarHot
.Picture = LoadPicture(App.Path & "\rescore\" & filename & ".bmp")
End With
又提示无效的NEW关键字
我查了VB的对象浏览器,PictureBox是位于VB对象中的,
后来又改成
Dim picToolBarHot As VB.PictureBox
Set picToolBarHot = New VB.PictureBox
我在输入VB后出现的下拉菜单里并没有PictureBox,只有一个Global
后面的代码照样还是不能执行.
请问我到底要怎样做,才能在模块中使用PictureBox载入一幅图片执行操作
下面是这个过程的完整代码.
Public Sub initImage(img As ImageList, filename As String)
Dim picToolBarHot As VB.PictureBox
Set picToolBarHot = New VB.Global
Dim pictemp As VB.PictureBox
Set pictemp = New VB.Global
With picToolBarHot
.Picture = LoadPicture(App.Path & "\rescore\" & filename & ".bmp")
End With
For i = 0 To 6
pictemp.Cls
pictemp.PaintPicture picToolBarHot.Picture, 0, 0, 24 * 15, 24 * 15, i * 24 * 15, 0, 24 * 15, 24 * 15
img.ListImages.Add , , pictemp.Image
Next
End Sub