Page 2 of 2 FirstFirst 12
Results 41 to 47 of 47

Thread: I need help looping through an array. [SOLVED]

  1. #41

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I just got it working partially. I got an idea though. Is there any way to get the number of elements in an array?

    Here's what happens:

    First time, the green system message appears.
    Second time, the black miscellaneous message appears.
    Third time, the second green system message appears, and all text in the textbox turns green, including the *supposedly* black misc message.
    Last edited by hothead; Mar 3rd, 2004 at 08:09 PM.

  2. #42
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Well, how about you post the code you are using again. It sounds like there have been some changes. Maybe we can get this resolved. Also explain why my code won't work.

  3. #43

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I did make some changes to get it to work. Here's the way it looks:

    VB Code:
    1. Private Function ColorServerMessageLines()
    2.     Dim strArray() As String
    3.     strArray = Split(rtbServerMessages.Text, vbNewLine)
    4.     rtbServerMessages.SelStart = 0
    5.     For i = 0 To UBound(strArray)
    6.         rtbServerMessages.SelLength = Len(strArray(i)) + 2
    7.         If Left$(strArray(i), 6) = "SYSTEM" Then
    8.             rtbServerMessages.SelColor = DarkGreen
    9.         ElseIf Left$(strArray(i), 5) = "ERROR" Then
    10.             rtbServerMessages.SelColor = DarkRed
    11.         Else
    12.             rtbServerMessages.SelColor = vbBlack
    13.         End If
    14.         rtbServerMessages.SelStart = rtbServerMessages.SelStart + rtbServerMessages.SelLength
    15.     Next i
    16. End Function

    However, it only works the first couple times the code is run through. If I get something like this:

    SYSTEM: Test
    Test
    SYSTEM: Test

    the whole thing will turn green again. However, it'll work with something like this:

    SYSTEM: Test
    Test
    Last edited by hothead; Mar 3rd, 2004 at 08:30 PM.

  4. #44
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Is the RTB changing at all while the coloring process is executing. What you describe seems impossible? I have tested a bunch of different ways and cannot duplicate your problem.

    Can you show the code that adds the text to the RTB?

  5. #45

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    EDIT: I have already found the problem, it was a missing function call. It works completely now. Thanks a lot!
    Last edited by hothead; Mar 3rd, 2004 at 08:50 PM.

  6. #46
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by hothead
    It goes through the loop twice for some reason, even though only one line is in the textbox

    And........... a CarriageReturn (that you loaded in the Form Load Event)!

    Hence the Array has two elements (0) being the first word, and (1) containing ""




    Bruce.

  7. #47
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    might i also suggest trimming any VBCrLf's (newline) from the end?

    something like
    VB Code:
    1. Do Until Right(rtbServerMessages.Text, 2) <> vbCrLf
    2.     rtbServerMessages.Text = Left(rtbServerMessages.Text, Len(rtbServerMessages.Text) - 2)
    3. Loop

Page 2 of 2 FirstFirst 12

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