Ok from this spotted a problem fairly fast. Just start up your app in VB by pressing F8 and then repeatedly press F8 over and over as it steps through your lines of code.
The problem area starts here in Form1.Load():
Code:
On Error GoTo closeidentd ' <-- from here onward ...
identd.Listen
closeidentd: ' <-- ... go to this error jump point on error
ds1.Connect txtServer, 6667
What you're saying is that if an error occurs to go to this label, but that is still in effect after you intend it to. It's not until your On Error Resume Next 2 calls down in SetEmo() that you change your error conditioning.
Meaning ANY errors that occur between those two On Error lines but after the label "closeidentd:" is going to behave wrongly and loop back up to that label again, without indicating what or why any error occurred.
So firstly add the line that resets error handling back to an immediate app failure after the label occurs like this:
Code:
On Error GoTo closeidentd
identd.Listen
closeidentd:
On Error GoTo 0
ds1.Connect txtServer, 6667
Next, I commented out your On Error Resume Next in SetEmo though if I had read the code of this subroutine by itself there is a problem:
Code:
Public Sub SetEmo()
Dim j As Integer
Dim CharCombo() As String
Dim lFoundPosition2 As Long
Dim Emo()
Dim Icon()
'On Error Resume Next
For i = 0 To 30
CharCombo = Split(Emo(i), " ")
You've redefined Emo() and Icon() here, which means their local variable scope will supercede the variables of the same name at the Form/Class scope. Those arrays are not yet initialized to a size and so currently have 0 elements in them, it's like those arrays are currently initialized as "Emo() = Nothing" and you can't have a ubound() / lbound() of Nothing.
Because of the On Error Resume Next you're not told about this problem and your app keeps on going.
So I comment those 2 lines out as well in the SetEmo() method:
And start over (end debug, then F8 to restart and step through to this point since it's still near the beginning). Error occurs here:
Code:
'On Error Resume Next
For i = 0 To 30
CharCombo = Split(Emo(i), " ")
For j = 0 To UBound(CharCombo)
lFoundPosition2 = InStr(lFoundPosition, txtMain.Text, CharCombo(j)) ' <-- here
You haven't yet assigned any value to the variable lFoundPosition, it's just zero, and in the context of the series "1st, 2nd, 3rd, 4th, 5th, etc." there's no way to say what the 0th position would really represent. It's not an array index value where the first element of the array is 0-based, it's asking which ordinal position to begin at, and you want it to begin with the first character and so lFoundPosition should be set/initialised to 1 before the loop(s) begin.
Then, finally, you need to clean up the bounds of your initial loop:
Since Emo() only ranges from 0 to 16, do what you do with the inner loop and only go over the valid range instead:
This routine then runs successfully without needing to re-enable the On Error Resume Next at all, which is a good thing because these On Error statements have been the reason your code has had so many errors not caught by normal/quick/simple debugging practices. Not going to get preachy about the fact properly designed code shouldn't have had these faults in the first place, since that will come with more programming experience, but until that time, just don't depend on tricks to suppress errors for a quick/easy way to write an app, because in the long run it just adds up to all of these problems sneaking in to bite you anyway.
Those two subroutines in full as they stand now:
Code:
Public Sub Form_Load()
txtServer.Visible = False
txtPort.Visible = False
txtRoom.Visible = False
txtNickName.Visible = False
ReDim Emo(16)
ReDim Icon(16)
Emo(1) = "(H) (h)"
Icon(1) = frmEmo.sunglass.Text
Emo(2) = ":P :p :-P :-p"
Icon(2) = frmEmo.Tongue.Text
Emo(3) = ":O :o :-o :-O"
Icon(3) = frmEmo.Oh.Text
Emo(4) = "(Y) (y)"
Icon(4) = frmEmo.thumbsup.Text
Emo(5) = ":) :-)"
Icon(5) = frmEmo.Smile.Text
Emo(6) = ":D :-D :d :-d :>"
Icon(6) = frmEmo.BSmile.Text
Emo(7) = ":( :-("
Icon(7) = frmEmo.Sad.Text
Emo(8) = ":| :-|"
Icon(8) = frmEmo.shut.Text
Emo(9) = ":'("
Icon(9) = frmEmo.cry.Text
Emo(10) = "(F) (f)"
Icon(10) = frmEmo.flower.Text
Emo(11) = ":s :S :-S :-s"
Icon(11) = frmEmo.SS.Text
Emo(12) = ";) ;-)"
Icon(12) = frmEmo.knipoog.Text
Emo(13) = ":@"
Icon(13) = frmEmo.angry.Text
Emo(14) = "(K) (k)"
Icon(14) = frmEmo.kiss.Text
Emo(15) = ":$ :-$"
Icon(15) = frmEmo.blush.Text
Emo(16) = "(A) (a)"
Icon(16) = frmEmo.angel.Text
txtNickName.Text = "Webchat_" & Format(Now, "mmss") 'this is the random name
txtRoom.Text = Replace(txtRoom.Text, " ", "\b")
CMode = 1
Dim localport As Long
ds1.Close
localport = 0
ds1.RemotePort = 6667
ds1.localport = localport
identd.localport = 113
On Error GoTo closeidentd
identd.Listen
closeidentd:
On Error GoTo 0
ds1.Connect txtServer, 6667
txtMain.SelColor = &H8000&
txtMain.SelItalic = False
txtMain.SelText = "Please wait, connecting to server..." & vbCrLf
ResetFontFormat
End Sub
Public Sub SetEmo()
Dim j As Integer
Dim CharCombo() As String
Dim lFoundPosition2 As Long
'Dim Emo()
'Dim Icon()
'On Error Resume Next
lFoundPosition = 1
For i = 0 To UBound(Emo)
CharCombo = Split(Emo(i), " ")
For j = 0 To UBound(CharCombo)
lFoundPosition2 = InStr(lFoundPosition, txtMain.Text, CharCombo(j))
While lFoundPosition2 > 0
txtMain.SelStart = lFoundPosition2 - 1
txtMain.SelLength = Len(CharCombo(j))
txtMain.SelRTF = Icon(i)
lFoundPosition2 = InStr(lFoundPosition2, txtMain.Text, CharCombo(j))
Wend
Next j
Next i
lFoundPosition = Len(txtMain.Text) - 1
End Sub