[RESOLVED] Arrays! How to define one
I am working on a video game. I used to code in qbasic and I would to create a map array use
for x=1 to 15
for y=1 to 13
read map0(x,y)
next
next
code
code
code
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
data 1,2,3,4,2,7,3,4,9,6,1,3,5,2,4
something like that. how can i do this in visual basic without 15*13 lines of code
map0(1,1)=1
map0(1,2)=3
map0(1,3)=7
and so on
Re: Arrays! How to define one
If you're moving upwards by in a sequential "fashion", say, by 1's, 2's, 3's, etc, then it would be like this:
VB Code:
Dim map0(15,13) As Long
Dim x As Long, y As Long
For x = 1 To 15
For y = 1 To 13
If (x > 0) Then
map0(x,y) = map0(x - 1, y - 1) + 3
End If
Next y
Next x
That would of course, add by 3 each time. That what you were after?
chem
Re: Arrays! How to define one
Hi damasterjo, welcome to VBForums! :wave:
There isn't a direct replacement, typically these days people use files to store the data instead - which makes sense seeing as the amount of data usually stored by a program has increased dramtically.
This also gives more flexability, as you can have multiple files to load the data from (eg: one for each level in your game), and you can write another program (like a map editor) to let you plan it on-screen, then write the file for you.
To see examples of reading/writing data to a file, see the Classic VB FAQ link in my signature. If you need help converting this data into an array (or deciding what format to store the data, etc) then let us know. :)
Re: Arrays! How to define one
Oh stupid me. Its been so long since I've even touched my QBasic editor in a CMD window :D
My bad.
chem
Re: Arrays! How to define one
Same here, but I distincly remember having to type out loads of those "Data" lines, and write code to show me my mistakes! :sick:
1 Attachment(s)
Re: Arrays! How to define one
ok thanks for the advice. ONe more question though I have never used access before but i did figure out how to use a table. I have an attachment of what I created now can someone tell me how I would take field1-field15 and put it into the array map0 (1 to 15, 1 to 11). That would be awesome.
Re: Arrays! How to define one
Ah, if you have it in a database then that isn't quite the same, and you need to use a different method to get the data. If you look at the 'ADO Tutorial' link in my signature, this will give you an example of how to get data from a database.
When you get data from a database it is stored in a RecordSet (basically a glorified array - but you can only read one row of data at a time), so you may or may not want to transfer the data to an array. If you need help, we're here :)
Re: Arrays! How to define one
hey awesome im using txt files now but how do i write in a text file
1,2,3,4,5,6
2,3,4,5,7,8
like that . in the example i saw it would do like
1
2
3
4
5
6
2
3
4
5
7
8
Re: Arrays! How to define one
never mind i got everything i need thank you so much