Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----REMOVE BELOW THIS LINE-----
- if you got this from pastebin, you might wonder why it's not highlighted in a programming language syntax.
- that's because i didn't find BASIC there, there was just random shit like VB.NET, Basic4GL and VisualBasic which didn't work on this guide. It will work when you open this up in Notepad++, though.
- -----REMOVE ABOVE THIS LINE-----
- REM coded by newt
- REM not compatible with visual basic yet; for educational purposes only
- REM all codes below (except REM codes) are original and thought of in the brightest way possible
- REM they are all examples, so feel free to modify them in any manner if possible
- REM to display messages in seperate boxes:
- Private Sub Command1_click()
- MsgBox "My name is Newt"
- End Sub
- REM to close the program:
- Private Sub Command1_click()
- End
- End Sub
- REM to initialize a single variable when it is declared:
- Dim num As Integer = 12
- Dim str As String = "Newt"
- REM to declare multiple variables. each variable may be initialized in a seperate declaration line:
- Dim str1 As String = "Newt", x = 5 As Integer, y As Integer = 10
- REM to initialize the variable after the declaration has been done:
- Dim str1
- Str1 = "Newt"
- REM to change the value of the variable anytime during the program after initialization has already been done:
- Dim x As Integer = 10
- x = 20
- REM here, the variable x will have the value 4:
- Dim x As Integer
- x = 2 ^ 2 * 2 / 2
- REM here, the variable y will have the value 3:
- Dim y As Integer
- y = 9\2 + 1 - 2
- REM to display the current date the user's computer is displaying:
- Private Sub Command1_click()
- Print "Today is " & Date
- Print "The time is " & Time()
- End Sub
- REM to use string functions:
- Private Sub Command1_click()
- Dim nm As String
- nm = "My friend is Newt"
- Print "The total number of characters in his name are " & Len(nm)
- Print "The two characters from the middle of his name are " & Mid(nm, 6, 3)
- End Sub
- REM to add inputs in a text box:
- Private Sub Command1_click()
- Text3.Text = Val(Text1.Text) + Val(Text2.Text)
- End Sub
- REM to display only the OK button in a text box (message box):
- Private Sub Command1_click()
- MsgBox "Hello people," & " my name is Newt."
- End Sub
- REM to display only the OK and Cancel button in a text box:
- Private Sub Command1_click()
- x = MsgBox("Hello people", l, "WELCOME MESSAGE")
- End Sub
- REM to use the InputBox() function in a text box:
- Private Sub Command1_click()
- Dim n As Integer
- n = InputBox("Enter a number", "Accept number", 10)
- Print n
- End Sub
- REM code to calculate the area of a circle in a message box:
- Private Sub Command1_click()
- Dim AREA As Single
- AREA = 3.14 * Val(Text1.Text) * Val(Text1.Text)
- MsgBox "The area of the circle is " & AREA
- End Sub
- REM here we have a couple of codes which all represent a function or input used in list codes in basic:
- Private Sub Shift_click()
- List2.AddItem List1.Text
- List1.RemoveItem List1.ListIndex
- End Sub
- Private Sub Add_click()
- Dim CUISINE As String
- CUISINE = InputBox("Enter the name of the cuisine in List1")
- List1.AddItem CUISINE
- End Sub
- Private Sub Remove_click()
- List1.RemoveItem List1.ListIndex
- End Sub
- Private Sub Clear_click()
- List1.Clear
- End Sub
- REM codes to add two strings into a list:
- Private Sub Add_click()
- Dim fname, lname As String
- fname = InputBox("Enter the first name")
- lname = InputBox("Enter the last name")
- Combo1.AddItem fname
- Combo2.AddItem lname
- End Sub
- Private Sub Remove_click()
- Combo1.RemoveItem Combo1.ListIndex
- Combo2.RemoveItem Combo2.ListIndex
- End Sub
- Private Sub Concatenate_click()
- Text1.Text = Combo1.Text + " " + Combo2.Text
- End Sub
- Private Sub Clear_click()
- Combo1.Clear
- Combo2.Clear
- End Sub
- REM code without the END IF statement:
- Private Sub Calculate_click()
- If TxtAmount.Text > 10000 Then
- TxtDiscount.Text = TxtAmount.Text * 0.1
- End If
- End Sub
- REM using the END IF statement:
- Private Sub Calculate_click()
- If TxtAmount.Text > 10000 Then
- TxtDiscount.Text = TxtAmount.Text * 0.1
- Price = TxtAmount.Text - Discount
- MsgBox "The price is " & Price
- End If
- End Sub
- REM using IF, THEN, ELSE:
- Private Sub Command1_click()
- If TxtAmount.Text > 10000 Then
- TxtDiscount.Text = TxtAmount.Text * 0.1
- Else
- TxtDiscount.Text = TxtAmount.Text * 0.05
- End If
- End Sub
- REM using IF, THEN, ELSEIF
- Private Sub Command1_click()
- If TxtAmount.Text > 20000 Then
- TxtDiscount.Text = TxtAmount.Text * 0.15
- ElseIf TxtAmount.Text > 10000 Then
- TxtAmount.Text = TxtAmount.Text * 0.1
- ElseIf TxtAmount.Text > 5000 Then
- TxtAmount.Text = TxtAmount.Text * 0.05
- Else
- TxtAmount.Text = TxtAmount.Text * 0.02
- End If
- End Sub
- REM code for comparing two given numbers:
- Private Sub Calculate_click()
- Dim N1, N2 As Integer
- N1 = Text1.Text
- N2 = Text2.Text
- If N1 < N2 Then
- MsgBox N1 & " is smaller"
- ElseIf N2 < N1 Then
- MsgBox N2 & " is smaller"
- Else
- MsgBox " Both numbers are the same."
- End If
- End Sub
- REM code for formatting a given text:
- Private Sub Check1_click()
- If Check1.Value = 1 Then
- Text1.FontBold = True
- Else
- Text1.FontBold = False
- End If
- End Sub
- Private Sub Check3_click()
- If Check3.Value = 1 Then
- Text1.FontItalic = True
- Else
- Text1.FontItalic = False
- End If
- End Sub
- Private Sub Check2_click()
- If Check2.Value = 1 Then
- Text1.FontUnderline = True
- Else
- Text1.FontUnderline = False
- End If
- End Sub
- Private Sub Check4_click()
- If Check4.Value = 1 Then
- Text1.FontStrikethru = True
- Else
- Text1.FontStrikethru = False
- End If
- End Sub
- Private Sub check3_Change()
- If Check4.Value = 1 Then
- Text1.FontStrikethru = True
- Else
- Text1.FontStrikethru = False
- End If
- End Sub
- Private Sub check2 Click()
- If Check2.Value = 1 Then
- Text1.FontUnderline = True
- Else
- Text1.FontUnderline = False
- End If
- End Sub
- Private Sub check4 Change()
- If Check4.Value = 1 Then
- Text1.FontStrikethru = True
- Else
- Text1.FontStrikethru = False
- End If
- End Sub
- Private Sub Text2_change()
- End
- End Sub
- REM code for calculating and displaying a message for the addition of two numbers:
- Private Sub Command1_click()
- firstnum = Val(Text1.Text)
- secondnum = Val(Text2.Text)
- total = Val(Text3.Text)
- If total - firstnum + secondnum Then
- Label5.Caption = "Your answer is correct!"
- Else
- Label5.Caption = "Your answer is wrong"
- End If
- End Sub
- REM code for calculating the area of a rectangle and circle:
- Private Sub Command1_click()
- If Option1.Value = True Then
- Dim L, B, R, AREA As Integer
- L = InputBox("Enter the length")
- B = InputBox("Enter the length")
- AREA = L * B
- MsgBox "The area is " & AREA
- ElseIf Option2.Value = True Then
- Dim R, C, AREA As Integer
- R = InputBox("Enter the radius")
- AREA = 22.7 * R ^ 2
- MsgBox "The area is " & AREA
- End If
- End Sub
- REM to display results on a label using select case:
- Private Sub Form_load()
- Dim IntAge
- IntAge = InputBox("Enter a number from 4-20 and you will tell yourself what kind of a gamer you are!")
- Select Case IntAge
- Case 4
- Label1.Caption = "You: I don't even play games"
- Case 5
- Label1.Caption = "You: I know how to use the AWSD keys"
- Case 6
- Label1.Caption = "You: I play games on the medium difficulty"
- Case 7
- Label1.Caption = "You: I have a PlayStation 2, PC and more than 50 games"
- Case 8
- Label1.Caption = "You: I pawn other players online and I make them cry"
- Case 9
- Label1.Caption = "You: I have a PlayStation 2, PlayStation 3, Xbox One, Xbox 360, PC, Nintendo Wii, Nintendo DS 3D and more than 750 games"
- Case Else
- Label1.Caption = "You: I am as good a gamer as Newt!"
- End Select
- End Sub
- REM to display in which kind of school the user is in:
- Private Sub Form_load()
- Dim class
- class = InputBox("Enter the class you are in right now")
- Select Case class
- Case 1, 2, 3, 4, 5
- MsgBox "You are in Primary School"
- Case 6, 7, 8
- MsgBox "You are in Primary Secondary School"
- Case 9, 10
- MsgBox "You are in Senior School"
- Case 11, 12
- MsgBox "You are in Senior Secondary School"
- Case Else
- MsgBox "Wrong class! Enter a number between 1 and 12"
- End Select
- End Sub
- REM to find whether a given figure is a square:
- Private Sub Command1_click()
- Dim SIDE1, SIDE2, SIDE3, SIDE4 As Integer
- SIDE1 = InputBox("Enter the first side of the 4 sided figure")
- SIDE2 = InputBox("Enter the second side of the 4 sided figure")
- SIDE3 = InputBox("Enter the third side of the 4 sided figure")
- SIDE4 = InputBox("Enter the fourth side of the 4 sided figure")
- If SIDE1 = SIDE2 And SIDE1 = SIDE3 And SIDE1 = SIDE4 Then
- MsgBox "The figure is a square"
- Else
- MsgBox "The figure is not a square"
- End If
- End Sub
- REM to display text 5 times:
- Private Sub Command1_click()
- Dim VAR As Integer
- For VAR = 1 To 5 Step 1
- Print "I am Newt"
- Next VAR
- End Sub
- REM to display numbers from 1 to 10:
- Private Sub Command1_click()
- Dim x As Integer
- For x = 1 To 10
- Print x
- Next
- End Sub
- REM to display odd numbers from 1 to 10:
- Private Sub Command1_click()
- Dim x As Integer
- For x = 1 To 10 Step 2
- Print x
- Next
- End Sub
- REM to display the series of 5 in the same line:
- Private Sub Command1_click()
- For x = 5 To 50 Step 5
- Print x & Space$ (2);
- Next
- End Sub
- REM to display the sum of 5 numbers entered by the user:
- Private Sub Command1_click()
- Dim sum, num, I As Integer
- sum = 0
- For I = I To 5
- num = InputBox("Enter a number")
- sum = sum + num
- Next I
- Print "The sum of the five numbers is " & sum
- End Sub
- REM to print the series of 1 to 10 in reverse order:
- Private Sub Command1_click()
- Dim I As Integer
- For I = 10 To 1 Step -1
- Print I
- Next I
- Print "The program ends"
- End Sub
- REM to display text 5 times using DO LOOP:
- Private Sub Command1_click()
- Dim VAR As Integer
- VAR = 1
- Do
- Print "I am Newt"
- VAR = VAR + 1
- Loop While VAR <= 5
- End Sub
- REM to accept a name in a text box and print the following pattern:
- Private Sub Print_click()
- I = 1
- Do While I <= Len(Text1.Text)
- Print Left(Text1.Text, I)
- I = I + 1
- Loop
- End Sub
- REM to print the last three characters of the 5 names entered by the user in an input box:
- Private Sub Print_click()
- Dim str As String
- I = 0
- Do
- str = InputBox("Enter a name")
- Print Right(str, 3)
- I = I + 1
- Loop While I <= 5
- End Sub
- REM to accept a number and display the sum of the digits of the number:
- Private Sub Command1_click()
- Dim sum, num, l As Integer
- sum = 0
- num = Val(Text1.Text)
- Do
- l = num Mod 10
- sum = sum + 1
- num = Int(num / 10)
- Loop While num > 0
- MsgBox "The sum of the digits is " & "sum"
- End Sub
- REM to display the cube of a number till the user wants:
- Private Sub Display_click()
- Dim ans As String
- ans = "y"
- Do While ans = "y"
- n = InputBox("Enter a number")
- Print "The cube of "; " is " & n ^ S
- ans = InputBox("Do you wish to continue?")
- Loop
- End Sub
- REM to print *** in different rows and columns:
- Private Sub Display_click()
- Dim row, col As Integer
- For row = 1 To 3
- For col = 1 To 3
- Print "*"
- Next col
- Print
- Next row
- End Sub
- REM to print numbers in the form of a right angled triangle:
- Private Sub Command1_click()
- Dim row, col As Integer
- For row = 2 To 4
- For col = 1 To row
- Print col,
- Next col
- Next row
- End Sub
- REM to print numbers in a decreasing kind of order:
- Private Sub Command1_click()
- Dim row, col As Integer
- For row = 1 To 5
- For col = 5 To row Step -1
- Print col,
- Next col
- Print
- Next row
- End Sub
- REM to print numbers in the pattern i customized:
- Private Sub Command1_click()
- Dim row, col As Integer
- For row = 2 To 8 Step 2
- For col = 5 To row
- Print row,
- Next col
- Print
- Next row
- End Sub
- REM to accept a number and generate the next 5 consecutive numbers and to repeat the whole process till desired:
- Private Sub Command1_click()
- Dim and As String
- Dim no, * As Integer
- ans = "y"
- Do While ans = "y"
- no = InputBox("Enter a number")
- For I = 1 To 5
- Print no + I
- Next I
- ans = InputBox("Do you wish to continue?")
- Loop
- End Sub
- REM to show a form2 if you have multiple forms:
- Private Sub Form_load()
- Form2.Show
- End Sub
- REM to show multiple forms when the user has pressed a function key:
- Private Sub f1_click()
- Form1.Show
- End Sub
- Private Sub f2_click()
- Form2.Show
- End Sub
- Private Sub f3_click()
- Form3.Show
- End Sub
- Private Sub E1_click()
- End
- End Sub
- REM congratulations! you have finished newt's basic example guide!
- REM if you read through everything and used some of it - GREAT!
- REM if you just scrolled to the end - LOSER!
- REM copyright 2014 newt drost
- REM distributed by the newt productions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement