Solved

Assign result to variable variable name

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

832 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