program reading and writing problem, complicated with gui
Author 
Message 
hey_joe42

Posted: Fri Mar 07, 2003 10:03 am Post subject: program reading and writing problem, complicated with gui 


i have a gui program it attached just in case but the main problem is the reading and writign to the binary file
here is the reading code(my goal is to have it read it into a variable that displays the text, string, int, real, in the gui text fields it will work if i get this one problem fixed):
type inventory :
record
product : string (10) %the product's name
manufacturer : string (10) %The company that made product
price : real %the products price%real
number : int %the number of products in the warehouse%int
reorder : int %the number which to order more; unsafe number%int
numinstock : int %the number that should be kept in stock %int
prodnumber : string ( 8 ) %the products id number %string
%amtorder : int %the ammount to order
cater : string (10) %what the product catergories as
%ammount to reorder,
%product number
sale : boolean
end record
var prod : array 1 .. 50 of inventory
var numRecords : int := 1
var currentRecord : int := 1
var produ : array 1 .. 50, 1 .. 9 of string
var pos : int
var recordnumb :=1
open : fn, "inventoryss.bin",read, seek
put fn
delay(1000)
if fn = 1 then
put"hi"
delay(5000)
seek : fn, *
tell : fn, pos
put sizeof(inventory)
put pos
recordnumb := pos div (sizeof (inventory))
put recordnumb
delay(1000)
for i : 1 .. recordnumb
put fn
read : fn, prod (i)
put prod(i).product,"..."
delay(1000)
produ (i, 1) := prod (i).product
put produ(i,1)
delay(100)
produ (i, 2) := prod (i).manufacturer
produ (i, 3) := intstr (prod (i).number)
produ (i, 4) := realstr (prod (i).price, 8 )
produ (i, 5) := intstr (prod (i).reorder)
produ (i, 6) := intstr (prod (i).numinstock)
produ (i, 7) := prod (i).prodnumber
produ (i, 8 ) := prod (i).cater
if prod (i).sale = true then
produ (i, 9) := "yes"
else
produ (i, 9) := "no"
end if
end for
for z:recordnumb+1..50
put z
produ (z, 1) := ""
produ (z, 2) := ""
produ (z, 3) := "0"
produ (z, 4) := "0"
produ (z, 5) := "0"
produ (z, 6) := "0"
produ (z, 7) := "11111" + intstr (z)
produ (z, 8 ) := ""
produ (z, 9) := ""
end for
else
for z:recordnumb..50
produ (z, 1) := ""
produ (z, 2) := ""
produ (z, 3) := "0"
produ (z, 4) := "0"
produ (z, 5) := "0"
produ (z, 6) := "0"
produ (z, 7) := "11111" + intstr (z)
produ (z, 8 ) := ""
produ (z, 9) := ""
end for
end if
close : fn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the writing to the file part:
loop
if buttonmoved ("down") then
buttonwait ("down", mx, my, mbtn, mbtn)
if mbtn = 1 then
if mx > 15 and mx < 35 and my > 13 and my < 30 then
%close:fn
put currentRecord
put produ (1, 3)
open : fn, "inventorys.bin", write, mod, seek, read
for i : 1 .. currentRecord  1
%
prod (i).product := produ (i, 1)
prod (i).manufacturer := produ (i, 2)
if strintok (produ (i, 3)) then
put "asdf"
prod (i).number := strint (produ (i, 3))
put prod (i).number
end if
if strrealok (produ (i, 4)) then
put "sdf"
prod (i).price := strreal (produ (i, 4))
end if
if strintok (produ (i, 5)) then
put "sd"
prod (i).reorder := strint (produ (i, 5))
end if
if strintok (produ (i, 6)) then
prod (i).numinstock := strint (produ (i, 6))
end if
prod (i).prodnumber := produ (i, 7)
prod (i).cater := produ (i, 8 )
if produ (i, 9) = "yes" or produ (i, 9) = "true" then
prod (i).sale := true
else
prod (i).sale := false
end if
seek : fn, (sizeof (inventory) * (i  1))
write : fn, prod (i)
%read:fn, prod(i)
%put prod(i).product
%delay(1000)
%close : fn % goes to help
end for
close : fn
end if
if mx > 225 and mx < 250 and my > 13 and my < 30 then
quit
end if
end if
end if
exit when GUI.ProcessEvent
end loop
%%%%%%%%%%%%%%%%%%%%%%%
If your looking at this, and might have an idea, plz give feedback, advice, etc, websites whatever, tho if you think it might be a problem somewhere else feel free to check the file, run it or whatnot, it will work i presume if you change the beginning in read; change the line that says, if fn=1 to if fn=10
Description: 

