Solved

Assign result to variable variable name

Posted on 2011-09-28
2
198 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 74

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 74

Expert Comment

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

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now