Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hey, this seems so simple but I've been staring at this code for an
hour or so and can't figure out what's wrong. I'm a new VBA programmer, so forgive me if this is a really dumb question. I keep getting Error 9 - Subscript out of range for this Sub. It happens on the first time through the loop, on this line: dealercard(cardnum).Picture = images(10).Picture I'm not sure why at that point the array index wouldn't be out of range, but if you can help, please do. Here's the code (sorry its long): --------------------------------------------------------------------------------------- Private Sub CommandButton1_Click() Dim images(1 To 13) As Image Dim cardnum, total, house As Integer Dim result As String Dim dealercard() As Image Dim playercard() As Image Set images(1) = New Image Set images(2) = New Image Set images(3) = New Image Set images(4) = New Image Set images(5) = New Image Set images(6) = New Image Set images(7) = New Image Set images(8) = New Image Set images(9) = New Image Set images(10) = New Image Set images(11) = New Image Set images(12) = New Image Set images(13) = New Image images(1).Picture = imgTwod.Picture images(2).Picture = imgThreed.Picture images(3).Picture = imgFourd.Picture images(4).Picture = imgFived.Picture images(5).Picture = imgSixd.Picture images(6).Picture = imgSevend.Picture images(7).Picture = imgEightd.Picture images(8).Picture = imgNined.Picture images(9).Picture = imgTend.Picture images(10).Picture = imgJackd.Picture images(11).Picture = imgQueend.Picture images(12).Picture = imgKingd.Picture images(13).Picture = imgAced.Picture result = vbYes Do Until result = vbNo house = Int(13 * Rnd()) + 1 For cardnum = 1 To 7 If house = 1 Then dealercard(cardnum).Picture = images(1).Picture house = 2 ElseIf house = 2 Then dealercard(cardnum).Picture = images(2).Picture house = 3 ElseIf house = 3 Then dealercard(cardnum).Picture = images(3).Picture house = 4 ElseIf house = 4 Then dealercard(cardnum).Picture = images(4).Picture house = 5 ElseIf house = 5 Then dealercard(cardnum).Picture = images(5).Picture house = 6 ElseIf house = 6 Then dealercard(cardnum).Picture = images(6).Picture house = 7 ElseIf house = 7 Then dealercard(cardnum).Picture = images(7).Picture house = 8 ElseIf house = 8 Then dealercard(cardnum).Picture = images(8).Picture house = 9 ElseIf house = 9 Then dealercard(cardnum).Picture = images(9).Picture house = 10 ElseIf house = 10 Then 'error occurs at this line dealercard(cardnum).Picture = images(10).Picture house = 10 ElseIf house = 11 Then dealercard(cardnum).Picture = images(11).Picture house = 10 ElseIf house = 12 Then dealercard(cardnum).Picture = images(12).Picture house = 10 ElseIf house = 13 Then dealercard(cardnum).Picture = images(13).Picture house = 1 End If total = house cardnum = cardnum + 1 result = MsgBox("You have a total of " & total & "." & Chr(13) & Chr(13) & "Do you want another card?", vbYesNo, "Total") Next Loop End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Subscript Out of Range | Excel Programming | |||
Subscript out of range.... | Excel Programming | |||
Subscript out of range | Excel Programming | |||
Subscript out of Range Q | Excel Programming | |||
Subscript out of range | Excel Programming |