some hints for assignments 2 and 3
assignment 2:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim degreeType As String
degreeType = TextBox1.Text
If degreeType = "Celsius" Then
' convert to other type
' output statement
Else
' convert to other type
' output statement
End If
End Sub
End Class
assignment 3:
see the spreadsheet on Blackboard for the strategy
Loops:
Be careful about infinite loops
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim answer As String
Do
answer = InputBox("Pete and Repeat were on a boat. Pete fell off. Who was left?", "Important question", "Repeat")
Loop While answer = "Repeat"
End Sub
End Class
Assignment 4:
HW: Modify the above to count how many times the person chose "Repeat". Output this somewhere at the end.
HW: Your program requires a password to get into it. That password is "swordfish". At the start of your program, prompt for the password and keep asking them until they finally say "swordfish".
Due date: Next Wednesday
Monday, September 20, 2010
Sunday, September 19, 2010
Don't forget!
Assignment #1 (with three parts) is due Monday night! Right now, only about 1/10 of the class has handed it in. In case it is because you don't know how to submit via BlackBoard, I'll demonstrate this in class on Monday.
Assignment #2 and #3 are due on Wednesday night. I'll be discussing a bit of strategy for assignment #3 (the rain in Spain) in class Monday, but if you can have something to discuss tomorrow with your lab instructor, you can get a jump on it.
Assignment #2 and #3 are due on Wednesday night. I'll be discussing a bit of strategy for assignment #3 (the rain in Spain) in class Monday, but if you can have something to discuss tomorrow with your lab instructor, you can get a jump on it.
Wednesday, September 15, 2010
notes for lecture #4
If conditionals
String data type
Methods
Calculate student's grade
* Midterm grade
* Final grade
* Bribe amount
Text property of a textbox has data type of String
Automatically, implicitly, Convert from one data type to another
CDbl
Option Strict On
Val
Option Strict On
Public Class Form1
Private Sub btnCalcGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcGrade.Click
' declare variables
Dim midtermGrade, finalGrade, bribe As Double
Dim semesterAvg As Double
' get input
midtermGrade = Val(txtMidterm.Text)
finalGrade = Val(txtFinal.Text)
bribe = Val(txtBribe.Text)
' processing
If bribe >= 50 Then
semesterAvg = 100
Else
semesterAvg = (midtermGrade + finalGrade) / 2
End If
' print out output
lblAverage.Text = CStr(semesterAvg)
End Sub
End Class
HW: convert from f to c, from c to f, based on an if and the value in a textbox
HW: Take the text "The rain in Spain falls mainly on the ground" and separate it into separate words. Print each word on a separate line in a ListBox.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = "hello"
s = s & " " & "world"
s = s.ToUpper()
s = s.Replace("WORLD", "EARTH")
Dim i As Integer
i = s.IndexOf("EARTH")
MessageBox.Show(i.ToString())
s = s.Substring(6, 5)
Button1.Text = s
End Sub
End Class
String data type
Methods
Calculate student's grade
* Midterm grade
* Final grade
* Bribe amount
Text property of a textbox has data type of String
Automatically, implicitly, Convert from one data type to another
CDbl
Option Strict On
Val
Option Strict On
Public Class Form1
Private Sub btnCalcGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcGrade.Click
' declare variables
Dim midtermGrade, finalGrade, bribe As Double
Dim semesterAvg As Double
' get input
midtermGrade = Val(txtMidterm.Text)
finalGrade = Val(txtFinal.Text)
bribe = Val(txtBribe.Text)
' processing
If bribe >= 50 Then
semesterAvg = 100
Else
semesterAvg = (midtermGrade + finalGrade) / 2
End If
' print out output
lblAverage.Text = CStr(semesterAvg)
End Sub
End Class
HW: convert from f to c, from c to f, based on an if and the value in a textbox
HW: Take the text "The rain in Spain falls mainly on the ground" and separate it into separate words. Print each word on a separate line in a ListBox.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = "hello"
s = s & " " & "world"
s = s.ToUpper()
s = s.Replace("WORLD", "EARTH")
Dim i As Integer
i = s.IndexOf("EARTH")
MessageBox.Show(i.ToString())
s = s.Substring(6, 5)
Button1.Text = s
End Sub
End Class
Monday, September 13, 2010
notes for lecture #3
1) Draw your GUI
2) Write your code
A bug
A syntax error causes build errors
A logic error
Runtime errors
Hello world program
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello, world!"
End Sub
End Class
Plato perfect age
Option Explicit On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim manAge As Integer
Dim wifeAge As Integer
' Get input
manAge = TextBox1.Text
' Processing
wifeAge = manAge / 2 + 7
' Display output
Label3.Text = wifeAge
End Sub
End Class
I'm naming controls (though not other variables) using "Hungarian"
camelCase
Apply a 10 point curve
Option Explicit On
Public Class Form1
Private Sub btnCalculateCurve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateCurve.Click
Dim grade As Integer
Dim curvedGrade As Integer
' Get input
grade = txtGrade.Text
' Processing
curvedGrade = grade + 10
' Display output
lblCurvedGrade.Text = curvedGrade
End Sub
End Class
2) Write your code
A bug
A syntax error causes build errors
A logic error
Runtime errors
Hello world program
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello, world!"
End Sub
End Class
Plato perfect age
Option Explicit On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim manAge As Integer
Dim wifeAge As Integer
' Get input
manAge = TextBox1.Text
' Processing
wifeAge = manAge / 2 + 7
' Display output
Label3.Text = wifeAge
End Sub
End Class
I'm naming controls (though not other variables) using "Hungarian"
camelCase
Apply a 10 point curve
Option Explicit On
Public Class Form1
Private Sub btnCalculateCurve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateCurve.Click
Dim grade As Integer
Dim curvedGrade As Integer
' Get input
grade = txtGrade.Text
' Processing
curvedGrade = grade + 10
' Display output
lblCurvedGrade.Text = curvedGrade
End Sub
End Class
Tuesday, September 7, 2010
Looking for a note-taker for this class
The Office of Special Services is requesting a volunteer to drop off a copy of their notes for CS80 once a week.
If you are interested, come to me, and I will give you a letter to bring to Kiely 171, so you can sign in with them and receive the note-taker guidelines. They will be pleased to give letters of recommendation for your assistance with this matter.
If you are interested, come to me, and I will give you a letter to bring to Kiely 171, so you can sign in with them and receive the note-taker guidelines. They will be pleased to give letters of recommendation for your assistance with this matter.
Some notes for lecture #2
syntax: the rules of the language. what is a verb, what is a noun, the order in which various words need to appear.
variable:
a "box" in memory with a name and a value. that value can change over time.
declaration:
Dim x as Integer
data types:
Integer, Long
String
Single, Double
Boolean
Initialization:
Dim x as Integer = 3
GUI: Graphical user interface
draw GUI, then VB code as the "codebehind"
asignment statement. use = operators. stuffs a value into a variable. does NOT establish a relationship, as if it were an equation.
variable:
a "box" in memory with a name and a value. that value can change over time.
declaration:
Dim x as Integer
data types:
Integer, Long
String
Single, Double
Boolean
Initialization:
Dim x as Integer = 3
GUI: Graphical user interface
draw GUI, then VB code as the "codebehind"
asignment statement. use = operators. stuffs a value into a variable. does NOT establish a relationship, as if it were an equation.
Thursday, September 2, 2010
Assignment 1
For each of these, make a VB program, complete with GUI.
1) Given speed and time, calculate distance and display it.
2) Given a temperature in Celsius, convert to Fahrenheit and display it.
3) Given a title, first name and last name, calculate and display it.
I haven't announced a due date for this homework yet.
Submit it via blackboard, once you have completed it.
1) Given speed and time, calculate distance and display it.
2) Given a temperature in Celsius, convert to Fahrenheit and display it.
3) Given a title, first name and last name, calculate and display it.
I haven't announced a due date for this homework yet.
Submit it via blackboard, once you have completed it.
Subscribe to:
Posts (Atom)