[BASIC] how to add text in a Draw document?

Hello,

I have tried adding text to an existing empty Draw document, following the info I found in A. Pytoniak’s book on macros, but the text doesn’t appear. Here is my code:

REM  *****  BASIC  *****

Function createPoint(ByVal x As Long, ByVal y As Long) As com.sun.star.awt.Point
  dim oPoint
  oPoint = createUnoStruct( "com.sun.star.awt.Point" )
  oPoint.X = x
  oPoint.Y = y
  createPoint = oPoint
End Function

Function createSize(ByVal x As Long, ByVal y As Long) As com.sun.star.awt.Size
  dim oSize
  oSize = createUnoStruct( "com.sun.star.awt.Size" )
  oSize.Width = x : oSize.Height = y
  createSize = oSize
End Function

Sub Main
dim oDoc, page, texte, point
oDoc = ThisComponent
page = oDoc.getDrawPages().getByIndex(0)
page.width = 1485
page.height = 1050
page.borderLeft = 50
page.borderTop = 50
page.borderRight = 50
page.borderBottom = 50

page.orientation = com.sun.star.view.PaperOrientation.LANDSCAPE

texte = oDoc.createInstance("com.sun.star.drawing.TextShape")
'point = createUnoStruct( "com.sun.star.awt.Point" )
'point.X = 10
'point.Y = 5
'rect.position = point
texte.setPosition( createPoint( 50, 50 ) )
texte.setSize( createSize( 1385, 950 ) )
texte.setString("HTH")
texte.string =" 123 "

page.add(texte)


End Sub

Can anybody help or point to other info? Thanks!

Move page.add(texte) to the line immediately after you create the TextShape:

texte = oDoc.createInstance("com.sun.star.drawing.TextShape")
page.add(texte)