|
-
Jun 10th, 2000, 12:15 AM
#1
Thread Starter
Hyperactive Member
Hello I have a ComboBox...
Say i have the Combo's Text: "Just.Testing.This/3783"
Is there a way i can put what is BEFORE the "/" into One textbox (text1) and Anything AFTER into another Textbox(Text2).
Secondly, say i have a DIFFERENT combo box,
I want to use commands like a MUD server would.
So what i need to find out is:
In the Combo box people can type in commands, LIKE
"get <item>"
"chat <message>"
And also If it could read like " chat <message" *Notice the SPACES*
Ect, stuff like that.
So i need it to Read the FIRST word and do an action with the SECOND part, (After the word) till the end of the box.
LIKe:
ComboBox's Text = "chat hello people whats up?"
Reads "chat" and makes a MESSAGE BOX Appear with "hello people whats up?"
If the first word DOESn't match any commands it displays
Msgbox "Unknown"
Thanks ALOT!
PS: this is using VB5.
-
Jun 10th, 2000, 05:33 AM
#2
Junior Member
combo box
Ok first thing i would recommend for u to do is make distinct variables to store each thing u want to manipulate.
u can use commands like LStr to take parts of strings and manipulate them. u need to take the text in the combo boxes and break them up into the parts that u want.
u can use the same methods to cut out the beginning of the commands u want and place the rest into a variable so that it can be placed into message boxes or analyized so that u can perform the proper codes.
i hope this has been of some help. please tell me if it does help.
-
Jun 10th, 2000, 06:59 AM
#3
Thread Starter
Hyperactive Member
Yea, i have no idea what that means or how to do it.
-
Jun 10th, 2000, 07:13 AM
#4
Junior Member
string manipulation
Ok here we go. u know how to bring up help in vb right.
do that. click on the "Index" tab and u will see a large list of words. type in "strings". this will have a long list of items slightly indented below it.
u want to double click on where it says leftmost characters, middlemost characters, and rightmost characters. it will give u the LEFT, RIGHT, and MID functions. these three functions allow u to take out part of a string and break up a string into multiple parts.
u want to put each part u want to keep into a different string. use good names so u can keep them apart and remember them. u can always combine strings together again for any reason. example. strMessage = string1 & string2
u can use these same functions to cut off the parts of the command for your mud that u dont need and then check the rest to see what needs to be done. if u have any other questions email me at [email protected]
-
Jun 10th, 2000, 08:30 AM
#5
here ya go
the +1 and -1 are so you dont get the "/" with the strings.
Code:
Dim LeftPart As String ' this stuff in
Dim RightPart As String ' the general
Dim TempInStr As String ' declarations section
Private Sub Command1_Click()
TempInStr = InStr(1, Combo1.Text, "/")
RightPart = Mid(Combo1.Text, (TempInStr + 1))
Text2 = RightPart
LeftPart = Left(Combo1.Text, (TempInStr - 1))
Text1 = LeftPart
End Sub
-
Jun 11th, 2000, 12:11 AM
#6
here you are, this is for the 2nd question,
this is if the combobox reads "chat Hello People whats up?"
Code:
Dim TempInStr As Integer ' general
Dim RightWords As String ' declarations
Dim LeftWord As String ' section
Private Sub Command1_Click()
TempInStr = InStr(1, Combo1.Text, " ")
LeftWord = Left(Combo1.Text, TempInStr - 1)
RightWords = Mid(Combo1.Text, TempInStr + 1)
UCase (LeftWord) ' you could also do LCase, so all of the letters will be lower case
If UCase(LeftWord) = "CHAT" Then
MsgBox RightWords
End If
End Sub
the code should be able to be easily changed to accomidate more words, and instead of using if..then.. use the select case...
example
Code:
Select Case Ucase(LeftWord)
Case "CHAT" ' the case has to match
MsgBox RightWords
Case "GET"
' Do this stuff
End Select
I hope this helped.....
-
Jun 11th, 2000, 02:42 AM
#7
you could also use InStr to find the individual words..
example...
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim Words(1) As String ' create an array with a size of 2(0,1)
Dim TempInStr(1) As Integer ' create an array with a size of 2(0,1)
Words(0) = "dude" ' set index 0 of words to "dude"
Words(1) = "hello" ' set index 1 of words to "hello"
For i = 1 To 2 ' for loop
TempInStr(i - 1) = InStr(1, Combo1.Text, Words(i - 1)) ' the i - 1 is because of the offset of the arrays
Next
If TempInStr(0) = 0 Then ' exit the sub if instr returned 0
Exit Sub
ElseIf TempInStr(0) <> 0 Then ' if instr didnt return 0(it found the word) then do this
MsgBox "the box contains the word " & Words(0)
End If
If TempInStr(1) = 0 Then
Exit Sub
ElseIf TempInStr(1) <> 0 Then
MsgBox "the box contains the word " & Words(1)
End If
End Sub
add a few UCase or LCase in there to make sure all of the case's are consistant.
sorry for answering so many times... I just though that this was better. also, you might need to configure it so that if "dude" isnt the first word, it will do nothing.
-
Jun 11th, 2000, 04:57 AM
#8
Thread Starter
Hyperactive Member
Thanks alot guys. I havn't tryed it, because i am on the wrong computer. Later i will change computers and test it.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|