Write several textfield

I need to write 90 textfield taking parameters from a database.
i wrote a code for vb6 to have function:
Do While Not NumeroRiga > 90
sText = “text” & NumeroRiga
Form1(sText).Text = “”
NumeroRiga = NumeroRiga + 1
Loop

i don’t know how to convert to xojio

If your TextFields are named TF and are members of an array (1 to 90), then:

[code]Dim LoopIdx As Integer

For LoopIdx = 1 to 90
WriteTOS.WriteLine TF(LooopIdx).Text
Next[/code]

WriteTOS is a TextOutputStream.

The code above comes from the top of my head and must work.

Code to create a text file and get a TextOutputStream to write is here .

How do I set an array of TextFields ?
In the IDE, window design, place a TextArea in the window, put 1 into its index, duplicate it (to 90 items) and you’re done.

HTH,

Emile

i have an error during project compiling. xojo don’t accept TextField(LoopIdx).Text, it’s mismatch error for it

Post what you have so far. Make sure to click the code icon at the top of the editor before you paste it, so it makes it more legible.

Michelle,

I tried my advice in a simple project with 4 TextFields and one PushButton (to save) with in its Action:

[code] Dim WriteFI As FolderItem
Dim WriteTOS As TextOutputStream
Dim LoopIdx As Integer

WriteFI = GetSaveFolderItem("", “Save multiple TextFields.txt”)
If WriteFI <> Nil Then
WriteTOS = TextOutputStream.Create(WriteFI)
WriteTOS.WriteLine(“Text File Intro if needed, else remove that line”)

For LoopIdx = 0 To 3
  WriteTOS.WriteLine TF(LoopIdx).Text
Next
WriteTOS.Close

End If[/code]

Works fine here.

You have to adapt the code to write (above) to fit your needs, and create the code to read the text file…

PS: I had your error, but the variable name was wrong (LooopIdx) !

This is my code. Testo1 must have object name where to write parameter get from database
[ dim LoopIdx as integer
dim Testo1 as String
dim Testo2 as String
LoopIdx=1

  for LoopIdx=1 to 90
    'Testo1="TextField"+ Str(LoopIdx)+".Text"
    Testo2="SELECT * FROM Numero" + Str(LoopIdx)
    rs = db.SQLSelect(Testo2)
    'This is row that give me error
    Testo1.Text=rs.Field("Value").StringValue
    'if LoopIdx=1 then
    'TextField1.Text=rs.Field("Value").StringValue
    'end if
  next
  ][/code]

Sorry Michele, I did not notice the “most important word” in your question: database.

This will not work: Str(LoopIdx)

Did you set the TextFields to an array ?

I have to go, please, if Michele still have troubles, feel free to continue the explanation.

No, Sorry Emile, i’m newbie with xojo, i’m studying in this day. i understand now what you mean. really thanks

Great!!! it’s working. thanks for support!!!

[quote=173716:@michele scalini]This is my code. Testo1 must have object name where to write parameter get from database
[ dim LoopIdx as integer
dim Testo1 as String
dim Testo2 as String
LoopIdx=1

  for LoopIdx=1 to 90
    'Testo1="TextField"+ Str(LoopIdx)+".Text"
    Testo2="SELECT * FROM Numero" + Str(LoopIdx)
    rs = db.SQLSelect(Testo2)
    'This is row that give me error
    Testo1.Text=rs.Field("Value").StringValue
    'if LoopIdx=1 then
    'TextField1.Text=rs.Field("Value").StringValue
    'end if
  next
  ][/code][/quote]

I have trouble understanding what you want to obtain, and where the error could be, especially since you commented out the code where you report errors.

  • Which line has the error ? Is it Testo1.Text=rs.Field("Value").StringValue ?
  • Which part of the line is overshaddowed yellow, and what is the exact error message ? Mismatch is not quite clear…

real problem was on textfield, i didn’t declare control set for array

It is a real pleasure when I read this.

Thank you to you.

Feel free to send more question as this forum is here to do that.