INPUT gets keyboard input from the user.
Syntax 1:INPUT Variable1, Variable2, ... Parameters:
Example:![]() DIM age PRINT "Age " INPUT age ' No prompt |
Syntax 2:INPUT "QuotedPrompt", Variable1, Variable2, ... Parameters:
Example:![]() DIM age INPUT "Age " , age ' "Prompt" comma variable |
Syntax 3:INPUT "QuotedPrompt"; Variable1, Variable2, ... Parameters:
Example:![]() DIM age INPUT "Age " ; age ' "Prompt" semicolon variable |
See also the LINE INPUT statement which allows keyboard input of text containing comma or quotation mark.
INPUT will input, from a file, lines of comma separated values into a parameter list of comma separated variables in a manner similar to the QBasic INPUT # function. The values in the file can be any of string, integer or floating point data types.
Syntax:INPUT #FileHandle, Variable1, Variable2, ... Parameters:
|
DIM P, N!, E#, L!, D$, j, random! OPEN "TEST.TXT" FOR OUTPUT AS #1 FOR j = 1 TO 10 random! = j * 100.0 * RND PRINT #1, j , ",", random!, ",", 12356789.012345#, ",", j + 10, ",", "This string has spaces" NEXT CLOSE #1 OPEN "TEST.TXT" FOR INPUT AS #1 WHILE NOT EOF(#1) INPUT #1, P, N, E, L, D PRINT P, " ", N, " ", E, " ", L, " ", D WEND CLOSE #1
See the FINPUT statement which also will input, from a file, lines of comma separated values.
INPUT returns an error code value to a BCX internal variable named SCANERROR.
INPUT without a prompt
DIM a!,b#,c$,d%,e$[10],f$ PRINT "Input 1.2,123456.78901234,string,12345,arraystring,this is a string" INPUT a!,b#,c$,d%,e$[5],f$ PRINT "single! ",a! PRINT "double# ",b# PRINT "string$ ",c$ PRINT "integer ",d% PRINT "array string ",e$[5] PRINT "string with spaces",f$
Result
single! 1.2 double# 123456.78901234 string$ string integer 12345 array arraystring sstring this is a string
INPUT with a prompt
INPUT "Input 1.2,123456.78901234,string,12345,arraystring,this is a string ",a!,b#,c$,d,e$[5],f$ PRINT "single! ",a! PRINT "double# ",b# PRINT "string$ ",c$ PRINT "integer ",d% PRINT "array string ",e$[5] PRINT "string with spaces ",f$
Result
single! 1.2 double# 123456.78901234 string$ string integer 12345 array arraystring sstring this is a string
CLS DIM a% DIM b! DIM c# INPUT "Type '1' then press ENTER ",a%, b!, c# ? "=====================" IF SCANERROR = -1 THEN PRINT "You did not enter enough data" ? "=====================" ? a% ? b! ? c# ? INPUT "Now Type '1,2,3,4' then press ENTER ",a%, b!, c# ? "=====================" IF SCANERROR = 1 THEN PRINT "You entered too much data" ? "=====================" ? a% ? b! ? c# INPUT "Finally, Type '1,2,3' then press ENTER ",a%, b!, c# ? "=====================" IF SCANERROR = 0 THEN PRINT "No data entry errors detected" ? "=====================" ? a% ? b! ? c#
Result
Type '1' then press ENTER 1 ===================== You did not enter enough data ===================== 1 0 0 Now Type '1,2,3,4' then press ENTER 1,2,3,4 ===================== You entered too much data ===================== 1 2 3 Finally, Type '1,2,3' then press ENTER 1,2,3 ===================== No data entry errors detected ===================== 1 2 3