Category Archives: 6. External Sites

Select Case

The  Select..Case statement is a special instance of the IF  structure. To implement multi-way decisions the  statement provides a more concise and elegant representation than multiple and statements, which can get very difficult to follow. Probably if you have more than three conditional statements you should consider using the Select..Case statement instead.

Here is an example algorithm

  1. Ask user to input a number between 1 and 7
  2. select case number
  3. Case is = 1 Display “Sunday”
  4. Case is = 2 Display “Monday”
  5. Case is = 3 Display “Tuesday”
  6. Case is = 4 Display “Wednesday”
  7. Case is = 5 Display “Thursday”
  8. Case is = 6 Display “Friday”
  9. Case is = 7 Display “Saturday”
  10. Case else Display “Error”
  11. End Select

String Handling

Description and exemplification of the following constructs in pseudocode and an appropriate high level language: string operations (concatenation and substrings)

String and string handling are the bread and butter of all programs.  Today we looked at how the programmer can cut (substring) and paste (concatenation) strings together.

  • Len – Output is the length of the string
  • Ucase – Output is the string in upper case
  • Lcase – Output is the string in lower case
  • Asc – Output is the ASCII value of the character
  • Chr – Output is the ASCII character of the value
  • Mid$ – outputs the characters from anypoint in the string.
    • Mid$(String,First,HowMany)
  • Strings.Left – Outputs the leftmost characters in a string.
    • Strings.Left(String,HowMany)
  • Strings.Right – Outputs the rightmost characters in a string.
    • Strings.Right(String,HowMany)

Concatenation is a scary-looking word, but it simply means “joining together”.  String concatenation means joining two (or more) strings together to form one new string: String concatenation in VB is very simple – you don’t need a special function – you just use the + sign.

For example,

  • if string1 = “Fred”,
  • and string2 = “McSporran”,
  • then string1 + string2 = “FredMcSporran”.

Today’s “Impossible Task”

Create a program that displays the ASCii codes of all the characters of a string that is entered by the user, solution after the jump.

Continue reading String Handling

Simple Conditional Statements (IF)

A simple conditional statement is checks one condition. We use IF in VB, it is written as

  • IF <Condition> then
    • Do something
  • ELSE
    • Do something else
  • END IF

The Condition has to resolve to true or false and uses comparison operators (Comparitors). Try these tasks

  1. Says hello to people named Bob
  2. Tells you if a number is above 10
  3. Tells you which of two numbers is the biggest
  4. Tells you if a number is odd or even

Continue reading Simple Conditional Statements (IF)

Nested Fixed Loops

A nested fixed loop is a loop within a loop, that is iterated a fixed number of times.

This is written in pseudocode like this

  • For X = 1 to 10
    • For Y = 1 to 10
      • Display X & Y
    • Next Y
  • Next X

The program above will display

  • 1 1
  • 1 2
  • 1 3
  • ..
  • 2 1
  • 2 2
  • 2 3
  • ..
  • ..
  • 10 1
  • 10 2
  • 10 3
  • ..

Create the following programs

  1. Display a triangle of stars
  2. Display the first 10 times tables
  3. Display a number grid of the first 10 times tables

Continue reading Nested Fixed Loops