BASIC Programming/Beginning BASIC/User Input
Introduction[edit | edit source]
Read the Variables and Data Types article before reading this one.
User Input is one of the most important aspects of programming concepts. Every program should have some sort of user interaction, from getting a character's name for a game to asking for a password to log into a database. This article will teach the basics of user input in the BASIC Programming Language. Please note that the following code may vary from compiler to compiler. (FreeBASIC Users: Do not use line numbers).
Code[edit | edit source]
- you can copy it from here, hashtags do not do anything, it's a reminder.
Example 1 (qBasic)
CLS 10 PRINT "what is your name?" 20 INPUT "...(Enter Your Name)...", a$ 30 PRINT 40 PRINT "hello, "; a$; ", I am your computer, nice to meet you." 60 END
Example 2 (freeBasic)
10 Dim userInput As String 20 Input "What is your name?", userInput 30 Print 40 Print "Hello, " ; userInput ; "! I am your computer, it's nice to meet you." 50 Sleep 60 End
Explanation[edit | edit source]
What is your name? ...(Enter Your Name)... Hello, yourName, I am your computer, nice to meet you.
10: Dim userInput declares the variable userInput. As String tells the compiler that userInput is a string (A collection of pure text, can include numbers and symbols, but is considered text).
20: Input "What is your name?" prompts the user for their name. userInput OR a$ tells the compiler to store the answer in the variable in userInput or a$.
30: Makes a blank line.
40: A normal Print statement, ; tells the compiler not to skip to the next line.
50: Sleep makes the program wait for the user to press a key.
60: The ending to all BASIC programs, signifies a termination of the program.
|Previous: Variables and Data Types||Main: BASIC Programming||Next: Documentation|