Can't you just store the styleruns in an array? I don't know, it's been a
while since I used them...

Maarten


On 18/11/06, Emile SCHWARZ <[EMAIL PROTECTED]> wrote:

Hi,

REALbasic 2006r4 running on Mac OS X 10.4.8 (but will be deployed on Linux
and Windows if possible)

I wanted to add to my simple text editor (small amount of text, else I use
- when possible - TextEdit or a true text processing software) the
LowerCase, UpperCase, TitleCase functions and so I started using LowerCase.

As usual (with newbies and people with memory indexing troubles), I forget
_the styles_ of the original text... See CODE #1.

Then, I wrote CODE #2 who gracefully takes care (store / restore) of the
text styles (Bold, Italic, ... TextName, TextSize, TextColor). But it takes
forever (see next paragraph) to convert 20 characters

The final code runs on around 36 Ticks for 20 characters
(ABCDEFGHIJKLMNOPQRST), each using one color different from the previous,
style also different from the previous (Plain, Bold, Italic), but only one
Font Name / Font Size (I was tired at that stage!)

My (simple) question is:

How can I get my code run faster ?

PowerBook G4, 15", 1.5GHz, RAM: 512MB
[Changing the machine is not an option]


I searched in the Language Reference, but I didn't saw anything that can
help me running faster or writting different code who achieve the same job.
Any taker for this challenge ?


[Also, an advice to code TitleCase is welcome; the code below is not
"usable" with TitleCase ;) !]


TIA,

Emile

CODE #1
-------
The code below was used to set LowerCase an EditField's selected text
(very fast):
Dim StartSel As Integer
Dim LenSel   As Integer

// Get these three properties
StartSel = Me.SelStart
LenSel   = Me.SelLength

// Set the change
Me.SelText = LowerCase(Me.SelText)

// Select back the changed text [re-select the text as it was prior the
case change]
Me.SelStart  = StartSel
Me.SelLength = LenSel


CODE #2
-------
The code below seems to work fine, but takes "times" on only 20 characters
(think at a large document!):
//
// Change the case of the selected text to LowerCase
//
Dim StartSel As Integer // Position of the first selected Character
Dim LenSel   As Integer // Number of selected Characters
Dim CharIdx  As Integer // Loop indice
Dim EndSel   As Integer // Top value of the Loop (meaningless name!)
// Used to store and restore the character styles
Dim sPlain     As Boolean
Dim sBold      As Boolean
Dim sCondense  As Boolean
Dim sExtend    As Boolean
Dim sItalic    As Boolean
Dim sOutline   As Boolean
Dim sShadow    As Boolean
Dim sUnderline As Boolean
Dim sTextColor As Color
Dim sTextFont  As String
Dim sTextSize  As Integer

Dim TickStart As Double
Dim TickEnd As Double

TickStart = Ticks

// Get these three properties
StartSel = Me.SelStart
LenSel   = Me.SelLength
EndSel   = StartSel + LenSel

For CharIdx = StartSel To EndSel
   // ------------------------- ----- ----- ----- -----
   // CHANGE ONE CHARACTER CASE
   // -------------------------
   // Select one character at a time
   Me.SelStart = CharIdx

   // Set .SelLength to one character only
   Me.SelLength = 1

   // Save the Character properties
   // a. Get the Character styles
   sPlain = Me.SelPlain
   If sPlain Then
     // Do nothing, already done!
   Else
     sBold      = Me.SelBold
     sCondense  = Me.SelCondense
     sExtend    = Me.SelExtend
     sItalic    = Me.SelItalic
     sOutline   = Me.SelOutline
     sPlain     = Me.SelPlain
     sShadow    = Me.SelShadow
     sUnderline = Me.SelUnderline
   End If
   // b. Set the Text styles
   sTextColor = Me.SelTextColor
   sTextFont  = Me.SelTextFont
   sTextSize  = Me.SelTextSize

   // Set the change (one character at a time)
   Me.SelText = LowerCase(Me.SelText)


   // ------------------------- ----- ----- ----- -----
   // SET THE CHARACTER STYLES BACK
   // -----------------------------
   // Select one character at a time
   Me.SelStart = CharIdx

   // Set .SelLength to one character only
   Me.SelLength = 1

   // Restore the Character properties

   // a. Set the Character styles
   If sPlain Then
     Me.SelPlain = sPlain
   Else
     Me.SelBold      = sBold
     Me.SelCondense  = sCondense
     Me.SelExtend    = sExtend
     Me.SelItalic    = sItalic
     Me.SelOutline   = sOutline
     Me.SelShadow    = sShadow
     Me.SelUnderline = sUnderline
   End If
   // b. Set the Text styles
   Me.SelTextColor = sTextColor
   Me.SelTextFont  = sTextFont
   Me.SelTextSize  = sTextSize
Next

// Select back the changed text [re-select the text as it was prior the
case change]
Me.SelStart  = StartSel
Me.SelLength = LenSel

TickEnd = Ticks

MsgBox "Duration: " + Str(TickEnd - TickStart) + " (in Ticks)"

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to