Results 1 to 7 of 7

Thread: [RESOLVED] select case in this chat app help

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Resolved [RESOLVED] select case in this chat app help

    client
    Code:
    ws.SendData "dc$$" & "disconnectedd" & "," & txtName.Text
    sending a disconnect message and user


    server


    Code:
    Dim strr() As String
     strr = Split(strData, "dc$$")
        
        Select Case strr(1)
                Case "disconnectedd"
               
                  Debug.Print strr(1) & " " & "disconnected"
                
                Case "tandaaa"
            
          
                Case Else
              
        End Select

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: select case in this chat app help

    Your second delimiter is a comma, and not "dc$$", so strr(1) after the Split() will, at a minimum, have a comma on the end of it, and it will also have whatever is in txtName.Text after the comma.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: select case in this chat app help

    Quote Originally Posted by Elroy View Post
    Your second delimiter is a comma, and not "dc$$", so strr(1) after the Split() will, at a minimum, have a comma on the end of it, and it will also have whatever is in txtName.Text after the comma.
    ok then anyways it is not firing
    Dim strr() As String
    strr = Split(strData, ",")

    Select Case strr(1)
    Case "disconnectedd"

    Debug.Print strr(1) & " " & "disconnected"

    Case "tandaaa"


    Case Else

    End Select

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: select case in this chat app help

    Well, in your post #3 case, you're leaving the "dc$$" pre-pended onto the beginning of your string. Just include that in your Select Case tests if that's the way you want it. Also, your test string will be in strr(0), not strr(1).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: select case in this chat app help

    Well, maybe take a second to step back from the code and keyboard and think about it.

    The string you are splitting is going to look like this:

    dc$$disconnectedd,jenniger

    Split that on a comma and look at the resulting strings. Do any of them exactly match your Case statements? Hint: No.

    Edit: Also, what Elroy noted above.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: select case in this chat app help

    Code:
    Dim strr() As String
    strr = Split(strData, ",")
    
    Select Case strr(0)
    Case "dc$$disconnectedd"
    
    Debug.Print strr(0) & " " & "disconnected"
    
    Case "dc$$tandaaa"
    
    
    Case Else
    
    End Select
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: select case in this chat app help

    Also, just as another tip, I sometimes use Select Case True. This allows me to put a complete conditional statement in each Case test. That would allow the following to be done:

    Code:
    Dim strr() As String
     strr = Split(strData, "dc$$")
        
        Select Case True
                Case Left$(strr(1), Len("disconnectedd")) = "disconnectedd"
               
                  Debug.Print strr(1) & " " & "disconnected"
                
                Case Case Left$(strr(1), Len("tandaaa")) = "tandaaa"
            
          
                Case Else
              
        End Select
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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