红色的部分有错误,提示说:对象变量或With块变量未设置
求大家该怎么办?
Dim myPicture() As PictureBox
Private Sub Command1_Click() Dim DlgInfo As DlgFileInfo
Dim I As Integer
'清除List1中的项
List1.Clear
'选择文件
With CommonDialog1
.CancelError = True
.MaxFileSize = 32767
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.DialogTitle = "选择文件"
.Filter = "(*.jpg)|*.jpg"
.ShowOpen
DlgInfo = GetDlgFileInfo(.FileName)
ReDim Preserve myPicture(DlgInfo.iCount)
End With
For I = 1 To DlgInfo.iCount
List1.AddItem DlgInfo.sPath & DlgInfo.sFile(I)
ImageList1.ListImages.Add , , LoadPicture(DlgInfo.sPath & DlgInfo.sFile(I)) '往ImageList当中添加图片
myPicture(I).Picture = ImageList1.ListImages(I).Picture
Next I
Exit Sub
ErrHandle:
'按了“取消”按钮 End Sub
求大家该怎么办?
Dim myPicture() As PictureBox
Private Sub Command1_Click() Dim DlgInfo As DlgFileInfo
Dim I As Integer
'清除List1中的项
List1.Clear
'选择文件
With CommonDialog1
.CancelError = True
.MaxFileSize = 32767
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.DialogTitle = "选择文件"
.Filter = "(*.jpg)|*.jpg"
.ShowOpen
DlgInfo = GetDlgFileInfo(.FileName)
ReDim Preserve myPicture(DlgInfo.iCount)
End With
For I = 1 To DlgInfo.iCount
List1.AddItem DlgInfo.sPath & DlgInfo.sFile(I)
ImageList1.ListImages.Add , , LoadPicture(DlgInfo.sPath & DlgInfo.sFile(I)) '往ImageList当中添加图片
myPicture(I).Picture = ImageList1.ListImages(I).Picture
Next I
Exit Sub
ErrHandle:
'按了“取消”按钮 End Sub
myPicture(I-1).Picture = ImageList1.ListImages(I-1).Picture
List1.AddItem DlgInfo.sPath & DlgInfo.sFile(I)
ImageList1.ListImages.Add , , LoadPicture(DlgInfo.sPath & DlgInfo.sFile(I)) '往ImageList当中添加图片
Set myPicture(I) = Controls.Add("vb.PictureBox", "myPicture")
Set myPicture(I).Picture = ImageList1.ListImages(I).Picture
Picture1.Picture = myPicture(1).Picture
红色句子部分只能使一个MyPicture有效,到第二个的时候就会提示已经有一个MyPicture了,怎么样才能利用红色句子来创建PictureBox数组呢?