Computer Science, asked by rameshkatiyar503, 8 months ago

write the steps to save a qbasic program

Answers

Answered by Amazonalexa
3

Explanation:

you have inputed the username with something like,

INPUT "Type your username: ", uName$

To save it to a file, simply use these commands:

OPEN "User.dat" FOR OUTPUT AS #1

PRINT #1, uName$

CLOSE #1

Here's a complete program:

DEFINT A-Z

'Error handler for the first time we run the program. The data file won't exist, so we create it.

ON ERROR GOTO FileNotExist

'Create a type and an Array of users that would include Username and the Status (adminstrator vs. Unwanted user)

TYPE user

Uname AS STRING * 16

Status AS STRING * 1

END TYPE

DIM Users(1 TO 100) AS user

'Gets all the users stored in the file. i is a variable which represents the number of users before adding a new user

i = 0

OPEN "User.txt" FOR INPUT AS #1

WHILE NOT EOF(1)

i = i + 1

INPUT #1, Users(i).Uname

INPUT #1, Users(i).Status

WEND

CLOSE #1

TryAgain:

'Gets info for the new user

CLS

INPUT "User name: ", Users(i + 1).Uname

PRINT "Admin (a), Unwanted user (u), or Regular user (r) ?"

Users(i + 1).Status = LCASE$(INPUT$(1))

'Ensure there are no blank lines in the file

IF Users(i + 1).Uname = "" OR Users(i + 1).Status = "" THEN GOTO TryAgain

'Outputs user data to the file "User.txt"

OPEN "User.txt" FOR OUTPUT AS #1

FOR j = 1 TO i + 1

PRINT #1, Users(j).Uname

PRINT #1, Users(j).Status

NEXT j

CLOSE #1

'Just for a closer: Prints all the current users.

CLS

FOR j = 1 TO i + 1

PRINT Users(j).Uname,

IF Users(j).Status = "a" THEN PRINT "Amdinistrator" ELSE IF Users(j).Status = "u" THEN PRINT "Unwanted User" ELSE IF Users(j).Status = "r" THEN PRINT "Regular user" ELSE PRINT Users(j).Status

NEXT j

END

'*** ERROR HANDLER: ***

FileNotExist:

OPEN "User.txt" FOR OUTPUT AS #1

CLOSE

RESUME

Similar questions