Weekly Qbasic and Qb64 Lesson Topics

QB64 lessons and tutorials,Games => Weekly Lesson => Topic started by: GarrisonRicketson on June 11, 2011, 08:03:24 am



Title: Name, Input File saveing
Post by: GarrisonRicketson on June 11, 2011, 08:03:24 am
Code:
COLOR 15: LOCATE 10, 12: PRINT SPACE$(20)
COLOR 14: LOCATE 10, 12: INPUT "Enter your Name: ", name$

   
This is simple enough, it asks to enter your name,..but I

am wondering, what more is needed , to make it where it also saves the

name to a file, so the next time the program runs, it already has the

name,..This could be more comlicated, but also I have to run, it is

time to go to work,...So I will have to explain more later.
from Garry


Title: Re: Name, Input File saveing
Post by: GarrisonRicketson on June 11, 2011, 11:25:20 pm
 Ok sorry, this morning I started to post the question, and then I noticed the time, and did not have time to get very detailed. Your comment, above , is pretty much it,...yea, it is a easy question to ask,...the "routine" (code) may be a lot harder, The code you posted would be what I want to do, except that one needs to create a file, before they run the program
Quote
Make sure you create the file and enter in a valid name before you run the program.
So when they enter the name, the program (this ) would "look" and if that name is not already been used, when they enter the name, it would then create the file, or add (the name) to a data base,..
 But just now thinking about it I realize this is not necessary,..for what I have in mind,...Because, once the name is entered,...as long as the program runs, it has the name, when a new person starts it, a new name is entered ,and it uses the new name, Sorry,..I confused myself, and probably you, now....
Code:
          SCREEN
PRINT "this is all there is to it "
COLOR 15: LOCATE 10, 12: PRINT SPACE$(20)
COLOR 14: LOCATE 10, 12: INPUT "Enter your Name: ", name$
IF UCASE$(name$) = UCASE$(name$) THEN PRINT "Hello "; name$; " Hope you enjoy this little program "
'///The rest could be any program, I just did these little things, for my 'explanation
PRINT " This is all there is to it , I think "
PRINT "This could be the rest of the program,press anykey to continue"
SLEEP
PLAY " abcdefg"
PRINT " 2 + 2 = "
PRINT 2 + 2
PRINT "Any key to exit"
SLEEP
IF UCASE$(name$) = UCASE$(name$) THEN PRINT "GoodBye, thank you for useing this program "; name$

_DELAY 2
SYSTEM
      
So after all said and done, I realize there is not really any need for what I was talking about,...Once the name is entered, it is used through out the entire program,...It was in the process of trying to think of how to explain what I was trying to do, that I realized, that was all ,simpley, when the person starts the program, get the name, and at the end say "goodby, thanks, Name". It might also use the name at various points in the program, but there is no need to make a file, with the name,..There still may be a better way to do this,..it did take me a while to get this to work right,...but I enjoyed it!
Thanks from Garry


Title: Re: Name, Input File saveing
Post by: ChatKing on November 27, 2011, 11:52:42 am
Hi to all

What I understood from your idea is that a program ask for the name if doesn't exist and then display, but if the name exists then it only display. I mean obviously it will ask for the name input at first run but then on every subsequent run it will only display the name. If I am write the code for this are as following, please check and then tell me were you asking about this, the code are as following:-

Code:
DIM na AS STRING
DIM a AS INTEGER

CLS
OPEN "Names.txt" FOR BINARY AS #1
a = LOF(1)
CLOSE #1

IF (a = 0) THEN
    INPUT "Enter Your Name : "; na
    OPEN "Names.txt" FOR OUTPUT AS #1
    PRINT #1, na
    CLOSE #1
    PRINT "Hello "; na
ELSE
    OPEN "Names.txt" FOR INPUT AS #1
    INPUT #1, na
    CLOSE #1
    PRINT "Hello "; na
END IF


Do you mean this the above code will ask for name only on first run until the text file names.txt exist in the directory on every subsequent run it will only display the code. Please comment, I am waiting and if this is not your desired code then a bit elaborate your question if you can by showing examples. Thanks

Keen to know about your idea.



Title: Re: Name, Input File saveing
Post by: GarrisonRicketson on November 28, 2011, 07:47:16 am
At first that had been ,the idea,..and the code you posted works good for this,..
 When the user runs it the first time, it asks the name, and saves it. From then on when the user starts it, it has the name,..Which is fine if it is always the same person, that uses the program,I guess another line is needed to say:
 If you are not:  original name , Please enter new name:
Then the new name also would be added to a "data base",..More kind of a "loggin" sort of thing,
because, the program nor the computer never has anyway of knowing, when somone starts the program, who it is,...
 So then I realized, it is sufficient, just asking the name ,when the program starts, and as long as it continues running, it would keep useing the name entered, there is no need to "save" the name, because the next user might be a different name,...
 Unless of course, if someone wanted, to make it more like a "loggin", type thing, and the first time, a "registration" is needed,...to get the name and any data ,..then there would be a need to save these to a file,..but  that is going into a entirely different, area,...similar to what even the forum uses, the user name, then the user has a "profile",...
------------------------
 The idea never was real clear to me,---one thought though, was this was for a "math" program, and I wanted a way, to make it where, when  Alfonso, (name) uses the program,. it would show, that he used it, how long, or if he completed it, this would be so when I asked him ,Did you parctice your math this week ?, and he says yes, I would have a way to, look at the programs "data base", and see if he was telling the truth,....but that is pretty complex, I still do not even come close to being able to do this.
 Another example, is some games have, a list of "high scores", if you get a high score you add your name to the list,...
 guess that about it from Garry