Writetable() questions

Discuss any general programming issues here
Post Reply
User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Writetable() questions

Post by Tarzin » Wed Mar 17, 2010 5:59 pm

Hello,

1) How can I know how many records have been written to a file with writetable() function ??

2) How can I add records to a file which have been written with writetable().
I've tried to use seek(1,#EOF). It seems that datas are recored but when I print them with nprint (data(47)), I got an error

I try to write data a first time to the file and then add datas a second time to the same file. I only success to get first datas recorded (46 by example), second datas (47 and more) are recorded too but can't be printed

Thanks for your help!
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Re: Writetable() questions

Post by Tarzin » Wed Mar 17, 2010 8:02 pm

Tarzin wrote: 1) How can I know how many records have been written to a file with writetable() function ??
For this question, simple:
Print (ListItems(table))
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

User avatar
airsoftsoftwair
Posts: 2670
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Writetable() questions

Post by airsoftsoftwair » Wed Mar 17, 2010 11:01 pm

You have to keep track of this on your own. I.e. simply write the number of tables at the start of the file and then call WriteTable() in a loop.

User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Re: Writetable() questions

Post by Tarzin » Thu Mar 18, 2010 9:12 am

So, first record should be my number of records in the table?

something like this table ={98,"data1", "data2", ....} where 98 is my numer of records?

I can't see how can I have somthing dynamic. 98 is in this case handly written. Can table={} handle variables?
Something like
c=Listitems(table)
table = {c, "data1", "data2", ....}
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

User avatar
Allanon
Posts: 442
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Writetable() questions

Post by Allanon » Thu Mar 18, 2010 8:54 pm

Your sample code will work but ofcourse the value written to the file will be the number stored in 'c' and not the 'c' reference, but doesn't matter because you can load your table, modify wathever you want and then write your modified table overwriting the old one.
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Re: Writetable() questions

Post by Tarzin » Fri Mar 19, 2010 4:50 pm

Need some help...
sorry for my beginner code, I'm learning

---

@VERSION 4,0
@APPTITLE "Writetable()"
@APPAUTHOR "Tarzin"
@APPVERSION "$VER : 0.01 - Mars 2010"
@APPDESCRIPTION "Writetable() function tests"

@DISPLAY {title="WriteTable() Function tests", x=#CENTER, y=#CENTER, width=640, height=480, color=$000000}

; num : number of records in the table
; dat1 : first serie of datas
; dat2 : second serie of datas
; num2 : total of records (dat1+dat2)

;open file and list fields
;
Function p_open()
OpenFile(1, "writetable.bin", #MODE_READ)
dat=ReadTable(1)
NPrint ("") NPrint (ListItems(dat),"Record(s) in table:") NPrint ("")

For i=0 To ListItems(dat)-1
NPrint ("Field",i,":",dat)
Next
EndFunction


Local num, num2 = 0
NPrint ("1) Opening & creating file writetable.bin ")
OpenFile(1,"writetable.bin", #MODE_WRITE)
dat1 ={num,"Data1","Data2","Data3","Data4"}
WriteTable(1,dat1)
CloseFile(1)
NPrint("") NPrint ("File writetable.bin created...") NPrint ("") NPrint ("")


NPrint ("2) Opening file writetable.bin...")
p_open()
CloseFile(1)
num=(ListItems(dat))
NPrint ("")


NPrint ("3) Opening file writetable.bin for the second time") NPrint ("")
OpenFile(1,"writetable.bin", #MODE_WRITE)
dat2 ={"Data5","Data6","Data7","Data8","Data9","Data10","Data11"}
num2=ListItems(dat2) NPrint (num2,"records to add") NPrint ("")
Seek(1,0)
dat3={num2+num}
NPrint("Writing writetable.bin Header...") NPrint("")
WriteTable (1,dat3)

NPrint ((num2+num),"fields to record")

NPrint("Writing dat2 to writetable.bin...") NPrint("")
Seek (1,#EOF)
WriteTable(1,dat2)
CloseFile(1)

NPrint("")NPrint ("4) Checking recorded datas...") NPrint ("")
p_open()

WaitLeftMouse()
CloseFile(1)
End

---
This code is not fully working. Table is written but datas are lost
How can I correct to have my 12 datas in writetable.bin file? (1 header data + 11 datas)
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

Post Reply