|
-
Nov 17th, 2002, 05:47 PM
#1
Thread Starter
Fanatic Member
Multidimensional array
i want to redclare a multidimensional array, but it tells me that the subscript is out of range. im using redim preserve, heres the code:
VB Code:
Public Map() As Byte
Public Sub LoadMap(MapPath As String)
Dim Line, Token As String
Dim HCounter, VCounter As Integer
Open App.Path & "\maps\" & MapPath & ".map" For Input As #1
Do Until EOF(1)
VCounter = VCounter + 1
Line Input #1, Line
Do While HCounter <= Len(Line)
HCounter = HCounter + 1
ReDim Preserve Map(HCounter, VCounter)
Token = Mid(Line, HCounter, 1)
If Token > 0 Then
Map(HCounter, VCounter) = 0
Else
Map(HCounter, VCounter) = 1
End If
Select Case Token
Case "0"
frmScreen.Picture = LoadPicture(App.Path & "\graphics\grass.gif")
Case "1"
frmScreen.Picture = LoadPicture(App.Path & "\graphics\water.gif")
End Select
BitBlt frmScreen.picGame.hDC, (HCounter - 1) * 40, (VCounter - 1) * 40, 40, 40, frmScreen.hDC, 0, 0, SRCCOPY
Loop
Loop
End Sub
The code is in a module. Does anyone know whats wrong?
-
Nov 17th, 2002, 05:51 PM
#2
Lively Member
ReDim Preserve only allows you to change the size of the last subscript of an array. In your example you can only change the size of vCounter.
tecnithV -- artisan, artificer, workman, mechanic, architect, or builder
VB6, ASP, HTML, XML, Oracle, Access, MySql, PHP, C++, Etc...
To format your VB code in this forum use tags like this [vbcode] your code here[/vbcode]
-
Nov 17th, 2002, 05:53 PM
#3
Thread Starter
Fanatic Member
what should i use insted then?
-
Nov 17th, 2002, 05:56 PM
#4
yay gay
-
Nov 17th, 2002, 05:57 PM
#5
Hyperactive Member
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Nov 17th, 2002, 05:59 PM
#6
Thread Starter
Fanatic Member
two arrays wont work, that would layout the map like this:
0
0
0
0
i need this:
0000000000000
0000000000000
0000000000000
how do collections work? what are collections?
-
Nov 17th, 2002, 06:01 PM
#7
Need-a-life Member
Originally posted by Mushroom Realm
two arrays wont work, that would layout the map like this:
0
0
0
0
i need this:
0000000000000
0000000000000
0000000000000
how do collections work? what are collections?
It won't if you know how to implement it.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:03 PM
#8
Hyperactive Member
2 arrays and 2 indexs can work the same way as a single multi dimensional array. Define one for x and another for y and bingo! Use a class to define functions to manipulate the arrays.
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Nov 17th, 2002, 06:04 PM
#9
Thread Starter
Fanatic Member
what wont? when i typed the two array part i meant it to be diagonal, something must have changed it.
-
Nov 17th, 2002, 06:05 PM
#10
Need-a-life Member
Originally posted by Mushroom Realm
what wont? when i typed the two array part i meant it to be diagonal, something must have changed it.
diagonal? What do you mean?
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:08 PM
#11
Thread Starter
Fanatic Member
i should say maybe like this:
0000000000000000000
01
0 1
0 1
0 1
0
0
0
0
the zeros r the actual arrays, the 1's represent a visual image as if in x,y form
-
Nov 17th, 2002, 06:10 PM
#12
Hyperactive Member
A diagonal array is very, very strange. What do you mean? And why do you want a diagonal array? How does that differ from a single dimensional array?
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Nov 17th, 2002, 06:10 PM
#13
Need-a-life Member
I don't understand what you mean... but for example:
VB Code:
Dim Position(5, 5) As Integer
would be the same as:
VB Code:
Dim x(5) As Integer, y(5) As Integer
It's just a matter on how you code it later...
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:11 PM
#14
Hyperactive Member
Okay, i get what you mean now. But how will 2 arrays not implement this?
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Nov 17th, 2002, 06:12 PM
#15
Thread Starter
Fanatic Member
the first way gives you 5*5 variables, the second way (two arrays) only gives you 10
-
Nov 17th, 2002, 06:13 PM
#16
Need-a-life Member
Originally posted by Mushroom Realm
the first way gives you 5*5 variables, the second way (two arrays) only gives you 10
No!! It will give 25 as well
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:15 PM
#17
Need-a-life Member
x(0), y(0)
x(0), y(1)
x(0), y(2)
x(0), y(3)
x(0), y(4)
x(1), y(0)
x(1), y(1)
x(1), y(2)
x(1), y(3)
x(1), y(4)
x(2), y(0)
x(2), y(1)
x(2), y(2)
x(2), y(3)
x(2), y(4)
x(3), y(0)
x(3), y(1)
x(3), y(2)
x(3), y(3)
x(3), y(4)
x(4), y(0)
x(4), y(1)
x(4), y(2)
x(4), y(3)
x(4), y(4)
There you have the 25 combinations....
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:17 PM
#18
Thread Starter
Fanatic Member
but im only storing one byte, so u cant merge the x and the y, and two arrays would also require that example: the value for the x(2) be the same in every line (y), (x(2) used as example)
-
Nov 17th, 2002, 06:18 PM
#19
Hyperactive Member
Wrong. If you code it right you get 25 with 2 arrays
1 2 3 4 5
1
2
3
4
5
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Nov 17th, 2002, 06:18 PM
#20
Need-a-life Member
Originally posted by Mushroom Realm
so u cant merge the x and the y
What do you mean?
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2002, 06:20 PM
#21
Thread Starter
Fanatic Member
u have x(0),y(0) x(0),y(1) im assuming u meant to merge the valuse of x(0),Y(0) or whatever so that u could have 25
-
Nov 17th, 2002, 06:20 PM
#22
The picture isn't missing
Originally posted by Mc Brain
x(0), y(0)
x(0), y(1)
x(0), y(2)
x(0), y(3)
x(0), y(4)
x(1), y(0)
x(1), y(1)
x(1), y(2)
x(1), y(3)
x(1), y(4)
x(2), y(0)
x(2), y(1)
x(2), y(2)
x(2), y(3)
x(2), y(4)
x(3), y(0)
x(3), y(1)
x(3), y(2)
x(3), y(3)
x(3), y(4)
x(4), y(0)
x(4), y(1)
x(4), y(2)
x(4), y(3)
x(4), y(4)
There you have the 25 combinations....
but you can't store 25 info like that, you could only store 5, because it would overwrite the previous y values (look carefully and you will know what i mean)
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Nov 17th, 2002, 06:22 PM
#23
-
Nov 17th, 2002, 06:27 PM
#24
Need-a-life Member
VB Code:
Option Explicit
Private Type MyType
y(4) As Integer
End Type
Dim x(4) As MyType
Private Sub Form_Load()
Dim i As Integer, j As Integer
For i = 0 To 4
For j = 0 To 4
x(i).y(j) = i * 5 + j
Next j
Next i
For i = 0 To 4
For j = 0 To 4
Debug.Print x(i).y(j)
Next j
Next i
End Sub
There you have.... 25 different numbers
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|