I am trying to print a series of letters in a textarea with styled text.
I have a routine that replaces all instances of certain text with customer names, address, etc.
The code looks something like this:
[code]
//WordProcessor_container1
//SUBROUTINE ReplaceAllStyledText(SourceText as TextArea, TextToFind as string, ReplacementText as string)
// how often is the TextToFind in the SourceText?
dim i as integer = InStr( SourceText.text, TextToFind )
// iterate over the text until all occurences have been replaced
while i > 0
SourceText.SelStart = i-1
SourceText.SelLength = Len( TextToFind )
SourceText.SelText = ReplacementText
i = InStr( SourceText.text, TextToFind )
wend[/code]
s = WordProcessor_container1.TextArea1.StyledText //Save the original text to be reused
WordProcessor_container1.ReplaceAllStyledText(WordProcessor_container1.TextArea1,"<firstname>",fname) // pass the TextArea into the method, not just the text of it
Dim stp As StyledTextPrinter
Dim g As Graphics
Dim ps As New PrinterSetup
Dim pageWidth, pageHeight As Integer
If PageSetup <> "" Then //PageSetup contains properties
ps.setupString=PageSetup
pageWidth=ps.Width-36
pageHeight=ps.Height-36
// open Print dialog with Page Setup properties
g=OpenPrinterDialog(ps)
Else
g=OpenPrinterDialog //open dg w/o Page Setup properties
pageWidth=72*7.5 //default width and height
pageHeight=79*9
End If
If g <> Nil Then //user didnt cancel Print dialog
stp=WordProcessor_container1.TextArea1.StyledTextPrinter(g,pageWidth-48)
Do Until stp.EOF
stp.drawBlock 36,36,pageHeight-48
If Not stp.eof Then //is there text remaining to print?
g.NextPage
End If
Loop
End If
WordProcessor_container1.TextArea1.StyledText = s //Replace the original text for the next letter to print
All works well until I try to do this in a loop of records. The textarea does not update and so the same data stays merged in the letter. Not sure how to let the UI update so the textarea returns to the original text so it can be reformatted for the next customer.
Is there a way to not use the textarea but instead place the styled text into a variable, replace the desired text with data, and then print that?