[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Assign result to variable variable name

Posted on 2011-09-28
2
Medium Priority
?
232 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
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…
Suggested Courses

656 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