Wednesday, August 4, 2010

answers to final 1

Sub Btn_Click(...)
    Dim T(3) aS Integer = { 1, 4, 6, 8}
    Mystery(T, 3)
End Sub

Sub NumbersInSequence(ByVal I as Integer, _
            ByVal J as Integer)
    For T = I to J
        lstBox.Items.Add(T)
    Next
End Sub

Sub PrintUntil7(ByVal A() As Integer)
    For Each x in A
        Debug.Print(x)
        if x = 7 then exit for
    Next
End Sub

Sub PrintUntil7(ByVal A() As Integer)
    For I = 0 to UBound(A)
        Debug.Print(A(I))
        if A(I) = 7 then exit for
    Next
End Sub

Sub PrintUntil7(ByVal A() As Integer)
    I = 0
    Do
        Debug.Print(A(I))
    While A(I) <> 7
End Sub

letter = txtBox.Text
Select Case letter.ToUpper
    Case "A"
        Debug.Print("apple")
    Case "B"
        Debug.Print("baseball")
    Case "C"
        Debug.Print("cow")
    Case "D"
        Debug.Print("debug")
End Select

Tuesday, August 3, 2010

latest tetris -- more functionality, but more bugs

Public Class Form1
    Dim board(9, 9) As Boolean
    Dim drawnBoard(9, 9) As PictureBox
    Dim sq As Square
    Sub undraw()
        For I = 0 To sq.data.GetUpperBound(0)
            For J = 0 To sq.data.GetUpperBound(1)
                If sq.data(I, J) = True Then
                    drawnBoard(sq.Y + I, sq.X + J).Visible = False
                End If
            Next
        Next
    End Sub
    Sub moveDown()
        If isOverLap(0, +1) Then Return
        undraw()
        sq.Y = sq.Y + 1
    End Sub
    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.Down Then
            moveDown()
        ElseIf e.KeyCode = Keys.Left Then
            If isOverLap(-1, 0) Then Return
            undraw()
            If sq.X <> 0 Then
                sq.X = sq.X - 1
            End If
        ElseIf e.KeyCode = Keys.Right Then
            If isOverLap(+1, 0) Then Return
            undraw()
            If sq.X + sq.data.GetUpperBound(1) <> 10 Then
                sq.X = sq.X + 1
            End If
        ElseIf e.KeyCode = Keys.Up Then
            undraw()
            sq.Rotate()
        End If
    End Sub

    Function isOverLap(ByVal XOffset As Integer, ByVal YOffset As Integer) As Boolean
        For I = 0 To sq.data.GetUpperBound(0)
            For J = 0 To sq.data.GetUpperBound(1)
                If sq.data(I, J) = True And board(I + sq.Y + YOffset, J + sq.X + XOffset) = True Then
                    Return True
                End If
            Next
        Next
        Return False
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pb As PictureBox
        For I = 0 To 9
            For J = 0 To 9
                pb = New PictureBox
                pb.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\box.png"
                pb.Location = New Point(J * 16, I * 16)
                pb.Size = New Point(16, 16)
                pb.SizeMode = PictureBoxSizeMode.StretchImage
                pb.Visible = False
                Controls.Add(pb)
                drawnBoard(I, J) = pb
            Next J
        Next I

        board(6, 3) = True
        drawnBoard(6, 3).Visible = True

        sq = New Square()

        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        ' draw the piece
        For I = 0 To sq.data.GetUpperBound(0)
            For J = 0 To sq.data.GetUpperBound(1)
                If sq.data(I, J) = True Then
                    drawnBoard(sq.Y + I, sq.X + J).Visible = True
                Else
                    drawnBoard(sq.Y + I, sq.X + J).Visible = False
                End If
            Next
        Next
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        moveDown()
    End Sub
End Class

Monday, August 2, 2010

Sample Tests

A midterm 2
A final
Another final
Another midterm 2

Tetris step 1

Public Class Form1
    Dim board(9, 9) As Boolean
    Dim drawnBoard(9, 9) As PictureBox
    Dim sq As Square
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pb As PictureBox
        For I = 0 To 9
            For J = 0 To 9
                pb = New PictureBox
                pb.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\box.png"
                pb.Location = New Point(J * 16, I * 16)
                pb.Size = New Point(16, 16)
                pb.SizeMode = PictureBoxSizeMode.StretchImage
                pb.Visible = False
                Controls.Add(pb)
                drawnBoard(I, J) = pb
            Next J
        Next I
        sq = New Square()
        sq.Construct()
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' draw the piece
        For I = 0 To sq.data.GetUpperBound(0)
            For J = 0 To sq.data.GetUpperBound(1)
                If sq.data(I, J) = True Then
                    drawnBoard(sq.Y + I, sq.X + J).Visible = True
                Else
                    drawnBoard(sq.Y + I, sq.X + J).Visible = False
                End If
            Next
        Next
    End Sub
