Results 1 to 8 of 8

Thread: Reading Before and After

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    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.

  2. #2
    Junior Member
    Join Date
    Dec 1999
    Posts
    25

    Cool 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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    Yea, i have no idea what that means or how to do it.

  4. #4
    Junior Member
    Join Date
    Dec 1999
    Posts
    25

    Cool 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]


  5. #5
    Guest
    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

  6. #6
    Guest
    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.....






  7. #7
    Guest
    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    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
  •  



Click Here to Expand Forum to Full Width