Results 1 to 9 of 9

Thread: [RESOLVED] Arrays! How to define one

  1. #1

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Resolved [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

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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:
    1. Dim map0(15,13) As Long
    2.  
    3. Dim x As Long, y As Long
    4.  
    5. For x = 1 To 15
    6.     For y = 1 To 13
    7.         If (x > 0) Then
    8.             map0(x,y) = map0(x - 1, y - 1) + 3
    9.         End If
    10.     Next y
    11. Next x
    That would of course, add by 3 each time. That what you were after?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Arrays! How to define one

    Hi damasterjo, welcome to VBForums!

    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.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

    My bad.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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!

  6. #6

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Arrow 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.
    Attached Images Attached Images  

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  8. #8

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    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

  9. #9

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Arrays! How to define one

    never mind i got everything i need thank you so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width