Category Archives: 2. Software Development

An excercise in fustration

I thought long and hard about today’s task, I set out to make a task that appeared easy to complete but without the correct design would prove to be frustrating.
The task below has been broken down so you need to follow it from start to finish and constantly revisit “finished” parts of the program, this is the iterative nature of programming.

1. Design and create a program that
a. Stores 20 class marks before displaying them and displaying the average to one decimal place.
b. Change the design and program to validate the marks (between 1 & 100) using the supplied function.
c. Change the design and program to also store the names of the students and then display the output in a two column report.

I’ll post the (1c) solution up tomorrow after class, the code for the function is after the break.

Continue reading An excercise in fustration

DIM

DIM is used to dimensionalise a variable, that is set memory aside for the variable to be stored. It is used thus

  • DIM Number1 as Integer
  • DIM Number2 as Integer

However this can be shortened to

  • DIM Number1, Number2 as Integer

In this case VB(Express Edition) sets number1 & number2 to integers. A more complex example can be seen below

  • DIM StrName as String
  • DIM Number1, Number2 as Integer

Becomes

  • DIM StrName as String, Number1, Number2 as Integer

You need to be careful that you get your syntax correct. It might be easier at the start to stick with the traditional(top) method.

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)