Results 1 to 7 of 7

Thread: Please, Help! I'm trying something...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Exclamation Please, Help! I'm trying something...

    Hi!

    I have a problem!
    This file has a simple project that calls an A string.
    The string is declared like this: Private A() as String.
    When I want to use it I do:
    ReDim A(1)
    A(1) = "Arie"
    Print A(1)

    Goes well! But then, when I try this:
    ReDim A(2)
    A(2) = "Ball"

    And Then...

    Print A(1)
    Print A(2)

    The Value of A(1) is gone!!!

    What's wrong?!?

    Tell me,
    Please,
    Arie.
    Attached Files Attached Files

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Use "Redim Preserve .." and it will work *hehehe*

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Ok, that works, but now...

    I have another problem!
    I had other variables like:
    Code:
    Type PL
     X as Integer
     Y as Integer
     .
     .
     .
    End type
    Public Player As PL
    Now the Player.X is gone. why?
    All the other are OK.
    Did I do something with the Preserve?
    How do I use it? Where should I put it?
    Help, Fox!

    Arie.

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    The Preserve tells ReDim to keep the values in the array youre modifying. It only works for the last dimension of the array, meaning:

    Code:
       Dim Temp()
        
        ReDim Temp(10) 'Create empty 1D array
        ReDim Preserve Temp(20) 'Change size of last dimension
        
        ReDim Temp(10, 10) 'Create empty 2D array
        ReDim Preserve Temp(10, 20) 'Change size of last dimension
        ReDim Preserve Temp(20, 20) 'Change size of more dimensions - won't work
        
        Erase Temp 'Release memory


    About your type: Should work, the errer must be somewhere else..

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Ok... but,...
    how this is related with my Type ?
    Why my Type values are gone?
    All worked until I put this Preserve thing...
    What's wrong?

    Arie.

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    What do you mean'its gone' ?

    If it's not in the properties you may have done a mistake somewhere.. try compiling it.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Thumbs up Oh, wait... It works!

    Thank you very much, Fox!
    You were very helpful. Thanx!!!

    Arie.

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