converting from VB to XOJO

From my VB6 app

"
Open “c:\Documents and Settings\Brygger\Mine Dokumenter\Dropbox\logg\loggtemp.txt” For Append As #1

    Print #1, Date
  Print #1, Time
 Print #1, Tab(12); "Rom"; Tab(20); "1"; Tab(28); "2"; Tab(36); "3"; Tab(44); "4"; Tab(52); "vekt"

 Close #1

"

But how do I do this in XOJO ?

[quote=158272:@Oddvar Demmo]From my VB6 app

"
Open “c:\Documents and Settings\Brygger\Mine Dokumenter\Dropbox\logg\loggtemp.txt” For Append As #1

    Print #1, Date
  Print #1, Time
 Print #1, Tab(12); "Rom"; Tab(20); "1"; Tab(28); "2"; Tab(36); "3"; Tab(44); "4"; Tab(52); "vekt"

 Close #1

"

But how do I do this in XOJO ?[/quote]

[code] // see http://documentation.xojo.com/index.php/TextOutputStream
// VB // Open “c:\Documents and Settings\Brygger\Mine Dokumenter\Dropbox\logg\loggtemp.txt” For Append As #1
Dim f as folderitem = specialfolder.desktop.child(“test.txt”) ’ GetFolderItem( “c:\Documents and Settings\Brygger\Mine Dokumenter\Dropbox\logg\loggtemp.txt”, FolderItem.PathTypeShell)
Dim t as TextOutputStream

if f<> nil then
t = TextOutputStream.Append(f)

//See http://documentation.xojo.com/index.php/date
dim d as new Date
t.Write(d.ShortDate+EndOfLine)
t.Write(d.ShortTime+EndOfLine)

// VB // Print #1, Date
// VB // Print #1, Time
// VB // Print #1, Tab(12); "Rom"; Tab(20); "1"; Tab(28); "2"; Tab(36); "3"; Tab(44); "4"; Tab(52); "vekt"
// There is no real equivalent to Print Tab. You may want to use function Mid() on a string made of spaces.
// For this snippet, I simply insert a tab character chr(9) between the fields
t.Write(chr(9)+"Rom"+chr(9)+"1"+chr(9)+"2"+chr(9)+"3"+chr(9)+"4"+chr(9)+"vekt"+EndOfLine)
// VB // Close #1
t.Close

end if[/code]

It is important that you get familiar with the language reference I placed links to. When you have a question, most of the time entering the command in the search box will give you a precise description, together with examples. What I am posting is taken in part from the second example at the TextOutputStream page. You also have access to the LR by clicking the Help icon on top of the Xojo IDE.

VB Tab() have no equivalent. It returns a number the spaces necessary to put the insertion point on the position. It’s not a Tab char (chr(9)).

Indeed. I used chr(9) for a quick snippet, and the result in Notepad is OK, but it is not at all the same.

As I noted, it is possible to emulate, but calculating the number of spaces needed requires keeping track of the strings length at each step, so one can calculate the next tab position. And that works only with fixed width fonts.

Chr(9) is a much more modern way of dealing with tabs. The VB Tab thing goes back to GWBasic, when text mode screens used monospaced characters and 132 columns was a luxury. We are talking vintage…

the whole concept addressing files with #Numbers goes strait back to gw-basic where you have to check first, which file number is free before you open anything. We all came a long way…

Something like (note I’ve written this entirely here in the forum so it may only be close)
Note there is no equivalent of the VB TAB so I just made it tab separated text

dim f as folderitem = GetFolderItem("C:\\Documents and Settings\\Brygger\\Mine Dokumenter\\Dropbox\\logg\\loggtemp.txt" , FolderItem.PathTypeAbsolute)

dim t as textoutputstream
if f.exists then
  t = TextOutPutStream.Append(f)
else
  t = TextOutPutStream.Create(f)
end if

dim d as new Date
t.writeline d.sqldate
t.writeline d.ShortTime
t.writeline  chrb(9) +  "Rom" + chrb(9) +  "1" + chrb(9) + "2" + chrb(9) + "3" + chrb(9) + "4" + chrb(9) +  "vekt"

[quote=158350:@Norman Palardy]

if f.exists then t = TextOutPutStream.Append(f) else t = TextOutPutStream.Create(f) end if[/quote]
Append can also create a file.

Thanks fore at lot of information and links.
Sorry, I has to tell I want to make this app fore Mac, the Win XP app work very well but I want to use Mac.

So I just need to know how to add text to the logg.txt file (or logg.rtf file)
the file is in “Macintosh HD/brukere/Dropbox/logg/logg.txt”

After a lot og Googling I cant find a way to access the file
Thanks

dim f as folderitem = GetFolderItem(“Macintosh\ HD/brukere/Dropbox/logg/logg.txt” , FolderItem.PathTypeShell)

ought to be close

Solved
When Timer1 fires

Dim f As FolderItem
f = GetFolderItem("/users/oddvardemmo/Dropbox/logg/logg.txt", FolderItem.PathTypeShell)
Dim t as TextOutputStream
dim d as new Date
t = TextOutputStream.Append(f)
t.Write(d.ShortDate)+" “+(d.ShortTime+” "+textfield2.text+EndOfLine)
t.Close

:slight_smile: OK no big deal but first time with file and wery different from VB
Thanks
“Users” confusing, on norwegian mac it is “brukere”

Use SpecialFolder.UserHome. That will always point to the current user’s home folder, no matter what language they use.