Wednesday, May 30, 2012

BookstoreOrderForm

 Today I found that to add items to a list at runtime, you use the following code:

lstItemsOrdered.Items.Add

LoanPayment & ComboBoxes

Today I found out that information that is entered in a combobox is actually treated as a string as opposed to the textbox format, where the property of text from a textbox can be treated as a Textbox.

GetPercentAmount(Me.cboRate.Text, rate, validData)


Sub GetDollarAmount(ByVal txtUserData As TextBox, ByRef dollars As Decimal, _
    ByRef isValid As Boolean)



Sub GetPercentAmount(ByVal cboUser As String, ByRef percent As Double, ByRef isValid _
    As Boolean)

Wednesday, May 23, 2012

PerfectSquare

First, a random thought:
The word "perfect" is one of such wonderfully rounded curves that seem to convey the meaning of itself - perfection.


I was trying to pursue perfection in this application that I created, and found it marred by errors instead.


First, I awkwardly forgot what an Int() function does. It rounds a number up to the nearest integer. 


Then I got my variables mixed up:
number was the user-entered number; numRt was the square root of that number

I originally wrote:

If Int(number) = numRt Then
            Return True
        End If

What happened, of course, is that only 1 returned a true statement (only the square root of 1 could possibly equal 1).


This below would return the correct answer.


If Int(numRt) = numRt Then
            Return True
        End If


This is my final code

  Dim num As String = Val(Me.txtNumber.Text)

        If PerfectSquare(num) = True Then
            Me.lblAnswer.Text = num & " is a perfect square."
        Else
            Me.lblAnswer.Text = num & " is not a perfect square."
        End If

    End Sub
Function PerfectSquare(ByVal number As Double) As Boolean

        Dim numRt As Double = Math.Sqrt(number)

        If Int(numRt) = numRt Then
            Return True
        End If

    End Function

    Private Sub txtNumber_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNumber.TextChanged
        Me.lblAnswer.Text = ""
    End Sub

Thursday, May 17, 2012

MetricConversion

This application involved entering a number and being able to convert between metric/customary units for various lengths.

I made a few errors while typing this program
The first one was that I treated a function like a procedure and typed:
finalNumber=(initialNum*2.54)
Return finalNumber

I changed this to:
 Return (initialNum * 2.54)
after Ms. Stark pointed out my error.

The second mistake I made was I predefined finalNumber as being equal to zero:
Dim finalNumber As Double

The third mistake I made was that I forgot to type in the tags. Oops.

Thursday, May 10, 2012

LetterGrade

This program returns a letter grade when a test score is entered.
The program that my modified version is based on uses A=90 or above, B=80 and above, etc. I changed it to display A+, A-, etc. by adding in additional ElseIf statements. I also had to change the Function's type from Char to String.


Function LetterGrade(ByVal score As Double) As String
        If score >= 97 Then
            Return "A+"
        ElseIf score >= 93 Then
            Return "A"
        ElseIf score >= 90 Then
            Return "A-"

Wednesday, May 9, 2012

Add Coins

I made a very simple mishap here. I used two equal signs and wrote total = (quart * 0.25) + (dime * 0.1) =  (nick * 0.05) + (penny * 0.01), instead of total = (quart * 0.25) + (dime * 0.1) + (nick * 0.05) + (penny * 0.01) with only one equal sign.

CD DVD Tips


This was the code I wrote originally:

Private Sub btnTip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTip.Click

        Call Message(Me.lblTip)

    End Sub

    'After button has been clicked, a random number will be chosen that represents one of the three tips
    'post: the tip will show up in the label
    Sub Message(ByRef lblMessage As Label)
        Randomize()
        Dim tipNumber As Integer
        tipNumber = Int(3 * Rnd()) + 1

        Select Case tipNumber
            Case 1
                lblMessage.Text = "Handle CD/DVDS by the center hole or by the edges."
            Case 2
                lblMessage.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
            Case 3
                lblMessage.Text = "Store discs in a jewel case or sleeve to prevent scratches."
        End Select

This is the updated version with parameters based on TestRndIntFunction

   Dim lowNum As Integer = 1
        Dim highNum As Integer = 3
        Dim chosenNum As Integer
        Call RndInt(lowNum, highNum, chosenNum)

        If chosenNum = 1 Then
            Me.lblTip.Text = "Handle CD/DVDS by the center hole or by the edges."
        ElseIf chosenNum = 2 Then
            Me.lblTip.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
        Else
            Me.lblTip.Text = "Store discs in a jewel case or sleeve to prevent scratches."
        End If

    End Sub

    'After button has been clicked, a random number will be chosen that represents one of the three tips
    'post: the tip will show up in the label
    Sub RndInt(ByVal firstNum As Integer, ByVal secondNum As Integer, ByRef thirdNum As Integer)
        Randomize()
        thirdNum = ((secondNum - firstNum + 1) * Rnd()) + firstNum