I've made a code which has data put in and when you put a number in, it shows the corresponding data. The problem is that i don't know how to get it to save new data that you put in. And also, i don't know how to get it to add an account automatically. You will see what i mean if you try to run it.
rem Declaring Data
dim database$(10,4)
database$(1,1) = "Name: name"
database$(1,2) = "Email: email"
database$(1,3) = "Account Name: accname"
database$(1,4) = "Account Status: accstatus"
goto choices
rem Choices
choices:
cls
print "Type 1 to search accounts"
print "Type 2 to add accounts"
input "Enter Choice> ",choice
if choice = 1 then goto search
if choice = 2 then goto add
goto choices
return
rem Search
search:
cls
input "Enter Account Number> ",number
if number = 1 then goto 1
if number = 2 then goto 2
if number => 2 then print "Invalid Number!"
wait key
goto choices
return
rem Add
add:
cls
input "Enter Name> ",currentname$
input "Enter Email> ",currentemail$
input "Enter Account Name> ",currentaccname$
input "Enter Account Status> ",currentaccstatus$
database$(2,1) = "Name: " + currentname$
database$(2,2) = "Email: " + currentemail$
database$(2,3) = "Account Name: " + currentaccname$
database$(2,4) = "Account Status: " + currentaccstatus$
print "Saved"
goto choices
return
rem Account 1
1:
cls
print database$(1,1)
print database$(1,2)
print database$(1,3)
print database$(1,4)
wait key
goto choices
return
rem Account 2
2:
cls
print database$(2,1)
print database$(2,2)
print database$(2,3)
print database$(2,4)
wait key
goto choices
return
EDIT - I have compleltely re-written most of the code and have now solved most of the issues.
I do still need help ironing out a couple more though.
I need to know how to check if a file exists and cancel a file reading operation if it doesn't. Because at the moment if the user types a file that doesn't exist, the program exits.
Also, i need to know how to set cd to the default path. At the moment, once you have made a default path, you have to go into settings and tell it to set it to the default path.
cd "Database"
currentdirectory$ = "Database"
goto choices
choices:
cls
print "Type 1 to search accounts"
print "Type 2 to add accounts"
print "Type 3 to change directory"
input "Enter Choice> ",choice
if choice = 1 then goto search
if choice = 2 then goto add
if choice = 3 then goto change
goto choices
return
search:
cls
input "Enter Account Number> ",number$
open to read 1, number$
read string 1, currentfile1$
read string 1, currentfile2$
read string 1, currentfile3$
read string 1, currentfile4$
cls
print currentfile1$
print currentfile2$
print currentfile3$
print currentfile4$
wait key
close file 1
goto choices
return
add:
cls
input "Enter ID> ",currentid$
cls
input "Enter Name> ",currentname$
cls
input "Enter Email> ",currentemail$
cls
input "Enter Account Name> ",currentaccname$
cls
input "Enter Account Status> ",currentaccstatus$
open to write 2, currentid$
write string 2, currentname$
write string 2, currentemail$
write string 2, currentaccname$
write string 2, currentaccstatus$
close file 2
cls
print "Saved"
wait key
goto choices
return
change:
input "Enter directory (1 is default)> ",currentdirectory$
if currentdirectory$ = "1" then goto defaultdir
open to write 3, "directory"
write string 3, currentdirectory$
close file 3
cd currentdirectory$
cls
print "'" + currentdirectory$ + "' has been set to the default directory."
wait key
open to write 3, "directory"
write string 3, currentdirectory$
close file 3
cls
goto choices
return
defaultdir:
open to read 4, "directory"
read string 4, defaultdir$
cd defaultdir$
close file 4
cls
print "'" + defaultdir$ + "' has been set to the default directory."
wait key
goto choices
return
I have edited it yet again (WITH LOADS OF HELP FROM GROG) to perfection (Hopefully)
cd "Database\"
if file exist ("directory") then gosub defaultdir
currentdirectory$ = "Database\"
choices:
do
cls
print "Type 1 to search data"
print "Type 2 to add data"
print "Type 3 to change directory"
input "Enter Choice> ",choice
if choice = 1 then gosub search
if choice = 2 then gosub add
if choice = 3 then gosub change
loop
return
search:
cls
repeat
cls
input "Enter ID (# to return)> ",number$
if number$ = "#" then gosub choices
until file exist(number$)
open to read 1, number$
read string 1, currentfile1$
read string 1, currentfile2$
read string 1, currentfile3$
read string 1, currentfile4$
cls
print "Name: " + currentfile1$
print "Price: " + currentfile2$
print "Supermarket: " + currentfile3$
print "Date: " + currentfile4$
wait key
close file 1
return
add:
cls
input "Enter ID (# to return)> ",currentid$
if currentid$ = "#" then gosub choices
cls
input "Enter Name (# to return)> ",currentname$
if currentname$ = "#" then gosub choices
cls
input "Enter Price (# to return)> ",currentprice$
if currentprice$ = "#" then gosub choices
cls
input "Enter Supermarket (# to return)> ",currentsupermarket$
if currentsupermarket$ = "#" then gosub choices
cls
input "Enter Date (# to return)> ",currentdate$
if currentdate$ = "#" then gosub choices
if file exist(currentid$) then delete file currentid$
open to write 2, currentid$
write string 2, currentname$
write string 2, currentprice$
write string 2, currentsupermarket$
write string 2, currentdate$
close file 2
cls
print "Saved"
wait key
return
change:
cls
input "Enter directory (1 is default, # to return)> ",currentdirectory$
if currentdirectory$ = "1" then gosub defaultdir
if currentdirectory$ = "#" then gosub choices
open to write 3, "directory"
write string 3, currentdirectory$
close file 3
cd currentdirectory$
cls
print "'" + currentdirectory$ + "' has been set to the default directory."
wait key
open to write 3, "directory"
write string 3, currentdirectory$
close file 3
cls
return
defaultdir:
open to read 4, "directory"
read string 4, defaultdir$
cd defaultdir$
close file 4
cls
print "'" + defaultdir$ + "' has been set to the default directory."
wait key
return
Please leave comments or suggestions.
Any help appreciated.
Matt
Umm...