Author Topic: TextEdit Add sub issue.  (Read 1408 times)

briansykes

  • Newbie
  • *
  • Posts: 23
TextEdit Add sub issue.
« on: October 10, 2009, 11:32:01 AM »
Alright so i made this add sub to add text with formatting and also to highlight any url's in the text and it works except i have to put a space at the end of every new line and i cant seem to fit it lol, so here is the code hope someone can make use of it and possibly figure out how to fix the space issue.  The isStart function is also included.

Code: [Select]
PUBLIC SUB Add(Text AS String, OPTIONAL TextColor AS Integer, OPTIONAL bBold AS Boolean)
  DIM strWords AS String[]
  DIM i AS Integer
  DIM strWord AS String
  DIM strCheck AS String
  strWords = Split(Text, " ")
  FOR i = 0 TO strWords.Count - 1
    strWord = strWords[i]
    strCheck = LCase(strWord)
    IF ModMain.isStart(strCheck, "http://") OR ModMain.isStart(strCheck, "https://") OR ModMain.isStart(strCheck, "ftp://") OR ModMain.isStart(strCheck, "irc://") OR ModMain.isStart(strCheck, "telnet://") OR ModMain.isStart(strCheck, "mailto:") THEN
      teLog.Select(String.Len(teLog.Text), 0)
      teLog.Format.Color = Color.RGB(0, 0, 168)
      teLog.Format.Font.Underline = TRUE
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      teLog.Insert(strWord & " ")
    ELSE
      teLog.Format.Color = TextColor
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      teLog.Insert(strWord & " ")
    END IF
  NEXT
  teLog.Insert("\n")
END

PUBLIC FUNCTION isStart(inputText AS String, searchFor AS String) AS Boolean
 
  IF Mid(inputText, 1, Len(searchFor)) = searchFor THEN
      RETURN TRUE
  ELSE
      RETURN FALSE
  END IF
 
END

Linux Basic

TextEdit Add sub issue.
« on: October 10, 2009, 11:32:01 AM »

briansykes

  • Newbie
  • *
  • Posts: 23
Re: TextEdit Add sub issue.
« Reply #1 on: October 14, 2009, 09:12:40 PM »
I have since resolved the issue, this is now the full and complete sub that should work with any TextEdit you use, hopefully this is useful to someone.

Code: [Select]
PUBLIC SUB Add(Text AS String, OPTIONAL TextColor AS Integer, OPTIONAL bBold AS Boolean)
  DIM strWords AS String[]
  DIM i AS Integer
  DIM strWord AS String
  DIM strCheck AS String
  strWords = Split(Text, " ")
  FOR i = 0 TO strWords.Count - 1
    strWord = strWords[i]
    strCheck = LCase(strWord)
    IF ModMain.isStart(strCheck, "http://") OR ModMain.isStart(strCheck, "https://") OR ModMain.isStart(strCheck, "ftp://") OR ModMain.isStart(strCheck, "irc://") OR ModMain.isStart(strCheck, "telnet://") OR ModMain.isStart(strCheck, "mailto:") THEN
      teLog.Select(String.Len(teLog.Text), 0)
      teLog.Format.Color = Color.RGB(0, 0, 168)
      teLog.Format.Font.Underline = TRUE
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      IF i = 0 THEN
        teLog.Insert(strWord)
      ELSE
        teLog.Insert(" " & strWord)
      END IF
    ELSE
      teLog.Format.Color = TextColor
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      IF i = 0 THEN
        teLog.Insert(strWord)
      ELSE
        teLog.Insert(" " & strWord)
      END IF
    END IF
  NEXT
  teLog.Insert("\n")
END

briansykes

  • Newbie
  • *
  • Posts: 23
Re: TextEdit Add sub issue.
« Reply #2 on: October 19, 2009, 06:49:09 PM »
Alright due to extensive testing of the sub i've found a few bugs which i have hence forth fixed as far as i know first, if you clicked on the textedit and then inserted a line of text, it would insert where you clicked this was easily fixable by setting the TextEdit.Pos variable to the length of the test, along with the url highlighting text after a url was inserted.

PUBLIC SUB Add(Text AS String, OPTIONAL TextColor AS Integer, OPTIONAL bBold AS Boolean)
  DIM strWords AS String[]
  DIM i AS Integer
  DIM strWord AS String
  DIM strCheck AS String
  strWords = Split(Text, " ")
  FOR i = 0 TO strWords.Count - 1
    strWord = strWords
    strCheck = LCase(strWord)
    teLog.Pos = Len(teLog.Text)
    IF ModMain.isStart(strCheck, "http://") OR ModMain.isStart(strCheck, "www.") OR ModMain.isStart(strCheck, "https://") OR ModMain.isStart(strCheck, "ftp://") OR ModMain.isStart(strCheck, "irc://") OR ModMain.isStart(strCheck, "telnet://") OR ModMain.isStart(strCheck, "mailto:") THEN
      teLog.Select(String.Len(teLog.Text), 0)
      teLog.Format.Color = Color.RGB(0, 0, 168)
      teLog.Format.Font.Underline = TRUE
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      IF i = 0 THEN
        teLog.Insert(strWord)
      ELSE
        teLog.Insert(" " & strWord)
      END IF
      teLog.Format.Font.bold = FALSE
      teLog.Format.Font.Underline = FALSE
    ELSE
      teLog.Format.Color = TextColor
      IF bBold = TRUE THEN teLog.Format.Font.Bold = TRUE
      IF i = 0 THEN
        teLog.Insert(strWord)
      ELSE
        teLog.Insert(" " & strWord)
      END IF
      teLog.Format.Font.bold = FALSE
      teLog.Format.Font.Underline = FALSE
    END IF
  NEXT
  teLog.Insert("\n")
END