Post by n00b on Jun 19, 2020 0:12:21 GMT -6
This is a new set of tutorials covering just the basics (pun was fully intended).
1. Setup RCBasic on Windows
Code From Tutorial:
2. Data Types
Code From Tutorial:
3. Variables
Code From Tutorial:
4. Input and Output
Code From Tutorial:
5. Functions Part 1
Code From Tutorial:
6. Functions Part 2
Code From Tutorial:
7. Flow Control Part 1
Code From Tutorial:
8. Flow Control Part 2
Code From Tutorial:
9. Loops
Code From Tutorial:
10. Arrays
Code From Tutorial:
11. Scope
Code From Tutorial:
12. Final Challenge - Applying what we have learned
Code From Tutorial:
1. Setup RCBasic on Windows
Code From Tutorial:
Print "Hello World"
2. Data Types
Code From Tutorial:
'NUMBERS
'Order of Operations
'1. Parenthesis
'2. Exponents
'3. Multiplication and Division
'4. Addition and Subtraction
Print "---NUMBERS---"
Print (5+3)*2^2
Print 5^2-3
Print 6/2+3*2
Print 6/(2+3)*2
Print ""
'STRINGS
Print "---STRINGS---"
Print "5"+"1"
Print "A String can hold any character"
3. Variables
Code From Tutorial:
'Dim myNumber
myNumber = 5*2
myNumber = myNumber + 5
Print myNumber
Dim myString$
myString$ = "hello world"
Print MyString + " how are you"
4. Input and Output
Code From Tutorial:
Dim user_input$
user_input$ = Input("Enter a number:")
user_input_number = Val(user_input$)
Print user_input_number + 5
5. Functions Part 1
Code From Tutorial:
Dim user_input$
Dim s$
s = "Enter your name:"
r$ = ReplaceSubstr("Something in a string", "i", "_")
user_input$ = Input(r)
'Sub Routine Test
Push_N(5)
'STR and VAL function test
user_input$ = Input("Enter a number:")
Print user_input$ + Str(5)
6. Functions Part 2
Code From Tutorial:
'Number Function
Function MyNumberFunction(a, b)
c = a + b
Return c
End Function
Print MyNumberFunction(3,4)
'String Function
Function MyStringFunction$(a, b$)
c$ = Str(a) + " " + b
Return c
End Function
Print MyStringFunction$(5.35, "this is a string")
'Sub Routine
Sub Tst(a$)
Print "Parameter A = " + a
End Sub
Tst("This")
'ByRef parameter
Sub MySub(ByRef a)
a = 5
End Sub
myVar = 0
7. Flow Control Part 1
Code From Tutorial:
'IF Statement
Print "What is 2+2?"
Print "A. 1"
Print "B. 3"
Print "C. 4"
Dim x$
x = Input$("Enter your choice: ")
If x = "a" Then
'DO THIS
Print "you are wrong"
ElseIf x = "b" Then
'DO THIS
Print "you are really wrong"
ElseIf x = "c" Then
'DO THIS
Print "You are correct"
Else
Print "You did not pick a available option"
End If
8. Flow Control Part 2
Code From Tutorial:
'IF Statement
Print "What is 2+2?"
Print "A. 1"
Print "B. 3"
Print "C. 4"
Dim x$
x = Input$("Enter your choice: ")
'BOOLEAN
'AND
'OR
'XOR
'NOT
If x = "a" OR x = "A" Then
'DO THIS
Print "you are wrong"
ElseIf x = "b" OR x = "B" Then
'DO THIS
Print "you are really wrong"
ElseIf x = "c" OR x = "C" Then
'DO THIS
Print "You are correct"
Else
Print "You did not pick a available option"
End If
9. Loops
Code From Tutorial:
'LOOPS
FOR I = 1 TO 10 STEP 2
PRINT I
NEXT
I = 1
WHILE I <= 10
PRINT I
I = I + 1
WEND
10. Arrays
Code From Tutorial:
Dim User_Input$
Dim User_Num
Print "Multiples"
User_Input$ = Input$("Enter a number: ")
User_Num = Val(User_Input$)
Dim N[11]
For i = 0 to 10
N[i] = User_Num * i
Next
Print ""
Print "Output Multiples"
For i = 0 to 10
Print User_Num;" x ";i;" = ";N[i]
Next
11. Scope
Code From Tutorial:
'A$ is in the main scope and will be accessible in
'all the scopes that derive from the main scope
A$ = "hello"
i = 0
For i = 1 to 3
For j = 1 to 3
Dim x
x = 17
Print A
Next
'If we try to Print x here is will fail to compile because x is not accessible within this scope
'Print x
Next
12. Final Challenge - Applying what we have learned
Code From Tutorial:
Dim Student_Name$[3]
Dim Student_Age[3]
Dim Student_Math_Grade[3]
Dim Student_History_Grade[3]
Dim Student_Science_Grade[3]
Print "Student Database (3 students)"
Print ""
'Remember arrays indexes start at 0 so an array with 3 indexes would
'be numbered 0 through 2
For i = 0 to 2
Student_Name$[i] = Input("Enter Student #" + Str(i) + " Name: ")
'Since Input$() returns a string we can just pass it directly to Val()
'to convert it to a number
Student_Age[i] = Val( Input("Enter Student #" + Str(i) + " Age: ") )
Student_Math_Grade[i] = Val( Input("Enter Student #" + Str(i) + " Math Grade: ") )
Student_History_Grade[i] = Val( Input("Enter Student #" + Str(i) + " History Grade: ") )
Student_Science_Grade[i] = Val( Input("Enter Student #" + Str(i) + " Science Grade: ") )
'Add a blank line to put space between this student and the next
Print ""
Next
'Create a SUB Routine that will output a students info from the array based on what
'number we pass to it
Sub ShowStudentInfo(n)
Print "Student Name: ";Student_Name$[n]
Print "Student Age: ";Student_Age[n]
Print "Student Math Grade: ";Student_Math_Grade[n]
Print "Student History Grade: ";Student_History_Grade[n]
Print "Student Science Grade: ";Student_Science_Grade[n]
End Sub
Dim User_Input$
User_Input$ = ""
'We will loop continuously while User_Input is not "q" and User_Input is not Q
While User_Input$ <> "q" AND User_Input$ <> "Q"
Print "Select an Option"
Print "0. Show Student #0 Info"
Print "1. Show Student #1 Info"
Print "2. Show Student #2 Info"
Print "Q to quit"
User_Input$ = Input("Enter your option: ")
'Blank Line for some space
Print ""
'Since User_Input$ is a string we have to compare it to a string rather than a raw number
If User_Input$ = "0" OR User_Input$ = "1" OR User_Input$ = "2" Then
'Convert User_Input to a number and pass it to the ShowStudentInfo SUB Routine we created
ShowStudentInfo( Val(User_Input$) )
'If something other than one of the options we provided is entered then output an error message
ElseIf User_Input$ <> "q" AND User_Input$ <> "Q" Then
Print "Please Select One of the Options Provided"
End If
'Output a blank line to add space
Print ""
Wend