VB.NET Cheat Sheet By: Andrew Kiceniuk s1

VB.NET Cheat Sheet By: Andrew Kiceniuk s1

<p>VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 1: Computer Memory Computer Memory: Computers have two types of memory: </p><p>1. Permanent  ex: your hard drive  info stay on your computer even after the power is turned off.</p><p>2. Temporary  RAM (Random Access Memory)  this is the computers working memory, it allows programs to run, but all info saved in the RAM is lost when the computer’s power is turned off.</p><p>You can think of the computer’s RAM as being a collection of storage boxes. Sometimes your programs will need to save information to the computer’s RAM. That would be like putting the information into the storage box. Ex: 5 </p><p>Sometimes your programs will need to use information from the computer’s RAM. That would be like taking information out of the storage box. Ex: 5</p><p>These storage boxes are called memory locations. When we give a memory location a unique name we call it a variable.</p><p>Working With Variables: Working with a memory location involves three steps: 1) Declaring a variable (i.e. naming the memory location) 2) Initializing the variable (i.e. putting a value in the memory location) 3) Using the variable a. To complete of a calculation or b. To output an answer to a label</p><p>Let us look at each step: 1) Declaring a variable – requires a statement that has three parts: intNumberOfFeet</p><p>Statement Format: Dim preVariableName As DataType Declaration Example: Dim intNumberOfFeet As Integer</p><p>Dim - is a keyword to indicate that you want to name a memory location. VariableName – is the name you are giving the memory location. Is should be descriptive of the value to be saved in the memory location. - Notice that the variable name starts with a 3 letter, lowercase, prefix that describes the data type that the variable will hold. Data Type – This tells the computer what type of values will be saved into the memory location. The basic data types we will work with are: VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 1: Computer Memory Data Type Value Held 3 Letter Prefix String “Text” str Integer numbers without decimals int Double numbers with decimals dbl Boolean True, 1, False, 0 bln Char A single keyboard chr character VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 1: Computer Memory </p><p>2) Initializing a variable You can save a value to a memory location by using an assignment statement (as in you are assigning a value to the variable.) intNumberOfFeet</p><p>Statement Format: preVariableName = value Assignment Example: intNumberOfFeet = 5</p><p>You specify the variable name followed by the assignment operator (i.e. =), then the value. The value must match the data type specified in the variable declaration.</p><p>3) Using the variable You use variables either to:</p><p>1) complete a calculation Example: dblAnswer = intNumberOfFeet * 2.50 Computer reads it as: dblAnswer = 5* 2.50</p><p>2) display in a label Example: Me.lblAnswer.Text = dblAnswer Label displays: 12.50</p><p>When Do You Use Variables? There are two situations: 1.) To complete calculations – the result of a math calculation should be saved in a variable. Example: dblAnswer = intNumberOfFeet * 2.50</p><p>2.) To accept user input – whenever you have a TextBox on your form you will need a variable to save the value the user enters into it.</p><p>How to handle text input from a TextBox:</p><p>Statement Format: preVariableName = Me.TextBoxName.Text Example: strHomeTown = Me.txtHomeTown.Text</p><p>How to handle numeric input from a TextBox:</p><p>Statement Format: preVariableName = Val(Me.TextBoxName.Text) Example: intAge = Val(Me.txtPetsAge.Text)</p><p>Note: Everything entered into a TextBox is actually text. For example: The user input in the Kraken Kafe program is not recognized as a number, but rather as text (i.e. “25”). VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 1: Computer Memory </p><p>We need to use the Val( ) method to convert the text value (“25”) into a numeric value (25).</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us