Results 1 to 20 of 20

Thread: Vectors and Arraylists

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Vectors and Arraylists

    Is there anythign in VB6 that works like a Vector, Arraylist or limtiless Array?

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    yes, define an array without limits first and as you assign values to it use redim statement to increase its limit.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    So in theory if I was taking strings of information out of a table I could use redim over and over to increase the capacity by 1 every time I add somethign else? and what is the Syntax for this ReDim?

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    use something like this
    ReDim Preserve strString(i)
    where preserve will keep your already assigned values in it and just using redim will erase existing contents

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    Oh my god I can't beleive this, I'm confusing the For loop with the .Net version. How is it done in VB6?

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    the syntax for the for loop is

    for i

  7. #7
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    the syntax for the for loop is

    for i=0 to 10 step 1
    your codes
    next

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    Thaks a lot you're a saviour

  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    qualinwraith, could u rate me

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    sigh, I'm getting a Can't Assign to array error in this line of Code.
    VB Code:
    1. Private Sub displayRecord()
    2.     Dim inArray(9) As String
    3.     inArray = mdlConnection.displayRecord 'Can't Assign to Array
    Anyonw Know why? mdlConnection is a module, displayRecord is a public function and inArray is an Array than I just declared.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Vectors and Arraylists

    You can't assign a string to an array. You can assign a string to an array element, which is a string.

    What is mdlConnection.displayRecord returning?

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    An array of strings

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Vectors and Arraylists

    OK well in that case you need to make the array dynamic in length so that it can handle the return result properly.

    VB Code:
    1. Dim inArray() As String
    2. inArray = mdlConnection.displayRecord()

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    Ah ok then thanks a lot

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    Is there a way how to break out of a loop?

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Vectors and Arraylists

    No but if you find yourself needing to use something like "break;" I suggest a re-think. Maybe a Do loop with an extra continuation condition or something similar.

    Or, (horror of horrors) you could use a Goto.

  17. #17
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    you can use exit do in do loop and exit for in for loop

  18. #18
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Vectors and Arraylists

    Hmm, I've been outwitted. I was thinking of "continue"

  19. #19
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Vectors and Arraylists

    ok...

  20. #20

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    63

    Re: Vectors and Arraylists

    Thanks a lot guys

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