ExpertCentral.coman About company
Your Search is Over!
Expert Home Sign Up My ExpertCentral Answer Library Help
Search for Experts in 
View question by Expert saintly
Question History!
From : Slappy
To : saintly
Rating :
Message Status : Public

[08-11-2000] Slappy : Hi,
Any one can probably help me with this. I have some code, that gathers a number from a user, it is an array(1 to 6), and depending on the number inputted it throws up a picture. The problem is for every one at the moment I have a case structure
eg.
Select Case Number(1)
Case 1
rmEnterNewResultCheck.imgNumber1.Picture = LoadPicture("C:\My Documents\Number1.bmp")

Case2 etc all the way to 44 with 44 case options. Each case loads a different image, and there are six numbers that each have 44 cases and each load to a different image box.

Any idea how to shorten my code as i have
6 case structures * 44 options * 2 lines each totalling to 528 lines of code

Kind Regards
Me


[08-11-2000] saintly : So wait... let me see if I can understand this. You get a number 1-44 from the user six times, and each time you get a number, you load a picture?

Do you use similar code for each instance of loading the picture? Like...

rmEnterNewResultCheck.imgNumber1.Picture = ...
rmEnterNewResultCheck.imgNumber2.Picture = ...
rmEnterNewResultCheck.imgNumber3.Picture = ...
up to imgNumber6.Picture = ...?

And this is C++, right? Could you please attach or email me more code?
[08-11-2000] Slappy : Shit, I always do that, no sorry its VB can you still help
[08-11-2000] saintly :
Ok, I'll try... bear in mind that I haven't used Visual Basic much:

Some generic ways you might save lines... if the images are not named arbitrarily, but are like "Number1.bmp","Number2.bmp" ... "Number44.bmp" you might try something like

imgNumber1.Picture = LoadPicture("C:\My Documents\Number" & option & ".bmp")

where option is the variable containing the user's input.

If you're using separate variable names for each picture under rmEnterNewResultCheck, you could make them an array:

Not:
dim imgNumber1 as Something
dim imgNumber2 as Something
...
dim imgNumber6 as Something
but:
dim img(6) as Something

And step through them with a for loop (further down) Likewise, put all the picture names in a 2-dimensional array:

Dim imgarray(6,44) as String
imgarray(0,0) = "Number1.bmp"
imgarray(0,1) = "Number2.bmp"
..
imgarray(0,43) = "Number44.bmp"
imgarray(1,0) = ...
..
imgarray(5,43) = "lastimg.bmp"

Filling up the array with the actual image names of course, leaving out whatever stays the same, like if they all start with "C:\My Documents\", you can leave it out and add it when you want to load the image.

Then say, a user gives you a number 'userOpt' and you want to load that image number in all 6 panels:

Dim userOpt as Integer
Dim x as Integer

... user gives you userOpt ...

for x = 0 to 5
rmEnterNewResultCheck.img(x).Picture = LoadPicture(imgarray(x,userOpt))
next x

Does that help? I can explain it better if you like. Here are some links to tutorials on using arrays:

http://www.vbexplorer.com/arraytut.asp
Shows how to convert code like you were mentioning with select/case statements into code using an array...

http://minich.com/education/racc/visualbasic/cis230ch8/ch8notes1.htm
Good intro to arrays.

ExpertCentral.com
Home | Sign Up | My ExpertCentral | Answer Library | Help | Log Out
Public Board | How it Works | Why Join? | Tell a Friend | About Us | Contact Us

Copyright © 2000 ExpertCentral.com, Inc. All Rights Reserved.
ExpertCentral and ExpertCentral.com are trademarks of ExpertCentral.com, Inc.
Use of this site constitutes your acceptance to the terms and conditions of the ExpertCentral Member Agreement.