Thursday, August 26, 2010

Notes on Variables

object- button, text box
event- hover, click, type something in
properties- colour, text, size
variable- string variable is letters and/or numbers, integer variable is a whole number, decimal variable is number with some sort of decimals in it.
way to tell the programme its a variable is to enter: Dim *insert name of variable here* As *either String, Integer or Decimal*. Eg. Dim clock As Integer

HiLO Guessing Game









1) How many objects are referred to? What are they?
There's one variable, two text boxes and two buttons.
2) What is the name of the variable referred to?
secretnum
3) What are the three text options that appear in textbox1?
higher, lower and correct.
4) What do you think this code does?
You would enter a number in one of the text boxes and click a button but if the random number is higher, lower or if it's correct the other text box would tell you.
5) Well actually you should replace TextBox2 with a label and that means replacing TextBox2 in the code with Label1. This means that you can't enter something in the wrong textbox which is what I was doing which is why it wasn't working. In the original code I was entering a number where it shouldn't have been entered which is why you change it into a label because you can't enter a number in a label. The first button checks your answer and the second button resets it.

Wednesday, August 25, 2010

Simple Timer

Ohhh... once sir goes through it with us it makes so much sense. Anyways here is the code for a simple timer that counts in 0.1 seconds and also resets.

Make sure you put the Dim part right under public class (that's the first line).
For the timer have the Enabled property set as false to begin with and if you wanted to change it so it counts as seconds not 0.1 seconds you chage the interval to 1000 and the +0.1 to +1.
I used 2 buttons, 1 label, a timer and the variable clock.

Friday, August 20, 2010

Random Number Generator

The INT function returns the integer part of a specified number.
Rnd is used to return psuedo-random values. These values may look random but because they use complex mathematical formulas they technically aren't random as they are still predictable.
Each time the program is run the psuedo-random values returned by Rnd are always the same. To overcome this you use randomize to initialise VB's random number generator. To avoid generating the same sequence of psuedo-random values you call randomize before you call Rnd.
To change the different values it can choose from you change the highest and lowest values. In the following code the highest is 10 and the lowest is 1. This means that it can choose a value between 1 and 10. You put it after:  Handles Button1.Click






I've changed the code so that it can only choose between 1 and 3.


Wednesday, August 18, 2010

Variables

A variable is like a bucket with a whole heap of events in it.
Dim means 'remember this'.
Eg Dim myname As String. This means to remember myname as a string variable.
Eg. Dim number As Integer. This means to remember the number as an integer variable.
Eg. Dim point As Decimal. This menas to remember that decimal as a deciaml variable.
Note: Rnd ( ) generates a random number between 0 and 0.9999999

In the code of button one I put: number = Rnd ( )

Label1.Text = number
and this goes after Handles Button1.Click

In the code of button two I put: point = Rnd ( )
Label2.Text = point
this goes after Handles Button2.Click

In the code of button three I put myname = TextBox1.Text
Label3.Text = myname
this goes after Handles Button3.Click
Here is the finished product:

Thursday, August 12, 2010

Wednesday, August 11, 2010

Happy or Sad

Here is the finished product:

Here is the code I used to make this possible (I hope you can read it):
The faces are just pictures I got from the internet. I used 2 radio buttons for each picture. I changed the background because white is so boring.

Friday, August 6, 2010

Heads and Tails

The first white box you se is a label but in the text part of the properties I've put a whole heap of spaces and made sure the background colour is white. The second box is a button where the text has been changed to 'CHECK'. The final box is a text box where the user can type somehing in. I put the following code into the code of the button.
If TextBox1.Text = "heads" Then Label1.Text = "win"
If TextBox1.Text = "tails" Then Label1.Text = "lose"

The code above is an example of selection. If you misspell heads or tails or use a capital letter then the label will stay the same as the last one.

A solution to this problm would be to use radio buttons because the user wouldn't type in something wrong. To put the radio buttons in I put in the following code:
If Heads.Checked = "true" Then Label1.Text = "win"

If Tails.Checked = "true" Then Label1.Text = "lose"
A user friendly programme should always allow for user input errors.

Wednesday, August 4, 2010

Visual Basic

If you want to add something to your form click the tab on the left of the screen that says tools.
To change the properties of something you click it then in the bottom right corner there are a whole heap of things you can change.
If you want to view your form to see if it works then click the green play button found jus under the tab windows. To get back to the design mode you click the blue stop button where the play button was.
To change what the button does eg. hide picture, double click it and type insert file name of picture here. Visable=False. This means that when you click the button hide the picture will disappear. To make it show again do the same for the button show but type True instead of False. This also works for the radio button.
To insert a picture select picturebox, go to the property image and click the button with the dots in it. Then select local resource and import. To change the size of the image click the play type button in the corner and click stretch and then move the sides of the image to get it the right size.