End Class

Public Class Square
    Public data(1, 1) As Boolean
    Public X As Integer
    Public Y As Integer
    Public Sub Construct()
        data(0, 0) = True
        data(0, 1) = True
        data(1, 0) = True
        data(1, 1) = True
    End Sub
End Class

Thursday, July 29, 2010

Public Class Form1
    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As Byte(), ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Dim apples As New List(Of PictureBox)
    'Dim apple As PictureBox

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim txt As TextBox
        'For i = 0 To 9
        '    txt = New TextBox
        '    txt.BackColor = Color.AliceBlue
        '    txt.Location = New Point(100, i * 50)
        '    Me.Controls.Add(txt)
        '    txtboxes(i) = txt
        'Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        For Each apple In apples
            ' check if apple hit the ground
            If apple.Location.Y + apple.Size.Height >= theGround.Location.Y Then
                ' play a sound

                ' remove the item and penalize the player
                removeAnApple(apple)
                Label1.Text = Label1.Text - 500
                Exit For
            Else
                ' animate it
                apple.Location = New Point(apple.Location.X, apple.Location.Y + 4)
            End If
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PlaySound("C:\Users\Public\Music\Sample Music\Kalimba.mp3", 1, 0)

        addAnApple()
        Timer1.Enabled = True

    End Sub

    Sub removeAnApple(ByVal apple As PictureBox)
        Me.Controls.Remove(apple)
        apples.Remove(apple)
    End Sub


    Private Sub apple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        removeAnApple(sender)

        Label1.Text = Label1.Text + 100
        addAnApple()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        addAnApple()
    End Sub

    Sub addAnApple()
        Dim r As New Random

        Dim apple As PictureBox
        apple = New PictureBox
        ' Me.Width(-90)
        apple.Location = New Point(r.Next(0, Me.Width - 90), 12)
        apple.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\APPLE.jpg"
        apple.SizeMode = PictureBoxSizeMode.StretchImage
        apple.Size = New Point(90, 90)
        AddHandler apple.Click, AddressOf apple_Click

        Me.Controls.Add(apple)
        apples.Add(apple)
    End Sub
End Class

Wednesday, July 28, 2010

Public Class Form1
    Dim txtboxes(9) As TextBox
    Dim apple As PictureBox

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim txt As TextBox
        'For i = 0 To 9
        '    txt = New TextBox
        '    txt.BackColor = Color.AliceBlue
        '    txt.Location = New Point(100, i * 50)
        '    Me.Controls.Add(txt)
        '    txtboxes(i) = txt
        'Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' animate!
        If apple IsNot Nothing Then
            apple.Location = New Point(apple.Location.X, apple.Location.Y + 4)
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        addAnApple()
        Timer1.Enabled = True

    End Sub



    Private Sub apple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Controls.Remove(apple)
        apple = Nothing

        Label1.Text = Label1.Text + 100
        addAnApple()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        addAnApple()
    End Sub

    Sub addAnApple()
        Dim r As New Random

        apple = New PictureBox
        ' Me.Width(-90)
        apple.Location = New Point(r.Next(0, Me.Width - 90), 12)
        apple.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\APPLE.jpg"
        apple.SizeMode = PictureBoxSizeMode.StretchImage
        apple.Size = New Point(90, 90)
        AddHandler apple.Click, AddressOf apple_Click

        Me.Controls.Add(apple)
    End Sub
End Class

insertion sort

for pos = 0 to UBound(A)
    val = A(pos)
    for j = pos - 1 to 0 Step -1
        if val < A(j) then
            A(j+1) = A(j)
        else
            exit for
        endif
    next j
    A(j+1) = val
next pos

Tuesday, July 27, 2010

Public Class Form1
    Dim txtboxes(9) As TextBox
    Dim WithEvents apple As PictureBox

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim txt As TextBox
        For i = 0 To 9
            txt = New TextBox
            txt.BackColor = Color.AliceBlue
            txt.Location = New Point(100, i * 50)
            Me.Controls.Add(txt)
            txtboxes(i) = txt
        Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' animate!
        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 4)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        PictureBox1.Visible = False
        Label1.Text = Label1.Text + 100
    End Sub

    Private Sub apple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles apple.Click
        MessageBox.Show("hello")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        apple = New PictureBox
        apple.Location = New Point(284, 12)
        apple.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\APPLE.jpg"
        apple.SizeMode = PictureBoxSizeMode.StretchImage
        apple.Size = New Point(90, 90)


        Me.Controls.Add(apple)
    End Sub
