DataBase example
DataBase example
On Dec. 14, Bbell, attached a PDF file to his post. ?In it was an example of a "Flat Database". ?Has anyone tried to use it. ?I have and I cannot get it to run. ?I keep getting "Stream read error". ?What is missing or am I just missing something.
Mel
Mel
DataBase example
Ok, here is what I have got on this. I can`t seem to get any farther with it. Can any one tell me why I can only add 2-3 lines before it crashes.
Mel
`Flat Data Base
const cl = chr$(13)+chr$(10)
dim myDb as filestream
dim sData() as string
dim s as string
dim ndx as integer
dim dbCnt as integer
dim delim as string
dim flatdatabase as application
dbCnt=0
delim=","
object democust as form
center=1
caption="Demo Customer Flat Database"
clientheight=400
clientwidth=384
color=&h808000`&hff00000f `clBtnFace
object label1 as label
left=156
top=36
width=19
height=13
caption="First"
end object `label1
object label2 as label
left=155
top=68
width=20
height=13
caption="Last"
end object `label2
object label3 as label
left=144
top=100
width=31
height=13
caption="Phone"
end object `label3
object label4 as label
left=112
top=128
width=69
height=13
caption="Current Index"
end object `label4
object richedit1 as richedit
left=16
top=288
width=185
height=89
line(0)="DemoDataBase"
fontcolor=&hFF
plaintext=1
scrollbars=ssvertical
hidescrollbars=0
taborder=0
end object `RichEdit1
object bLoadDB as button
left=16
top=16
width=75
height=25
caption="LoadDB"
taborder=1
onclick=bLoadDBClick
end object
object bPrev as button
left=16
top=66
width=75
height=25
caption="Prev"
enabled=0
taborder=2
onclick=bPrevClick
end object
object bNext as button
left=16
top=116
width=75
height=25
caption="Next"
enabled=0
taborder=3
onclick=bNextClick
end object
object bAdd as button
left=16
top=166
width=75
height=25
caption="Add"
enabled=0
taborder=4
onclick=bAddClick
end object
object bFinish as button
left=16
top=216
width=75
height=25
caption="Finished"
enabled=0
onclick=bFinishClick
end object
object eFirst as edit
left=190
top=32
width=121
height=21
taborder=5
text="eFirst"
passwordchar=0
end object
object eLast as edit
left=190
top=64
width=121
height=21
taborder=6
text="eLast"
passwordchar=0
end object
object ePhone as edit
left=190
top=96
width=121
height=21
taborder=7
text="ePhone"
passwordchar=0
end object
object bclear as button
left=213
top=191
width=75
height=25
caption="Clear"
taborder=8
onclick=bClearClick
end object
end object
democust.ShowModal
sub bLoadDBClick()
`your code here
if fileexists("democust.db") = 0 then
myDB.open("democust.db")
bAdd.enabled=0
bLoaddb.enabled=0
bFinish.enabled=1
exit sub
end if
myDB.open("democust.db")
ndx=0
dbCnt=myDB.linecount
`showmessage str$(dbCnt)+"Load"
dbCnt=dbCnt - 1 `3 lines 0-1-2 so Linecount - 1
if dbCnt-1<0 then
bAdd.enabled=1
exit sub
end if
richedit1.line(1)="test"
s=""
do
s=myDB.readline
richedit1.line(ndx+1)=s
sData(ndx)=s
ndx=ndx+1
if ndx = dbCnt then exit do
`showmessage "ndx = "+Str$(ndx)
loop
myDB.Close
ndx=0
`pre-load the edit boxes
eLast.text=field$(sData(ndx),delim,1)
eFirst.text=field$(sData(ndx),delim,2)
ePhone.text=field$(sData(ndx),delim,3)
label4.caption="Current Index: "+str$(ndx)
bLoadDB.enabled=0
bNext.enabled=1
bAdd.enabled=0
bfinish.enabled = 1
end sub `bLoadDBClick
sub bPrevClick()
`your code here
if ndx - 1<0 then
bprev.enabled=0
bnext.enabled=1
exit sub
end if
ndx=ndx-1
Label4.caption="Current Index: "+str$(ndx)
elast.text=field$(sData(ndx),delim,1)
efirst.text=field$(sdata(ndx),delim,2)
ephone.text=field$(sData(ndx),delim,3)
end sub `bPrevClick
sub bNextClick()
`your code here
if ndx+1=dbCnt then
bnext.enabled=0
bprev.enabled=1
ndx=dbCnt
exit sub
end if
ndx=ndx+1
Label4.caption="Current Index: "+str$(ndx)
elast.text=field$(sData(ndx),delim,1)
efirst.text=field$(sdata(ndx),delim,2)
ephone.text=field$(sData(ndx),delim,3)
end sub `bNextClick
sub bAddClick()
`your code here
ndx=dbCnt-1
dbCnt=dbCnt+1
dim sData(ndx) as string
sData(dbCnt)=eLast.text+","+eFirst.text+","+ePhone.Text+cl
`showmessage sdata(ndx)
`showmessage str$(myDB.position)+"POS"
myDB.write(sData(ndx))
Label4.caption="Current Index: "+str$(ndx)
bAdd.enabled = 0
end sub
sub bClearClick()
`your code here
eLast.text=""
eFirst.text=""
ePhone.text=""
bAdd.enabled = 1
end sub
sub bFinishClick()
flatdatabase.Terminate
end sub
`*************
Thanks
Mel
`Flat Data Base
const cl = chr$(13)+chr$(10)
dim myDb as filestream
dim sData() as string
dim s as string
dim ndx as integer
dim dbCnt as integer
dim delim as string
dim flatdatabase as application
dbCnt=0
delim=","
object democust as form
center=1
caption="Demo Customer Flat Database"
clientheight=400
clientwidth=384
color=&h808000`&hff00000f `clBtnFace
object label1 as label
left=156
top=36
width=19
height=13
caption="First"
end object `label1
object label2 as label
left=155
top=68
width=20
height=13
caption="Last"
end object `label2
object label3 as label
left=144
top=100
width=31
height=13
caption="Phone"
end object `label3
object label4 as label
left=112
top=128
width=69
height=13
caption="Current Index"
end object `label4
object richedit1 as richedit
left=16
top=288
width=185
height=89
line(0)="DemoDataBase"
fontcolor=&hFF
plaintext=1
scrollbars=ssvertical
hidescrollbars=0
taborder=0
end object `RichEdit1
object bLoadDB as button
left=16
top=16
width=75
height=25
caption="LoadDB"
taborder=1
onclick=bLoadDBClick
end object
object bPrev as button
left=16
top=66
width=75
height=25
caption="Prev"
enabled=0
taborder=2
onclick=bPrevClick
end object
object bNext as button
left=16
top=116
width=75
height=25
caption="Next"
enabled=0
taborder=3
onclick=bNextClick
end object
object bAdd as button
left=16
top=166
width=75
height=25
caption="Add"
enabled=0
taborder=4
onclick=bAddClick
end object
object bFinish as button
left=16
top=216
width=75
height=25
caption="Finished"
enabled=0
onclick=bFinishClick
end object
object eFirst as edit
left=190
top=32
width=121
height=21
taborder=5
text="eFirst"
passwordchar=0
end object
object eLast as edit
left=190
top=64
width=121
height=21
taborder=6
text="eLast"
passwordchar=0
end object
object ePhone as edit
left=190
top=96
width=121
height=21
taborder=7
text="ePhone"
passwordchar=0
end object
object bclear as button
left=213
top=191
width=75
height=25
caption="Clear"
taborder=8
onclick=bClearClick
end object
end object
democust.ShowModal
sub bLoadDBClick()
`your code here
if fileexists("democust.db") = 0 then
myDB.open("democust.db")
bAdd.enabled=0
bLoaddb.enabled=0
bFinish.enabled=1
exit sub
end if
myDB.open("democust.db")
ndx=0
dbCnt=myDB.linecount
`showmessage str$(dbCnt)+"Load"
dbCnt=dbCnt - 1 `3 lines 0-1-2 so Linecount - 1
if dbCnt-1<0 then
bAdd.enabled=1
exit sub
end if
richedit1.line(1)="test"
s=""
do
s=myDB.readline
richedit1.line(ndx+1)=s
sData(ndx)=s
ndx=ndx+1
if ndx = dbCnt then exit do
`showmessage "ndx = "+Str$(ndx)
loop
myDB.Close
ndx=0
`pre-load the edit boxes
eLast.text=field$(sData(ndx),delim,1)
eFirst.text=field$(sData(ndx),delim,2)
ePhone.text=field$(sData(ndx),delim,3)
label4.caption="Current Index: "+str$(ndx)
bLoadDB.enabled=0
bNext.enabled=1
bAdd.enabled=0
bfinish.enabled = 1
end sub `bLoadDBClick
sub bPrevClick()
`your code here
if ndx - 1<0 then
bprev.enabled=0
bnext.enabled=1
exit sub
end if
ndx=ndx-1
Label4.caption="Current Index: "+str$(ndx)
elast.text=field$(sData(ndx),delim,1)
efirst.text=field$(sdata(ndx),delim,2)
ephone.text=field$(sData(ndx),delim,3)
end sub `bPrevClick
sub bNextClick()
`your code here
if ndx+1=dbCnt then
bnext.enabled=0
bprev.enabled=1
ndx=dbCnt
exit sub
end if
ndx=ndx+1
Label4.caption="Current Index: "+str$(ndx)
elast.text=field$(sData(ndx),delim,1)
efirst.text=field$(sdata(ndx),delim,2)
ephone.text=field$(sData(ndx),delim,3)
end sub `bNextClick
sub bAddClick()
`your code here
ndx=dbCnt-1
dbCnt=dbCnt+1
dim sData(ndx) as string
sData(dbCnt)=eLast.text+","+eFirst.text+","+ePhone.Text+cl
`showmessage sdata(ndx)
`showmessage str$(myDB.position)+"POS"
myDB.write(sData(ndx))
Label4.caption="Current Index: "+str$(ndx)
bAdd.enabled = 0
end sub
sub bClearClick()
`your code here
eLast.text=""
eFirst.text=""
ePhone.text=""
bAdd.enabled = 1
end sub
sub bFinishClick()
flatdatabase.Terminate
end sub
`*************
Thanks
DataBase example
Did not test it yet but i have a few questions.
Which version of fnxBasic did you use?
In bAddClick you declare an array "dim sData(ndx) as string" but you only use 1 string.
I don`t know if dynamic dim statement works.
You use ReadLine and Write, should you add a linefeed to make it a kind of WriteLine else the ReadLine does not know where the line ends.
When writing you should write at end of file to append data.
In bLoadDBClick you open and close myDB but where do you open and close myDB in bAddClick?
In bLoadDBClick you use "if fileexists("democust.db") = 0 then" and open but do not close myDB.
Just a quick look so my questions can be wrong (as always :))
Which version of fnxBasic did you use?
In bAddClick you declare an array "dim sData(ndx) as string" but you only use 1 string.
I don`t know if dynamic dim statement works.
You use ReadLine and Write, should you add a linefeed to make it a kind of WriteLine else the ReadLine does not know where the line ends.
When writing you should write at end of file to append data.
In bLoadDBClick you open and close myDB but where do you open and close myDB in bAddClick?
In bLoadDBClick you use "if fileexists("democust.db") = 0 then" and open but do not close myDB.
Just a quick look so my questions can be wrong (as always :))
DataBase example
Fred, thanks for the reply. ?Let me try to answer some of your questions.
R
R
DataBase example
Wanted to spend some time in the weekend with this but as always time is used for something different.. :)
"I was trying to open myDB and leave it open until I was through using it. Is this possible or must I open and close at
every step." You can leave open if you want.
Do you want to write every time all lines or only before program exit?
Any progress Mel?
"I was trying to open myDB and leave it open until I was through using it. Is this possible or must I open and close at
every step." You can leave open if you want.
Do you want to write every time all lines or only before program exit?
Any progress Mel?
DataBase example
Hi Fred, I have made little or no progress with the program. I too have had to use time for other things. We had our family together this week end to help us celebrate our wedding aniversary (44 years). I tried to port the code into RapidQ, but ran into a simular problem there. I emailed a fellow that programs in RapidQ and he sent me a file that doesn`t use filestream. I was able to look at it last night for the first time. I will try to convert it to FNX as I have the time.
Mel....
Mel....
DataBase example
A bit late but congratulations with your wedding aniversary :)
If you keep your records/lines in memory you can read/write them using filestream but writing all could take some time.
In that case i would write changes to a text file so you could recover after a program crash (kind like sql transaction log files).
if you have any questions let me know, i`m gad to help but sometimes i could use more time :)
Fred.
If you keep your records/lines in memory you can read/write them using filestream but writing all could take some time.
In that case i would write changes to a text file so you could recover after a program crash (kind like sql transaction log files).
if you have any questions let me know, i`m gad to help but sometimes i could use more time :)
Fred.
DataBase example
Thanks Fred. I haven`t had much time? lately to work on this either .? Several other projects have moved to the fore front that I must take care of.? I will let you know if I make any progress.
Mel...
Mel...