Visual Basic Reference

 

Controls

            Forms

            PictureBox

            p.Image = Image.FromFile(“FileName.jpg”)

            Labels, Textbox, Listbox, etc

       txtOutput += “Hello”       ‘Adds the word hello to a textbox

       lstOutput.Items.Add(“Hello”)      ‘Adds the word hello to a listbox

Variables

                Dim varName as varitype

                String     -- holds text, numbers, letters, etc.

                Double   -- whole, fractional or mixed between about –1.8 * 10308 and 1.8 * 10308

                Integer   -- whole numbers between about -2 billion to 2 billion

                Boolean -- holds true or false

Expressions

                Level of precedence for arithmetic operations pg 82

                Parentheses – can change order

Built-in Functions (Math)

Strings

            Properties and Methods:

                                s.Length                                -- gets the length of a string

                                s.ToUpper()          -- converts a string to upper case

                                s.ToLower()          -- converts a string to lower case

                                s.Trim()                  -- removes white space (spaces, tabs) from the start and end

                                s.IndexOf(string2)                -- finds the position of string2 in string s,
                                                                -- returns –1 if not found

                                s.Substring(startPos)          -- returns text from s starting at position startPos

                                s.Substring(startPos,n)       -- returns n letters from s starting at startPos

                                s.StartsWith(string2)           -- returns true or false if s starts with string2

 

Chr and Asc

Procedures and Functions

Decisions

            If – Then – Else – End if

              ‘Find if string w1 contains string w2

              Dim w1 as String = “Now is the time for all good men”

              Dim w2 as String = “Time”

              Dim u_w1 as String = w1.ToUpper()

              Dim u_w2 as String = w2.ToUpper()

              Dim found as bool = false

              if (u_w1.IndexOf(u_w2) > 0) then

                     found = true

              end if

                                   

            Select Case Blocks

Repetition

            For Next Loops

       Dim I as Integer

       For I = 1 to 10 step 2

              lb.Items.Add(i)

       Next

            Do While Loops

Arrays

            Dim student(30) as String

            Dim score(30) as Double

Files

       ‘Open file and show lines and count number of lines

Dim sr as IO.StreamReader = IO.File.OpenText(“FILENAME.TXT”)

       Dim line as String

       Dim count as Integer

       Do While (sr.Peek <> -1)

              line = sr.ReadLine

              lb.Items.Add(line)

              count += 1

       Loop

       sr.Close()