Download 
Filename: 
12vworking.t 
Filesize: 
13.78 KB 
Downloaded: 
256 Time(s) 






Sponsor Sponsor



Tony

Posted: Fri Mar 07, 2003 11:44 am Post subject: (No subject) 


I dont exactly understand your problem... If you're reading a value, shoudn't you know what type it is based on file format?
otherwise you can read everything as a string, then use strint and strreal to convert it to other formats.
If thats not it, plz specify whats wrong

Tony's programming blog. DWITE  a programming contest. 




hey_joe42

Posted: Mon Mar 10, 2003 5:52 pm Post subject: solved reading problem stuck on writing 


im going to post this msg twice because i really need an answer on this question
okay i solved the original reading problem i was having( you can see for yourself how i did so) but now i can't figure out the writing to a file part,
Plz try out the program yourself cuz the problem probably lies somewhere else, thank you for your time!
here is my code for writing to the file:
var font1:int
font1 := Font.New ("serif:12")
loop
if buttonmoved ("down") then
buttonwait ("down", mx, my, mbtn, mbtn)
if mbtn = 1 then
if mx > 15 and mx < 35 and my > 13 and my < 30 then
%close:fn
open : fn, "inventory.bin", write, mod, seek, read
for i : 1 .. currentRecord  1
%
prod (i).product := produ (i, 1)
prod (i).manufacturer := produ (i, 2)
if strintok (produ (i, 3)) then
prod (i).number := strint (produ (i, 3))
end if
if strrealok (produ (i, 4)) then
prod (i).price := strreal (produ (i, 4))
end if
if strintok (produ (i, 5)) then
prod (i).reorder := strint (produ (i, 5))
end if
if strintok (produ (i, 6)) then
prod (i).numinstock := strint (produ (i, 6))
end if
prod (i).prodnumber := produ (i, 7)
prod (i).cater := produ (i, 8)
prod(i).sale:=produ(i,9)
seek : fn, (sizeof (inventory) * (i  1))
Font.Draw ("Writing to file!", 50, 30, font1, red)
write : fn, prod (i)
delay(5000)
Font.Draw("Writing to file!",50,30,font1,white)
%read:fn, prod(i)
%put prod(i).product
%delay(1000)
%close : fn % goes to help
end for
close : fn
end if
if mx > 225 and mx < 250 and my > 13 and my < 30 then
quit
end if
end if
end if
exit when GUI.ProcessEvent
end loop
Description: 

Download 
Filename: 
16vworking.t 
Filesize: 
13.25 KB 
Downloaded: 
271 Time(s) 






Tony

Posted: Tue Mar 11, 2003 12:01 pm Post subject: (No subject) 


to be honest, I dont know about reading/writing to a binary file. When I need random access, I usually use a database such as MS Access or MySQL.
And I cant say where the problem is since I cant even run the file. Datafile is missing.

Tony's programming blog. DWITE  a programming contest. 




hey_joe42

Posted: Wed Mar 12, 2003 12:13 pm Post subject: data file 


heres the datafile just change the file name to .bin or change it in the program to .t
Description: 

Download 
Filename: 
Copy of inventory.t 
Filesize: 
1020 Bytes 
Downloaded: 
310 Time(s) 






Tony

Posted: Wed Mar 12, 2003 10:57 pm Post subject: (No subject) 


first of all... your add record doesnt work... some value for settext price is missing
as for writing part, you got a loop running 1 .. currentRecord  1
so its running from 1 to 0, which means NOTHING will be writen to the file.
here's the kicker  you need to add more records to save something, but that brings us back to the "add record" function that doesnt work

Tony's programming blog. DWITE  a programming contest. 





