finding and styling a piece of text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

finding and styling a piece of text

Post by Da_Elf » Sat Oct 25, 2014 4:26 pm

just to point out i have already looked at these pages
http://lessons.runrev.com/m/4071/l/5867 ... vecode-5-5
http://lessons.runrev.com/m/4603/l/4409 ... -with-text

i want that when im filling in a text field it will look in a database. and start finding matches for what im typing as i type. ive got that good so far. What i want it to do though is to style the chunk or chunks of text in what was found.

if i type in "ha" it will find in the database "Michael" however i want it to find in the word and change the background color of "ha" within "Michael" i did a small text with "find" but it didnt draw a box around "ha" like i thought it would. This is my code. I store whats being typed into the custom property cExistChecker so that i can keep whats being typed and whats showing separate.

Code: Select all

on newTabName
   if visible of grp "TabCreate" is true then
      put the cExistChecker of fld "tabPersonName" into tabzName
      if tabzName <> empty then
         put "SELECT tabname FROM tabs WHERE tabname LIKE '%"& tabzName &"%' ORDER BY tabname LIMIT 1 " into tdSQL
         put revDataFromQuery(comma, cr, gConnectionID, tdSQL) into tData
         if tData is empty then
            set the text of fld "tabPersonName" to tabzName
         else
            set the text of fld "tabPersonName" to tData
         end if
      end if
      find tabzName in fld "tabPersonName"
      send "newTabName" to me in 0
   end if
end newTabName

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: finding and styling a piece of text

Post by jmburnod » Sat Oct 25, 2014 4:48 pm

Hi,
You may play with the foundchunk:

Code: Select all

find tabzName in fld "tabPersonName"
set the textcolor of the foundchunk to red
Best regards
Jean-Marc
https://alternatic.ch

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: finding and styling a piece of text

Post by Da_Elf » Sat Oct 25, 2014 6:35 pm

i added string to it and it worked perfectly as long as i made sure to test that my string was more than 1 characters or it would have fit

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: finding and styling a piece of text

Post by jmburnod » Sun Oct 26, 2014 10:13 am

Hi,
i added string to it and it worked perfectly as long as i made sure to test that my string was more than 1 characters or it would have fit
Sorry, I forgot "string" :oops:
I tested (LC 5.5) with one char and it works

Code: Select all

   put "Michael" into fld 1
   find string "h" in fld 1
   set the textcolor of the foundchunk to red
https://alternatic.ch

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: finding and styling a piece of text

Post by Da_Elf » Sun Oct 26, 2014 2:27 pm

that 5.5. that would explain where the textcolor came from. im on 6.x and its foregroundColor

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: finding and styling a piece of text

Post by jmburnod » Sun Oct 26, 2014 2:45 pm

that 5.5. that would explain where the textcolor came from. im on 6.x and its foregroundColor
No. ForegroundColor and textcolor are synonym
Just tested with LC 6.6 and it works
https://alternatic.ch

Post Reply