Solved

Assign result to variable variable name

Posted on 2011-09-28
2
208 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
[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
  • 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

Technology Partners: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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