End Class
Here is a link to the midterm with answers

Thursday, July 22, 2010

Programming Projects:
Implement a leap year function, which takes in
a year and returns a boolean whether the year is
a leap year or not

Also, isPrime, using the Sieve of Eratosthenes

Wednesday, July 14, 2010

http://docs.google.com/View?id=ajbqhgmq9qdz_29hk3xsndd

Thursday, July 1, 2010


 Exercise 1: compute the sum of two numbers supplied by the user, and display the result in a listbox:

Exercise 2: compute the sum and product of two numbers supplied by the user, and display the result in a listbox(Note: when you click button “Compute Product”, the product of the two numbers should be displayed in textbox “Product”, and nothing in “Sum:”, and vice versa, if you want to compute the sum, the result should be displayed in “Sum:”, but nothing in “Product” ):


Wednesday, June 30, 2010

Syllabus

Midterm, Final -- 30%, 40%
Lab (and homeworks) -- 30%

Book, at Amazon:
2005 edition
2008 edition
2010 edition

Tuesday, June 29, 2010

Sunday, May 23, 2010

Previous sample midterms with answers

It appears that these already had answers as part of it:
http://docs.google.com/View?id=ajbqhgmq9qdz_45dp8fffcz

http://docs.google.com/View?id=ajbqhgmq9qdz_46hcr87qck

Midterm 2 review

http://docs.google.com/View?id=ajbqhgmq9qdz_85fp9cjr9m

I will try to go through some of the sample midterms as well...

Midterm 1 review

http://docs.google.com/View?id=ajbqhgmq9qdz_79dcp4v5v5

Wednesday, May 5, 2010

Two sample midterms

not all the questions from these

http://docs.google.com/View?id=ajbqhgmq9qdz_45dp8fffcz

http://docs.google.com/View?id=ajbqhgmq9qdz_46hcr87qck

Monday, April 26, 2010

Final

scheduled for 5/24, C205, 4-6 PM

Friday, March 26, 2010

my email address

is joshwaxman at gmail dot com.

contact me if you need to know your grade

Thursday, March 25, 2010

Scores, and the curve

The curve is square root of the grade times 10. Here is a chart of grades:


total      m/c, of 15         part 2   part 3
27        5                      1          6
30        6                      0          6
34        5                      2          12
38        7                      0          10
41        7                      0          13
42        7                      0          14
42        6                      0          18
43        6                      7          12
44        8                      0          12
47        7                      1          18
47        9                      3          8
48        8                      0          16
49        7                      5          16
50        8                      1          17
52        6                      12        16
53        7                      7          18
54        9                      6          12
57        8                      7          18
58        7                      11        19
58        9                      3          19
59        10                    4          15
60        9                      8          16
61        10                    1          20
63        9                      11        16
63        8                      11        20
66        9                      20        10
66        11                    5          17
67        10                    10        17
67        11                    5          18
68        12                    10        10
70        10                    13        17
71        12                    7          16
72        8                      20        20
73        9                      17        20
77        10                    18        19
79        10                    19        20
82        11                    20        18
88        12                    20        20
92        13                    20        20

Summary statistics, pre-curve:
MAX 92
MIN 27
AVG 57.9
MEDIAN 58
MODE 42

Wednesday, March 24, 2010


some clarification of some answers, for the first sample test:
(6) The position of the lowercase letter L is as the third position in the string. But counting begins at 0, so it is 2.

(9) This is what Trim does. As discussed in the book, It takes a string, and strips out any leading and trailing spaces.

(10) The person who wrote this question made an error. Here is a trace. In the first line, x is 0. After the second line, x is 4. In the third line, x+=2 is the same as x=x+2, which is x=4+2, so x is 6. In the fourth line, while we modify x by something, we don't assign anything to it with the = operator, so x itself remains unchanged. Thus, x is still 6, not 18.

(12) The explanation for this one is the same as for question 6. The position of lowercase letter T is as the sixth position. But since counting begins at 0, that would be position 5.

(14) I suppose that (A) is really what was intended, and this is also acceptable. And this was likely what was intended. But one could also say (D), since the number would still remain as the Double data type.

Tuesday, March 23, 2010

Answers to the second sample exam:
m/ch
1) b
2) d
3) c
4) c, because of the clear
5) the person who wroye the question was looking for a
6) c
7) a
8) a
9) d
10) d. the two labels, the two textboxes, and the form.

pt 2

