Results 1 to 6 of 6

Thread: Dynamic arrays??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29
    Uh... this is a little bit difficult to explain, but I'll try:

    Code:
    Sub InitTextures()
     layers=2
     ReDim numtextures(1 To layers)
     numtextures(1) = 2
     numtextures(2) = 1
    
     ReDim Textures(1 To layers, 1 To numtextures(x))  '<- the problem is here
    
     Slider1.Min = 1
     Slider1.Max = numtextures(1)
     Set Textures(1, 1) = CreateTextureSurface(App.Path & "\test.bmp")
     Set Textures(1, 2) = CreateTextureSurface(App.Path & "\test2.bmp")
     Set Textures(2, 1) = CreateTextureSurface(App.Path & "\tst1.bmp")
    End Sub
    Now, the problem is quite strange. In textures array, the value of second dimension should be relative to the first, so that when the 1st. dimension's value is 1, the maximum value of the 2nd. should be 2. And when the value of the first is 2, the max of second is 1.
    Is it even possible to do this, and if not, could someone tell how to make something that works in the same way?

  2. #2
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    Code:
    An array may be 
    1-dimentional. (XXXXXXXXX)
    
    2-dimentional. (XXXXXX)
                   (XXXXXX)
                   (XXXXXX)
    
    and so on.
    
    You are trying to make an wierd array that looks like this?
    (XXXXXXXX)
    (XXX)
    (XXXXXX)
    (XXXX)
    
    This cant be done. You will have to make the second dimention as large or larger as the largest number of textures you are going to use. In your example that is 
    Redim Textures(1 To layers, 2).
    
    Try using the Collection object.
    
    Dim A() As Collection
    ReDim A(1 To layers)
    A(0).Add CreateTextureSurface(App.Path & "\test.bmp")
    A(0).Add CreateTextureSurface(App.Path & "\test2.bmp")
    A(1).Add CreateTextureSurface(App.Path & "\tst1.bmp")
    and so on...
    
    Then later ie. use:
    For Each V in A(0)
      RenderTexture V
    Next V

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    How is 'Textures' defined?
    -Shickadance

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29
    It's textures() as directdrawsurface7 but it doesn't matter. To thomas, that's what I suspected, I just wasn't sure about it.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Works fine for me!

    I copied your code and made a few changes so it looks like this

    Code:
    ' module code
    
    Public Textures() As String  '(I just needed something to init)
    
    
    ' form code
    
    Private Sub Command1_Click()
    
     Dim numtextures() As Integer
     layers = 2
     ReDim numtextures(1 To layers)
     numtextures(1) = 2
     numtextures(2) = 1
    
     ReDim Textures(1 To layers, 1 To numtextures(2)) 
    
    End Sub
    I hit the command1 button and then in debug mode checked a watch on textures and it had initialised fine.

    no errors.

    I changed the numtextures(x) with numtextures(2) because x wasn't defined anywhere but I assume thats what you meant (and not a for loop which wouldn't achieve much)
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    To Thomas Halsvik,

    This is not an attempt to define an irregular array but an attempt to define an array's size as the size of the value on another array.

    The point is that every time the sub is run the array will resize to the value of the next item in the array which holds the texture size.

    So each iteration of the sub with have an appropriately sized array

    Irregular array can be created though, but they are a little more complex that just DIM,ing them, they need to be set up first.

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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