Solved

Assign result to variable variable name

Posted on 2011-09-28
2
207 Views
Last Modified: 2012-05-12
Hello

I have looping structure where depending on the iteration of the loop will effect what variuable I assign the result to. For example loop iteration 1 assign result to string1 where string is common in all variable names and the numeric portion is variable. In iteration2 of the loop I want to assign the results to string2 and so on until the looping process is complete is there an easy way to do the variable assignment in one statement as opposed to do something like this

select case loopcount
  case 1 string1 = midstr(lineoftext, startpos, endpos)
  case 2 string2 = midstr(lineoftext. startpos, endpos)

etc..
startpos and endpos are controlled within the loop to return different parts of the string depending on where I am upto in the string.

Any suggestions?
0
Comment
Question by:elschott
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36796198
Would it be possible to use a Dictionary? If so, you would have one variable, but you could index it by using the loopcount, if you set up the Dictionary appropriately. For example:

Dim strings As New Dictionary(Of Integer, String)

strings.Add(1, String.Empty)
strings.Add(2, String.Empty)
strings.Add(3, String.Empty)

For i As Integer = 0 To 3
    strings(i) = midstr(linoftext, startpos, endpos)
Next

Open in new window


When you want to retrieve the values, you simply pass the number you're interested in:

Console.WriteLine(strings(1))

Open in new window


Provided you added that value as a key to the Dictionary.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36796428
P.S.

Dictionary can be found under the System.Collections.Generic namespace.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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