anomaly
08-28-2002, 02:15 AM
fuzzy meaning MY logic, can anyone see why this loop makes the control sit there and seemingly do nothing?
if i type .load
it shells winamp, earlier it work, but you HAD to send text to the chat or it would keep shelling it. im trying to make it work if the text has changed or not, so it only runs the command once. the main parts of this I need help with are the LOOP and the IF THEN STATEMENT at the bottom here goes:
Private Function LastChatLine() As String
Dim aolchild As Long
Dim richcntlreadonly As Long
Dim ChatText As String
'i have a code called find_aolchlid that finds the window
aolchild = find_aolchild
'finds the chat window
richcntlreadonly = FindWindowEx(aolchild, 0&, "richcntlreadonly", vbNullString)
Dim TheText As String, TL As Long
'gets all the text from the chat window
TL = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, TL + 1, TheText)
ChatText = Left(TheText, TL)
'*************************************
'this is set to true when the control initalizes
'so it never uses the loop the 1st time through this code.
If ScanChat = False Then
'loops until the oldchat <> newchat
Do Until ScanChat = True
TL = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, TL + 1, TheText)
ChatText = Left(TheText, TL)
OldChat = ChatText
If NewChat = OldChat Then ScanChat = False
DoEvents
Loop
End If
'*************************************
'puts this text into the OldChat variable
OldChat = ChatText
'does some cleaning up
ChatText = Replace(TheText, Chr(13), vbCrLf)
ChatText = Replace(ChatText, Chr(0), "")
Dim last() As String
'counts the lines of text
last = Split(ChatText, vbCrLf)
LineNumber = UBound(last)
'gets the last line of text
If LineNumber <= 0 Then Exit Function
ChatText = last(LineNumber)
Dim Start As String
Dim Found
Dim Index As Integer
Dim Index1 As Integer
'alot more cleaning up here, because i dont need some of
the chattext I get back
Index = InStr(1, ChatText, " Link ")
Start = Right(ChatText, Len(ChatText) - Index)
Found = LCase(Start) Like ("link?#?*?#") Or LCase(Start) _ Like ("link?-#?*?#") Or LCase(Start) Like ("link?#?*?-#") Or _ LCase(Start) Like ("link?-#?*?-#")
If Found = True Then
Start = Left(ChatText, Index - 1)
Else
Start = ChatText
End If
LastChatLine = Start
'gets the screen name from the last line of text
Index = InStr(1, LastChatLine, ":") - 1
If Index <= 0 Then Exit Function
Screen_Name = Left(LastChatLine, Index)
'gets what was said from the same line
Index = InStr(1, LastChatLine, vbTab)
If Index <= 0 Then Exit Function
On Error Resume Next
What_Said = Right(LastChatLine, Len(LastChatLine) - Index)
'this checks the chat again to see if the text has changed
'*************************************
Dim NewText As String
NewText = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
NewChat = String(NewText + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, NewText + 1, NewChat)
NewChat = Left(NewChat, NewText)
'if this text is the same as the old text, then it will make the
'loop run next time through
If NewChat = OldChat Then ScanChat = False
'*************************************
End Function
if i type .load
it shells winamp, earlier it work, but you HAD to send text to the chat or it would keep shelling it. im trying to make it work if the text has changed or not, so it only runs the command once. the main parts of this I need help with are the LOOP and the IF THEN STATEMENT at the bottom here goes:
Private Function LastChatLine() As String
Dim aolchild As Long
Dim richcntlreadonly As Long
Dim ChatText As String
'i have a code called find_aolchlid that finds the window
aolchild = find_aolchild
'finds the chat window
richcntlreadonly = FindWindowEx(aolchild, 0&, "richcntlreadonly", vbNullString)
Dim TheText As String, TL As Long
'gets all the text from the chat window
TL = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, TL + 1, TheText)
ChatText = Left(TheText, TL)
'*************************************
'this is set to true when the control initalizes
'so it never uses the loop the 1st time through this code.
If ScanChat = False Then
'loops until the oldchat <> newchat
Do Until ScanChat = True
TL = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, TL + 1, TheText)
ChatText = Left(TheText, TL)
OldChat = ChatText
If NewChat = OldChat Then ScanChat = False
DoEvents
Loop
End If
'*************************************
'puts this text into the OldChat variable
OldChat = ChatText
'does some cleaning up
ChatText = Replace(TheText, Chr(13), vbCrLf)
ChatText = Replace(ChatText, Chr(0), "")
Dim last() As String
'counts the lines of text
last = Split(ChatText, vbCrLf)
LineNumber = UBound(last)
'gets the last line of text
If LineNumber <= 0 Then Exit Function
ChatText = last(LineNumber)
Dim Start As String
Dim Found
Dim Index As Integer
Dim Index1 As Integer
'alot more cleaning up here, because i dont need some of
the chattext I get back
Index = InStr(1, ChatText, " Link ")
Start = Right(ChatText, Len(ChatText) - Index)
Found = LCase(Start) Like ("link?#?*?#") Or LCase(Start) _ Like ("link?-#?*?#") Or LCase(Start) Like ("link?#?*?-#") Or _ LCase(Start) Like ("link?-#?*?-#")
If Found = True Then
Start = Left(ChatText, Index - 1)
Else
Start = ChatText
End If
LastChatLine = Start
'gets the screen name from the last line of text
Index = InStr(1, LastChatLine, ":") - 1
If Index <= 0 Then Exit Function
Screen_Name = Left(LastChatLine, Index)
'gets what was said from the same line
Index = InStr(1, LastChatLine, vbTab)
If Index <= 0 Then Exit Function
On Error Resume Next
What_Said = Right(LastChatLine, Len(LastChatLine) - Index)
'this checks the chat again to see if the text has changed
'*************************************
Dim NewText As String
NewText = SendMessageLong(richcntlreadonly, WM_GETTEXTLENGTH, 0&, 0&)
NewChat = String(NewText + 1, " ")
Call SendMessageByString(richcntlreadonly, WM_GETTEXT, NewText + 1, NewChat)
NewChat = Left(NewChat, NewText)
'if this text is the same as the old text, then it will make the
'loop run next time through
If NewChat = OldChat Then ScanChat = False
'*************************************
End Function