-
Jul 2nd, 2022, 09:25 AM
#1
Thread Starter
Banned
[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
-
Jul 2nd, 2022, 09:28 AM
#2
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.
-
Jul 2nd, 2022, 09:32 AM
#3
Thread Starter
Banned
Re: select case in this chat app help
Originally Posted by Elroy
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
-
Jul 2nd, 2022, 09:35 AM
#4
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.
-
Jul 2nd, 2022, 09:35 AM
#5
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.
-
Jul 2nd, 2022, 09:37 AM
#6
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.
-
Jul 2nd, 2022, 09:41 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|