Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Subscript of of range, please help.


achap89
 Share

Recommended Posts

Im trying to get a part of a picture.
```
Dim itemnum
Dim itempic
Dim MaxFrames
MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32
itemnum = GetPlayerEquipment(MyIndex, weapon)
If itemnum > 0 Then
itempic = Item(itemnum).Pic
Picture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")
Else
Exit Sub
End If

```
It highlights
```
MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32
```
What am i doing wrong?
Link to comment
Share on other sites

```
Dim itemnum
Dim itempic
Dim MaxFrames

```
You need to declare what type of variables these will be.

ex
```
Dim MaxFrames as Long

```
and Subscript out of range means your trying to access an element of an array that does not exist, make sure itempic is within the proper range of the DDSD_Item array.
Link to comment
Share on other sites

```
Dim itemnum
Dim itempic
Dim MaxFrames As Byte
Dim DDSD_Item As DDSURFACEDESC2
MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32
itemnum = GetPlayerEquipment(MyIndex, weapon)
If itemnum > 0 Then
itempic = Item(itemnum).Pic
Picture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")
Else
Exit Sub
End If

```give me "compile error expexted array"
and highlights the DDSD_Item
Link to comment
Share on other sites

You don't even have a type declared for itempic in the last snipit you posted, a subscript out of range error means your trying to access a part of an array that does not exist, so make sure your not feeding any numbers above or below its range into that array.

Example.
If an array is set to be 1-10and you try to call 11 or 0 you get a subscript out of range.

```
Dim TestArray(1 To 10) as Long

TestArray(11) = 4

```This would give you a subscript out of range because it's not using a number between 1 and 10 which is the min/max elements of this array.
Link to comment
Share on other sites

Ok well can you help me because I am new to coding XD  I do have a type now it is a long.

Private Sub Picture1_Click()

Dim itemnum As Long
Dim itempic As Long
Dim MaxFrames
itempic = Item(itemnum).Pic
MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32
itemnum = GetPlayerEquipment(MyIndex, weapon)
If itemnum > 0 Then
Picture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")
Else
Exit Sub
End If

End Sub

That was the whole code.

also its in the frmmain

sorry for the double post.

[Please do not double post.]
Link to comment
Share on other sites

1\. It seems MaxFrames lost its type again.

2.What are you trying to do here?

3.Use code tags please makes it easier to read

4.Format your code its annoying to read like that.

```
Dim itemnum As Long
Dim itempic As Long
Dim MaxFrames As Byte

    MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32
    itemnum = GetPlayerEquipment(MyIndex, weapon)

    If itemnum > 0 Then
        itempic = Item(itemnum).Pic
        Picture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")
    Else
        Exit Sub
    End If

```This should fix the subscript error, you where trying to use itemnum before you assigned it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...