Skip to content

Instantly share code, notes, and snippets.

@febritecno
Forked from nicr9/notes.vb
Last active March 5, 2024 20:15
Show Gist options
  • Save febritecno/e0de2e56d3f573b1bbdd0ab1bd701a6d to your computer and use it in GitHub Desktop.
Save febritecno/e0de2e56d3f573b1bbdd0ab1bd701a6d to your computer and use it in GitHub Desktop.
Visual Basic Cheat Sheet
http://howtostartprogramming.com/vb-net/
' 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