|
-
Jan 22nd, 2007, 08:13 PM
#1
Thread Starter
Member
[RESOLVED] String Manipulation
VB Code:
If InStr(sockBuff, "PRIVMSG") <> 0 Then
Select Case True
Case InStr(sockBuff, "!roll") <> 0:
y = Split(Mid(sockBuff, InStr(sockBuff, " : !roll ")), " ")
sendToIRC (sockBuff)
' status(0) = DCCCHat
' sckDCC(sckDCC.UBound).Connect ircGetIP(y(UBound(y) - 1)), Replace(y(UBound(y)), "", "")
I commented out the the last two lines. I thought they were causing me an error, and I don't want DCC anyway. Where I have "!roll" entered, it used to say "DCC CHAT". It keeps getting an error at the following bit of code:
VB Code:
y = Split(Mid(sockBuff, InStr(sockBuff, " : !roll ")), " ")
I hit F2 and typed in SPLIT, but I'm afraid I am not able to figure out what all it's trying to do here. Can anyone explain it to me?
Also, how would I go about getting the first "CyberInfantry" only out of the following string:
:[email protected] PRIVMSG #shadowfall :!roll
-
Jan 22nd, 2007, 08:42 PM
#2
-
Jan 22nd, 2007, 09:06 PM
#3
Thread Starter
Member
Re: String Manipulation
Run-time error '5':
Invalid procedure call or argument
-
Jan 22nd, 2007, 09:22 PM
#4
Re: String Manipulation
Well what
VB Code:
y = Split(Mid(sockBuff, InStr(sockBuff, " : !roll ")), " ")
says is
- InStr asks if the string " : !roll " is in sockBuff. If it finds it InStr will return a number that is the character number where the string was found. If not found it will return 0.
- Mid then tries to extract a portion of sockBuff from that character to the end of the string, and
- Split then tries to split it up at the spaces.
The problem is probably happening when the string isn't found by InStr since the zero that would be returned is not valid in the Mid command.
-
Jan 22nd, 2007, 09:28 PM
#5
Thread Starter
Member
Re: String Manipulation
So the InStr() command would be what I would need in order to find the first "CyberInfantry" in that other question I had?
Then I would need to find the first !...
And then do a Right(InStr(sockBuff, "!")), then a Left(sockBuff, Len(sockBuff) - 1) ?
Would that get me down to only "CyberInfantry" out of:
:[email protected] PRIVMSG #shadowfall :!roll
?
-
Jan 22nd, 2007, 09:33 PM
#6
Frenzied Member
Re: String Manipulation
CyberInfantry:
I’m not real sure what you are doing here, but I don’t think you are using the InStr() function correctly.
The InStr Function returns a Variant (Long) specifying the position of the first occurrence of one string within another.
The Syntax is: InStr([start, ]string1, string2, [compare])
Start is a numeric expression that sets the starting position for each search.
String1 is the String expression that is being searched.
String2 is the String expression you are trying to find.
Compare is a value that indicates the type of comparison.
The possible values are:
0 = Performs a binary comparison.
1 = Performs a textual comparison
2 = Is used for Microsoft Access only for info in a database.
An example of using the InStr function to return the position of the first occurrence of one string within another would be like this:
VB Code:
Dim SearchString, SearchChar, MyPos
SearchString = "XXpXXpXXPXXP" 'The string to search
SearchChar = "p" 'Search for "p".
MyPos = InStr(4, SearchString, SearchChar, 1)
'This would return 6, because the code is saying
'start at the 4th character in the SearchString, which is X
'and search for the SearchChar, which is p, and tell
'me where you find it. The return value of 6 means
'that it was found as the 6th character.
So your code statement: InStr(sockBuff, "PRIVMSG") doesn’t make sense.
If you want to compare two strings then maybe you should use the StrComp() Function.
Not sure if this helps you or not.
Last edited by AIS4U; Jan 22nd, 2007 at 09:34 PM.
Reason: correct typos
-
Jan 22nd, 2007, 09:33 PM
#7
Re: String Manipulation
VB Code:
Const STRINGTOBEFOUND = "CyberInfantry"
Dim intStartPos As Integer
intStartPos = InStr(TESTDATA, STRINGTOBEFOUND)
If intStartPos > 0 Then
MsgBox Mid$(TESTDATA, intStartPos, Len(STRINGTOBEFOUND))
End If
-
Jan 22nd, 2007, 09:41 PM
#8
Thread Starter
Member
Re: String Manipulation
AISU4:
I see what you are saying about the InStr() command. That was all ready in the code as it is, though. Is it possible that, if no numerical data is entered, it starts off at the beginning?
MartinLiss:
What are the $ signs for? I remember seeing them... only once in my VB class. That had to do with opening files and closing them. What do they mean?
Also, the string I'm trying to find within the larger string changes.
This is a bit of code from penderj's VB IRC Bot. IRC will have many different users. I copied that string from my Debug window when I had my text persona in the IRC room say something (trying to figure out the IRC protocols).
With each person, that name is going to be different. However, I KNOW it's going to start with ":" and I KNOW that after the name, it's going to have a "!".
Would the code I posted in my last post work for that?
-
Jan 22nd, 2007, 09:44 PM
#9
Re: String Manipulation
Mid and Mid$ are two different versions of the same function. The latter on returns a string. In this case they both do but you should use thye latter one.
-
Jan 22nd, 2007, 09:47 PM
#10
Re: String Manipulation
 Originally Posted by CyberInfantry
AISU4:
...Also, the string I'm trying to find within the larger string changes....
I used constants only for my testing and you would probably use some string variable that contained the word(s) you want to find and another one for the text to be searched instead of the Consts.
-
Jan 22nd, 2007, 10:17 PM
#11
Frenzied Member
Re: [RESOLVED] String Manipulation
CyberInfantry:
if no numerical data is entered, it starts off at the beginning?
Yes, that is correct. It is an optional argument and if you leave it out it starts from the beginning of the string.
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
|