Help support TMP


"VBasic Help - Associating objects with arrays" Topic


10 Posts

All members in good standing are free to post here. Opinions expressed here are solely those of the posters, and have not been cleared with nor are they endorsed by The Miniatures Page.

Please do not use bad language on the forums.

For more information, see the TMP FAQ.


Back to the Computer Stuff Plus Board


Areas of Interest

General

Featured Hobby News Article


Featured Recent Link


Featured Ruleset

Quickie Figs


Rating: gold star gold star gold star 


Featured Showcase Article

Cheap Scenery: Giant Mossy Rocks

Well, they're certainly cheap...


Featured Workbench Article

Basing Winter Trees

Need some trees for your wintery tabletop?


Featured Profile Article

The Limits of Writing With AI

Some observations on the current limitations of Large Language Models and writing/editing.


Current Poll


560 hits since 13 Nov 2012
©1994-2026 Bill Armintrout
Comments or corrections?


TMP logo

Membership

Please sign in to your membership account, or, if you are not yet a member, please sign up for your free membership account.
Last Hussar13 Nov 2012 4:28 p.m. PST

I know there is a way to do this in Vbasic, but my old files won't open so I can't find out how, and I can't get a relevent Google or Bing hit.

I have a form with a number of objects. I know there is a way to associate them with cells in an array, so I can reference ach one via a variable

Array(1)=Label1
Array(2)=Label2
etc

So I can then say (for instance) Array(i) = xxxx
Can't remember how to do it, or what this method is called. All can remember is you have to have a seub routine called from the declarion coding at the start of the programme.

Any ideas?

Personal logo Saber6 Supporting Member of TMP Fezian14 Nov 2012 10:40 a.m. PST

been awhile, but try:

Dimension XYZ as Array

Double check the rules for Arrays as well. Look in Excel or Word Macros for help too

Personal logo Saber6 Supporting Member of TMP Fezian14 Nov 2012 10:48 a.m. PST

Look here as well:

link

Last Hussar14 Nov 2012 1:00 p.m. PST

Thanks Sabre, but not what I was after – On rereading my question wasn't clear.

Imagine I have 10 Labels on the form, which need updating each time the array is changed.
ie the programe gets an result'r', and increase Array(r) by one
Totals(r)=Totals(r)+1

Now I could programme
If r = 1 then Label1.Text=Totals(1)
If r = 2 then Label2.Text=Totals(2)
etc

However you can do something like
Display(i)=totals(i)

where a list of variables called Display(1), Display(2) etc are each associated with an individual label (or button,or text box etc)

I know this association has to sit in a specifically named sub-routine which is called from the section that defines the variables at the start of the programme.

I can't remember
1) the name and syntax of this sub
2) How you declare each variable
3) How you associate each variable

I am writing a Suduko solver (as a intellectual exercise), and thus have 81 (!) boxes to deal with – If 'n' then will get rather repetitive!

Last Hussar14 Nov 2012 1:01 p.m. PST

If I could remember what the technique was called I could search for it!

blackscribe14 Nov 2012 2:05 p.m. PST

I thought about doing that once. Then I realized modern computers have enough horsepower to try every possible combination to find the answer very quickly and an elegant solution isn't required.

Last Hussar14 Nov 2012 3:09 p.m. PST

Blackscribe, I'me going for a brute force solution – each box has 10 cells associated – 0 is the answer, 1-9 show status of those digits. Simply check each box in turn against rest of cells in the rows lines and 3x3 box, blanking out what it can't be, then check if it can't be any other cells that contain that number, thus this is the last poss. Do that for each each number in each cell, and when you reach 9,9 check to see if all cell'0' filled. if not, go back and do it all again.

I've found what I'm looking for though

Private Sub progName_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load

SetControlArray()

End Sub

Private Sub SetControlArray()
Array(1,1)=Box11
Array(1,2)=Box12
etc

Used autofill on excel then Word Replace to mean I don't hve to type it all out!

Personal logo Saber6 Supporting Member of TMP Fezian14 Nov 2012 4:14 p.m. PST

cool. Like I said, it has been awhile evil grin

blackscribe15 Nov 2012 1:53 p.m. PST

Ah, cool, I don't think I've seen that array manipulation in VB before.

Last Hussar15 Nov 2012 4:24 p.m. PST

No wuckers Sabre – thanks for trying.

BlackScribe, its a great method, it means you can reference individial objects in a group (of identical objects). So if you had a score board showing the scores of 10 players the code doesn't have to be
If player=1 then Label1 = x
If Player=2 then Label2 = x
etc
you simply go

Score(player)=x

You do have to associate all the lables first, as shown above in SetControlArray(), but Paste is a wonderful tool!

Sorry - only verified members can post on the forums.