Jump to content

Ring/Lessons/Getting Input

From Wikibooks, open books for an open world

Getting Input

[edit | edit source]

We can get input from the keyboard using

  • The Give Command
  • The GetChar() Function
  • The Input() Function

Give Command

[edit | edit source]

Syntax:

	Give VariableName

Example:

	See "Enter the first number : " Give nNum1
	See "Enter the second number : " Give nNum2
	See "Sum : " + ( 0 + nNum1 + nNum2 )

Output:

	Enter the first number : 3
	Enter the second number : 4
	Sum : 7

GetChar() Function

[edit | edit source]

We can get one character from the standard input using the GetChar() function

Syntax:

	GetChar() ---> Character

Example:

	While True
		See "
			Main Menu
			(1) Say Hello
			(2) Exit
		    " 
		Option = GetChar()
		GetChar() GetChar()  # End of line

		# the previous two lines can be replaced with the next line
		# Give Option

		if Option = 1
			see "Enter your name : " give cName 
			see "Hello " + cName
		else
			bye
		ok
	End

Input() Function

[edit | edit source]

We can get input from the keyboard using the Input() function

Syntax:

	Input(nCount) ---> string

The function will wait until nCount characters (at least) are read

Example:

	See "Enter message (30 characters) : " cMsg = input(30)
	See "Message : " + cMsg