To circumvent the problem of using a udt to store values from products.dat and rewrite back to a new .dat file, use a string array.
This keeps memory size intact and rewrites properly.
Perhaps it might be easier to edit values and save, but this code is bare bones display and re save.
Code: Select all
Sub inita(a() As String,record As String,n As Long)
Dim As Long t
a(n,1)= Mid(record,1,13) :t+=14
a(n,2)= Mid(record,t,30) :t+=30
a(n,3)= Mid(record,t,4) :t+=4
a(n,4)= Mid(record,t,4) :t+=4
a(n,5)= Mid(record,t,2) :t+=2
a(n,6)= Mid(record,t,1) :t+=1
a(n,7)= Mid(record,t,10) :t+=10
a(n,8)= Mid(record,t,1) :t+=1
a(n,9)= Mid(record,t,4) :t+=4
a(n,10)=Mid(record,t,6) :t+=6
a(n,11)=Mid(record,t,4) :t+=4
a(n,12)=Mid(record,t,6) :t+=6
a(n,13)=Mid(record,t,4) :t+=4
a(n,14)=Mid(record,t,4) :t+=4
a(n,15)=Mid(record,t,4) :t+=4
a(n,16)=Mid(record,t,255) :t+=255
a(n,17)=Mid(record,t,4) :t+=4
a(n,18)=Mid(record,t,4) :t+=4
a(n,19)=Mid(record,t,4) :t+=4
a(n,20)=Mid(record,t,4) :t+=4
a(n,21)=Mid(record,t,4) :t+=4
a(n,22)=Mid(record,t,4) :t+=4
End Sub
Sub showproducts(a() As String)
For x As Integer = Lbound(a,1) To Ubound(a,1)
print "press a key to move forward, escape to exit and save"
print
print " Record ";x;" of "; Ubound(a,1)
print
Print " BarcodeNumber ";a(x,1)
Print " posdescription ";a(x,2)
Print " salelocation ";a(x,3)
Print " agerestricted ";val(a(x,4))
Print " agelimit ";a(x,5)
Print " pricetype ";a(x,6)
Print " retailprice ";a(x,7)
Print " vatcode ";a(x,8)
Print " print_guarantee_message ";val(a(x,9))
Print " print_guarantee_code ";a(x,10)
Print " displaymessage ";val(a(x,11))
Print " messagenumber ";a(x,12)
Print " sendtoppr ";val(a(x,13))
Print " requestserial ";val(a(x,14))
Print " itemnotallowed ";val(a(x,15))
Print " itemnotallowed_reason ";(a(x,16))
Print " restrict_product_qty ";val(a(x,17))
Print " product_qty_allowed ";val(a(x,18))
Print " discount_not_allowed ";val(a(x,19))
Print " no_refund_allowed ";val(a(x,20))
Print "ask_for_qty_before_selling ";val(a(x,21))
Print " healthy_start_voucher_ok ";val(a(x,22))
Print "--------------------------------------"
Sleep
If Inkey=Chr(27) Then Exit Sub
Next
End Sub
#Include "file.bi"
Sub savefile Overload(filename As String,p As String)
Dim As Integer n=Freefile
If Open (filename For Binary As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename
End If
End Sub
Sub savefile(filename As String,p() As String)
dim as string t
For n As Long=Lbound(p,1) To Ubound(p,1)
For m As Long=1 To 22
t+=p(n,m)
Next
Next
savefile(filename,t)
End Sub
Sub readfile(filename as string,s() As String)
Dim As Long f=Freefile,ctr
Open filename For Binary Access Read As #f
Dim As String record
Do Until Eof(f)
ctr+=1
Redim Preserve s(1 To Ubound(s,1) + 1,1 To 22)
record = Input(376, #f)
inita(s(),record,ctr)
Loop
Close #f
End Sub
Redim As String a(0,1 To 22)
readfile("products.dat", a())
showproducts a()
print "saving... please wait"
if fileexists("newproducts.dat") then Kill "newproducts.dat"
savefile("newproducts.dat",a())
Print "lenght original "; Filelen("products.dat")
Print "length saved "; Filelen("newproducts.dat")
? "OK"
Sleep