Solved

Dynamic Array in VB 2008

Posted on 2010-11-18
5
786 Views
Last Modified: 2012-05-10
This works in VB 6:

Partner() As String

Sub ReDimArray()
    ReDim Partner(0) As String
    Partner(0) = "Jaes"
    MsgBox Partner(0)  '<-- returns "Jaes"

    ReDim Preserve Partner(1) As String
    Partner(1) = "Mike"   '<-- returns "Jaes"

'etc
End Sub

How is this done in VB 2008

Thank you.
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:EYoung
ID: 34168057
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34168187
This works in vb 2008:
Dim Partner() As String

    Sub ReDimArray()
        ReDim Partner(0)
        Partner(0) = "Jaes"
        MsgBox(Partner(0))  '<-- returns "Jaes"

        ReDim Preserve Partner(1)
        Partner(1) = "Mike"   '<-- returns "Jaes"

        'etc
    End Sub

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34168194
You could use essentially the same code...but why would you want to?

Use a List(Of String) instead:

    Dim Partner As New List(Of String)

    ...
        Partner.Add("Jaes")
        Partner.Add("Mike")

You can access it like a traditional array:

    MessageBox.Show(Partner(0)) ' <-- "Jaes"

...and it GROWS automatically to accommodate the entries you add.

You can even remove from the middle and everything shifts down to fill the "hole".

See:
http://msdn.microsoft.com/en-us/library/6sh2ey19(VS.80).aspx
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 34168685
Hi Idle_Mind,

Your solution is the best practice and very much appreciated.

Hi Zhaolai,

Thank you for your post. I was looking for 2008-specific solution like what Idle_Mind has posted.

Thank you
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 34169266
EYoung,

My apology for not paying a good attention of your post. I will request to reopen the question and give your fair share.

Thank you,

Mike
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question