我想检查我的用户表单中的所有图像,并检查工作表中某些单元格中的值。然后根据值,将图像对象的图片更改为19(i1到i19)中的一个。
为了不检查每个图像,我想循环该过程。所有图像对象的名称从slot_1到slot_42。
我在下面的(插槽(a))是否可能?
编辑:我改变了你说的,但错误仍然发生。
Private Sub UserForm_Initialize()
name = Sheets("Player Data").Cells(2, 1).Value
inventory.Caption = name & "' s inventory"
name_label_inv.Caption = name
item_info_label.Visible = False
item_info_label.Caption = " "
Dim a
For a = 1 To 42 Step 1
If Sheets("Player Data").Cells(a + 1, 11).Value = 0 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\empty_icon.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 1 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_exp_book.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 2 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_silver_coin.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 3 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_gold_ingot.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 4 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_heal_hp_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 5 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_heal_mp_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 6 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_heal_hp_2.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 7 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_weapon_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 8 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_weapon_2.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 9 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_weapon_3.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 10 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_arrow.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 11 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_weapon_4.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 12 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_weapon_5.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 13 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_shield_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 14 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_armor_helmet_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 15 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_armor_chest_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 16 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_armor_ring_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 17 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_wild_1.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 18 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_wild_2.jpg")
Else
If Sheets("Player Data").Cells(a + 1, l2).Value = 19 Then
Me.Controls("slot_" & a).Picture = LoadPicture("C:\The Game\items\item_key.jpg")
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next
End Sub
1条答案
按热度按时间yeotifhr1#
在这种情况下,可以使用
Me.Controls
来访问控件。可以写成
这里有一个例子