Last active
August 27, 2023 04:14
-
-
Save nicr9/60bb6ab8ac4c644c5820 to your computer and use it in GitHub Desktop.
Visual Basic Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Data Types | |
Integer ' Simple numbers | |
Double ' Numbers with decimal points | |
String ' Text (a string of characters) | |
Boolean ' True or False | |
' Create a variable | |
Dim ... as Double ' Put the name of your variable here | |
' Create an array | |
Dim quotes(10) As String | |
' Ask user for value | |
Console.Write("What is the value of x? ") | |
Dim x as Integer = Console.ReadLine() | |
' If...Else If...Else | |
If ... Then ' Put a condition in here | |
... | |
Else If ... Then ' Put a different condition in here (optional) | |
... | |
Else ' Code below will be executed only if the above conditions aren't met (optional) | |
... | |
End if | |
' While loop (when we don't know how many times we need to loop) | |
Do | |
... ' Put the code you want to repeat here | |
Loop While ... ' Put the exit condition here | |
' For loop (when we know exactly how many times we want to loop) | |
For i as Integer = 0 To 10 Step 1 ' i is a variable inside the loop that tells us which iteration we're on | |
... ' Put the code you want to repeat here | |
Next i ' This tells the loop to step i and repeat the loop | |
' Define a structure | |
Structure ... ' Name of structure goes here | |
Dim ... As ... ' Name of first field and field type go here | |
... ' Any other fields that you need follow the same pattern | |
End Structure | |
' Write to a file | |
My.Computer.FileSystem.WriteAllText(filename, text, append) ' first two args are String, last one is Boolean | |
' Exception handling, pulled from: https://msdn.microsoft.com/en-us/library/8a9f2ew0(v=vs.90).aspx | |
Try | |
' Starts a structured exception handler. | |
' Place executable statements that may generate | |
' an exception in this block. | |
Catch '[optional filters] | |
' This code runs if the statements listed in | |
' the Try block fail and the filter on the Catch statement is true. | |
'[Additional Catch blocks] | |
Finally | |
' This code always runs immediately before | |
' the Try statement exits. | |
End Try | |
' Ends a structured exception handler. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment