Updating structure elements

Posted on 2006-05-14
Medium Priority
Last Modified: 2010-05-01
I have a program the uses the following structure:

Private Type tagUse
  tagname As String
  use1 As String
  use2 As String
  use3 As String
  use4 As String
  use5 As String
  use6 As String
  use7 As String
  use8 As String
  use9 As String
  use10 As String
End Type
Dim arrTagUse() As tagUse

After a while, various array items will have different values for the various .use% elements. And for that matter, different numbers of .use% elements. I have a code section that updates the .use% correctly. It looks like
  If tagItem.use1 <= " " Then
    tagItem.use1 = usedIn
  End If
  If tagItem.use2 <= " " Then
    tagItem.use2 = usedIn
    Exit Sub
  End If

My question: is there a more elegant solution? Some way of stepping through the elements in a For - Next loop?

Question by:holyfeld
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 16679000
I don't believe there is a way to enumerate structure fields in VB6, though it is possible in VB.Net.

If you made it a CLASS though and made the fields Public, then you can build a string which contained "use1", "use2", "use3", etc in a loop, and then would be able to get/set those values using that string and the CallByName function.
LVL 85

Accepted Solution

Rory Archibald earned 800 total points
ID: 16681720
Hi Holyfeld,
You could simply redefine your structure as:
Private Type tagUse
  tagname As String
  use(1 To 10) As String
End Type

so you end up assigning the values via something like: arrtaguse(1).use(3) = "Use item 3". You can then iterate as necessary through all the items in use() with a simple counter.



Author Comment

ID: 16686740
Idle_Mind answered the question I asked, so I awarded some points. rorya showed with a minor modifcation I can iterate like I want to.

Thank you.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

621 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