Private Sub Button1_Click() Handles Button1.Click
   Dim name as String
   name = InputBox("what is your name", "get name")
   If name > "carl" Then
      MessageBox.Show("your name comes after carl")
   ElseIf name < "carl" Then
      MessageBox.Show("your name comes before carl")
   Else
      MessageBox.Show("your name is carl!")
   EndIf
End Sub

pt 3 -- functions not on test
Answers to the first sample exam:
m/ch
1) B (but D also OK)
2) C
3) C
4) A
5) A
6) C
7) Not covered
8) Not covered
9) B
10) None of the above. The answer is 6
11) D
12) A
13) E
14) D
15) D

 part ii -- not covered

part iii --
1)
copy and paste this to Word -- not all columns are showing. You cannot see y and z.
Private Sub btnEval_Click(…) Handles btnEval.Click
x
y
z
     Dim x, y, z As Integer
0
0
0
     x = 4
4


     y = 2 + x + x

10

     z = y * x


40
     lstResult.Items.Clear()



     lstResult.Items.Add(z – y)



     lstResult.Items.Add(x + 2)



End Sub





2)
Hello

Wednesday, March 17, 2010

note to self

make up 3 m/ch questions on ifs

make up 3 programming problems on ifs

Monday, March 15, 2010

code from class

scheduled midterm 1,

this coming wednesday.
look at these exams:
Here and here

Wednesday, March 10, 2010

notes

Branching
Conditional Branching
Decision making

Comparison Operators
=
>
<
>=
<=
<>

Logical Operators
And
Or

we will resume with or operator

hw:
8 thru 30, even
8. is: (5 - a) * b < 7

Monday, March 8, 2010

read from a file
write it out to a textbox

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sw As IO.StreamWriter
        sw = IO.File.AppendText("c:\josh\josh3.txt")
        sw.WriteLine("hello there")

        sw.Close()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sr As IO.StreamReader
        sr = IO.File.OpenText("c:\josh\josh2.txt")
        TextBox1.Text = sr.ReadLine()
        Button1.Text = sr.ReadLine

        sr.Close()

    End Sub

3.5
60-66 even
'Each line triplet of DATA.TXT contains         DATA.TXT

70-76, even
The following steps calculate the amount of money earned in a walk-a-thon:

Wednesday, March 3, 2010

notes from class

input:
    textbox
    files
    s = inputbox("prompt")

output:
    debug.print
    listbox
    textbox
    file


format
formatcurrency
formatpercent
string.format
format string prior to outputting it

hw: 3.5: 32 - 36, even numbers

memory

some more code

Public Class Form1
    Dim x As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim x, y As Single
        x = 3.1
        y = 8
        ' Debug.Print(FormatNumber(x, 2))
        Debug.Print(String.Format("Your number, {0}, is {1}. Thanks for playing. Again, that number was {0,-15}.", FormatCurrency(x, 2), y))
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.ImageIndex = 1

    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

        Button12.ImageIndex = Button12.Tag
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Button6.Visible = False
    End Sub
End Class

Monday, March 1, 2010

another hw:
under strings, 3.4, even #s from 34 through 40, and 44

some code from class

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sentence As String
        sentence = "The rain in Spain falls mainly on the ground"
        Dim startpos, spacepos, wordlen As Integer
        startpos = 0
        spacepos = sentence.IndexOf(" ", startpos)
        wordlen = spacepos - startpos
        Debug.Print(sentence.Substring(startpos, wordlen))

        startpos = spacepos + 1
    End Sub
End Class

Monday, February 22, 2010

assignment: computer game

make an apple fall from a tree. if you click it before it falls off screen, then you win. otherwise, you do not win.

use pictureboxes and a timer to accomplish this.

Thursday, February 18, 2010

a homework

section 3.3
17-22
29, 30

Wednesday, February 3, 2010

Welcome to the Spring 2010 Semester

    Visual Basic.NET 2008
    qccs80.blogspot.com
    joshwaxman@gmail.com
    Syllabus to come

    2 Midterms, 1 Final
    25%, 25%, 30%
    HWs - 10%
    projects - 10%

    microsoft.com/express
    msdn academic alliance

    David I. Schneider
    Introduction to Programming    Using Visual Basic 2008
    http://books.google.com/


http://books.google.com/books?id=QesoYPIkLAAC&lpg=PP1&dq=Introduction%20to%20Programming%09Using%20Visual%20Basic%202008&pg=PA175#v=onepage&q=&f=false


create a new program
Label
Button
it will say "hello world"

HW: Goodnight moon program
2008 edition
# ISBN-10: 0136060722
# ISBN-13: 978-0136060727

2005 edition
ISBN 0130306541