Liberty BASIC Community Forum
« Why the file data is always overwritten ? »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 12:16am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Why the file data is always overwritten ?  (Read 184 times)
Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Why the file data is always overwritten ?
« Thread started on: Aug 12th, 2016, 11:24am »

Hi there ,

wanna make a sequential database with a one dimensional array. dim 1000

Here are 3 options. D - new data
S - Search
N - exit

If the user choose D the first is line 100 and the While loop is getting the data line by line.
The index0 variable is counting the words.

Then the user is asked for input and the input data
should be stored in the array in the for loop
daten$(index0+m)
Then the array with the right number (existing+m)
is written to file : print #1,daten$(index+m)

in line 500 the file is closed and then in 590 the file
is read again for a sorting routine (not yet in),

in 900 - after the sorting routine then..

the data arrays are written in the sorted order to file.
so many words as the variable index1 before has counted.


The problem is :

If you run the program and input first data arrays than
it is ok.

The searching routine is already running. ok

When you leave the program with N option
from line 20 to 510 , the data is displayed
with line 630 and seen.

But new data entries are overwriting old ones.

Seems that i have made here a mirror in indexing
the arrays on the right place in the loops.


Its a little bit strange.



WBR Zabo



Rem Sequentielle Datenbank = .txt Datei mit Suchfunktion und Sortierung


10 CLS

15 dim daten$(1000)

20 Print "Wollen Sie neue Daten eingeben oder wollen Sie suchen ? ( D / S /N)"
30 Print

40 Input Y$

50 If Y$ = "D" or Y$ = "d" then goto 100
60 If Y$ = "S" or Y$ = "s" then goto [searchfor]
65 If Y$ = "N" or Y$ = "n" then goto 510
70 If Y$ <> "D" and Y$ <> "d" and Y$ <> "S" and Y$ <> "s" then goto 20



100 index = 1
110 open "datenbank.txt" FOR Input AS #1
120 WHILE EOF(#1)= 0
130 LINE INPUT #1,daten$(index)
140 Print daten$(index)
150 index = index + 1
160 WEND
170 close #1


210 open "datenbank.txt" for output as #1 ' open text file for write
212 index0 = index+1

220 for m= 1 to 1000
Print " Jetzt koennen Sie neue Daten eingeben"
Print
input " Neuer Datensatz : " ; daten$(index0+m)
print #1 , daten$(index0+m)
Print
Print " Der neue Datensatz : " ; daten$(index0+m) ; " : wurde abgespeichert" : print : print
Print "Wollen Sie neue Daten eingeben ( J / N )"
Print
Input Z$
If Z$ = "J" or Z$ = "j" then print "Neue Dateneingabe" : print : print
If Z$ = "N" or Z$ = "n" then exit for
If Z$ <> "J" and Z$ <> "N" and Z$ <> "j" and Z$ <> "n" then exit for : close #1 : goto 20
Print
next m



500 close #1
510 Print " Vielen Dank fuer die Eingaben , Auf Wiedersehn" : print

590 index1 = 1
600 open "datenbank.txt" FOR Input AS #1
610 WHILE EOF(#1)= 0
620 LINE INPUT #1,daten$(index1)
630 Print daten$(index1)
640 index1 = index1 + 1
650 WEND
700 close #1


'' here comes the sorting algorhytm in YEAH



900 index2 = 1
910 open "datenbank.txt" for output as #1
920 for x = 1 to index1
930 print #1, daten$(x)
940 next
950 close #1






1000 end





[searchfor]

input "Type some text to search for? "; searchFor$
print "Searching for: " : print
print " "; searchFor$ : print
I = 1
nomatch = 1
open "datenbank.txt" for input as #1
WHILE EOF(#1)= 0
Line input #1,daten$(I) ' Input ein String ein lesen

a$ = upper$(daten$(I))
b$ = upper$(searchFor$)
if instr(a$, b$) > 0 then
print "Found! " ;daten$(I) : nomatch = 0 : print : print 'Gosub [Editdata]
end if
I = I + 1
WEND
if nomatch <> 0 then print "No matches found !" : print
close #1
goto 20



[Editdata]





« Last Edit: Aug 12th, 2016, 11:25am by Zabo » User IP Logged

Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Re: Why the file data is always overwritten ?
« Reply #1 on: Aug 12th, 2016, 11:44am »

Hi twice ,

i forget to say that the txt. file in this program code

is not produced automatic because it begins with

a sequential INPUT - Reading routine.

My mistake.

First Output and write , produces the txt.file.

i know. but forget.

a wordpad makes the job fast.

____________________________________________

The main theme in the code above is the following :

How is a .txt sequential file open and scanned with
a while loop to get the number of existing arrays
in there and then to.....

(sort the data first with a algorythm) AND

tell the for loop with a variable the existing numbers
because to write the arrays in the sorted order
back to the file.


I know that in append mode it is easier.
Also in random mode with lof(#1) / len


Sorry , not easier , only different.


See you.... on LB planet
« Last Edit: Aug 12th, 2016, 12:02pm by Zabo » User IP Logged

Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Re: Why the file data is always overwritten ?
« Reply #2 on: Aug 13th, 2016, 5:00pm »

Marathon programming ,

i got it.


Zabo
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls