[OT - Sorry] Ehh... Some Visual Basic help please...

Psionicist

Explorer
I feel a little ashamed posting this, so please don't laugh :)
I don't know any good programming forum accepting newbie questions like this, so I'll ask here, okay?

I am working on a little program here and I have created everything important and I just have to fix some small helptext in a statusbar, and I want to create a function out of it.

That is, instead of writing millions of crap like this:
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.SimpleText = ""
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.SimpleText = "Your +12V rail..."
End Sub
Private Sub Text2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.SimpleText = "Your +5V rail..."
End Sub
Private Sub Text3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.SimpleText = "Your VIO (Voltage Input Output) rail. Normal values are 3.3, 3.45 and 3.56..."
End Sub
...
...
...
and so on...
...

I want to create a small function, lets call it HelpText, so I just have to write something like this in one function:
HelpText(Form) = ""
HelpText(Text1) = "Your +12V rail..."
HelpText(Text2) = "Your +5V rail..."
HelpText(Text3) = "Your VIO (Voltage Input Output) rail. Normal values are 3.3, 3.45 and 3.56..."

Ehh... How do I do that?

icon11.gif
 

log in or register to remove this ad

Sorry, don't know how you'd go about making it appear in a statusbar without doing it the long way. Though text boxes have a propery called oh, shoot... umm... mouseovertext? I dunno, but they have a property that makes the little yellow box of appear when you put your mouse over it... lemme go check that out...
 

ToolTipText! Thats what it is... but if your dead set with the statusbar, you'll have to do it the long way (or get someone who knows a bit more about VB than me...). I'd do it the long way anyway, I work around problems instead of trying to find the easy way around them.
 

Use a different language. Say one which isn't VB, then I might know it. i refuse to touch the dark-code.

No, really... ;)
 

I hope this is useful

What you want to use is a Collection object (otherwise known as an Associative Array, or a Hash).

For reference go to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vaobjCollection.asp

Hopefully you can use the following implementation to start with. I didn't bother running it, so there may be some syntax errors, but the general idea is correct. Use the link I provided to find out more info.

Code:
Private Sub SetHelpText(strKey)
' instantiate a new collection object
Dim StatusTextCollection As New Collection
' add items to the collection object
' the format is:
' CollectionVariableName.Add "The data string that you want to display", "The 'key' which you want to use to refer to the data"
StatusTextCollection.Add "", "Form_MouseMove"
StatusTextCollection.Add "Your +12V rail...", "Text1_MouseMove"
StatusTextCollection.Add "Your +5V rail...", "Text2_MouseMove"

' to to set the StatusBar
StatusBar1.SimpleText = StatusTextCollection(strKey)
End Sub

EDIT:
I guess I should explain how to use it.

Simply call the subroutine in your code and pass in a value. The value that you pass in should correspond to the second element(the 'key') of the Add method.

For instance:
SetHelpText("Text1_MouseMove")

Should theorectically set StatusBar1.SimpleText to:
"Your +12V rail..." (without the quotes)
 
Last edited:

I'll try that! Thanks all!

I am building a diagnostic tool for analyzing the system voltages and I've created everything except for that stupid helpfunction I don't really need :)

Edit: Dang, that didn't work! I will use tooltiptext instead.
 
Last edited:


Remove ads

Top