another interesting question (text boxes)

JLocke
09-07-2003, 08:04 PM
Ok, this is a little weird and hard to explain what im trying to do, so.... I'm not going to :)

I was wondering, i need multiple if statement for a text box.

What I think I need - example: if txtConsole.Text = "This" fraWhatever.show

Any help there?

Also, how can I make it so the text in a text box starts out highlighted when the form loads, and how to make it so the person types, presses enter, and it highlights the text again... ?

Thanks!

Squishy
09-07-2003, 08:13 PM
For multiple If statements, you can either use ElseIf or a Select Case statement (use Select Case if you have many choices). To select the entire textbox, use the following code:

Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)

JLocke
09-07-2003, 08:59 PM
Ummm, that didn't work, was I supposed to put that in the text boxes code?

Squishy
09-07-2003, 09:10 PM
Make sure you change Text1 to whatever you named your TextBox. To select everything when the user presses Enter, use this:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
KeyAscii = 0
End If

End Sub


To select everything when the form loads, put the necessary code into the Form_Load event.

JLocke
09-07-2003, 09:16 PM
thanks! Ok, I have a really big problem...

I need a script that will check a selection of options to see if the key entered in a text box is an option thats available, if not, do nothing, if yes, do this.... Any help, appreciated!

Squishy
09-07-2003, 09:20 PM
You can put all the options into an array, then loop through it to check if there is a match. E.g.:

For i = LBound(strOptions) To UBound(strOptions) 'strOptions is an array that stores all the options
If Text1.Text = strOptions(i) Then MsgBox strOptions(i)
Next

JLocke
09-07-2003, 09:27 PM
For specifications, the user enters N, it checks to see if N is an available option, if yes, change picture according to something specified in options, if no, do nothing...

http://www32.brinkster.com/unids/screenshot1.jpg

That is what im trying to explain. How can I make it so if the user types 'North' or 'N' it will refresh the biggest img to something else and give them a new specified set of directions?

JLocke
09-07-2003, 09:30 PM
http://www32.brinkster.com/unids/screenshot1.jpg


btw that image got cut off a little, its not just a weird program :)

Squishy
09-07-2003, 09:32 PM
I can't view the screenshot (This file cannot be directly accessed from a remote site).

To check when the user presses enter, add to the previous code:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Select Case Text1.Text
Case "N", "North"
' If optN.Enabled = True Then (change it to check for the option's availability
MsgBox "North"
' End If
End Select
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
KeyAscii = 0
End If

End Sub

Squishy
09-07-2003, 09:35 PM
Nvm...I can open it (got rid of the referral URL thing).

If the available options are in a ListBox, you can make a function that loops through each item in the ListBox and checks to see if the entry matches a certain string.

JLocke
09-07-2003, 09:36 PM
how do I specify what picture to refresh and how to give them a new set of options?

Squishy
09-07-2003, 09:40 PM
If you're using a PictureBox, you can use Picture1.Picture = LoadPicture(...) to load a new picture. To give a new set of options, just .Clear the ListBox and then add new items.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum