PDA

View Full Version : Redundant code



austenr
02-12-2010, 08:16 PM
I'll admit I am a less than average programmer especially when it comes to logic. I am struggling with something that I can't seem to get mu head around.

Scenerio:

5 text boxes all placed in the same position each layered on top of the other. They are each displayed by a button (textbox1.visible = true) that also controls the visibility non/visibility of other image boxes, etc.

So now I have 5 buttons each controlling the visibility of a specific text box. When I switch to another text box and make it visible I end up making the previous one not visible (textbox1.visible = false). This leaves me turning the same text box invisible 4 times.

I know that this is horrible coding but I can't figure out another way.

If anyone is interested in helping Ill post the code. Thanks for listening.

Philcjr
02-12-2010, 09:39 PM
Austen,

How about trying this, this should bring the textbox to the front... once you click on the command button to show a textbox


TextBox1.ZOrder(fmTop)


Will this work for you?

austenr
02-12-2010, 10:02 PM

austenr
02-12-2010, 10:06 PM
Heres the code tried to post with code tags but it didn't take.

mdmackillop
02-14-2010, 06:02 AM
Hi Austen
Can you post a sample workbook containing the userform?
Regards
MD

p45cal
02-14-2010, 06:34 AM
Two approaches I would make with this one:
1.Write a sub which makes everything that you might want to make invisible, invisible. Call that sub first in the event handler then only make visible the items you want to be visible.
2.Instead of multiple controls on top of each other, only have one textbox/label etc. and get the code to change its contents with .caption .value and so on. I think you should also be able to change the picture in a similar way.

austenr
02-14-2010, 09:48 AM
Thanks for the input guys. Malcomb, this is straight up VB. Well VB.Net.

austenr
02-14-2010, 09:49 AM
p45Cal, that might work but once its visible and I want to load another picture would you not have to make whats visible invisible?

austenr
02-14-2010, 11:43 AM
How about writing a sub that makes everything invisible then call it inside the sub that is currently being processed?

austenr
02-14-2010, 11:43 AM
How about writing a sub that makes everything invisible then call it inside the sub that is currently being processed?

p45cal
02-14-2010, 03:28 PM
How about writing a sub that makes everything invisible then call it inside the sub that is currently being processed? That's just what I meant by "Write a sub which makes everything that you might want to make invisible, invisible. Call that sub first in the event handler then only make visible the items you want to be visible."
re:

that might work but once its visible and I want to load another picture would you not have to make whats visible invisible? With Approach 1 that would be covered by your suggestion above.
With Approach 2 I'd have thought the new picture loaded would replace the older one.