This program has an input box that prompts the user for a number and then generates 3 unique numbers between the given number and 1. A simple mistake that I made, typing in givenNum=InputBox(PROMPT, TITLE) twice, resulted in the input box popping up multiple times before finally generating the unique numbers. Argh.
Also, Juan taught me something pretty nifty regarding setting the maximum width of a label by going to the Properties bar in the designer window. That makes life much prettier.
Thursday, March 29, 2012
Tuesday, March 27, 2012
Phone Bill
I considered going with ElseIf statements but suspected it might not work, so I just used If Then statements.
Dim Charge As Decimal = 25
If Me.chkForward.Checked Then
Charge = 3.5 + Charge
End If
If Me.chkWaiting.Checked Then
Charge = 3.5 + Charge
End If
If Me.chkID.Checked Then
Charge = 3.5 + Charge
End If
Me.lblAnswer.Text = Charge
Tuesday, March 20, 2012
Rock Paper Scissors - using nested If then else
This really got me confused. The correct format is:
If Me.radRock.Checked And computerChoice = rock Then
Me.lblMessage.Text = "Computer throws rock. It's a draw! Cordial handshake."
Else
If Me.radPaper.Checked And computerChoice = rock Then
Me.lblMessage.Text = "Computer throws rock. You win! Computer sniffles."
Else
If Me.radScissors.Checked And computerChoice = rock Then
Me.lblMessage.Text = "Computer throws rock. Computer wins! Computer dances happily."
End If
End If
End If
I initially did not have the computerChoice defined on every line so it didn't work. Also, just using Else (without an If statement) would not work.
Thursday, March 15, 2012
Test Grade
I have yet to figure out how Visual Basic reads things in a predictable manner. For example, when I placed the list below (of Select Case) in reverse order, the program would only show me "D" for any number greater than 60. I had to switch the order with "A" on top and "F" on the bottom for it to work:
Dim Grade As Double
Grade = Val(Me.txtGrade.Text)
Select Case Grade
Case Is > 90
Me.lblMessage.Text = "A"
Case Is >= 80
Me.lblMessage.Text = "B"
Case Is >= 70
Me.lblMessage.Text = "C"
Case Is >= 60
Me.lblMessage.Text = "D"
Case Is < 60
Me.lblMessage.Text = "F"
End Select
Tuesday, March 13, 2012
Circle Area (with If Then Statements)
Syntax, once again, is very complicated. I originally wrote the text for the program to calculate circle area so that:
radius = Val(Me.txtRadius.Text)
If radius < 0 Then
Me.lblArea.Text = "Negative radii are illegal."
End If
area = PI * (radius ^ 2)
Me.lblArea.Text = area 'Shows answer of area of circle
This should have resulted in no answer displaying if the radius entered was negative. However, an answer still showed up when I pressed Debug, so I went back and rearranged things:
radius = Val(Me.txtRadius.Text)
area = PI * (radius ^ 2)
Me.lblArea.Text = area 'Shows answer of area of circle
If radius < 0 Then
Me.lblArea.Text = "Negative radii are illegal."
End If
Friday, March 9, 2012
Change/Time Conversion
I was finding it difficult initially to get the right operations to work for these two programs, especially with the Change program. I did the division out on a piece of paper, trying to figure out what information was needed for the remainder, etc.
Thursday, March 8, 2012
Energy
Yesterday, I discovered that "e" and "E" in VB are predefined numbers/operations (e=2.71) that can't be used as variables.
Tuesday, March 6, 2012
Temperature Converter Update
Today I managed to figure out how to make the temperature converter less clunky and more user-friendly. When the user clicks on Celsius from the drop down menu, for example, the label next to the text box will read: "Enter the temperature in Fahrenheit" and the label next to where the answer will be reads: "The temperature in Celsius is." The message changes depending on what is chosen from the menu. Clicking on the drop-down option also causes the appropriate button to light up.
After keying in the temperature to convert from, the user clicks on the lit-up button to see the appropriate temperature. The answer is cleared if new text is keyed in or a different temperature type is selected from the menu.
After keying in the temperature to convert from, the user clicks on the lit-up button to see the appropriate temperature. The answer is cleared if new text is keyed in or a different temperature type is selected from the menu.
Friday, March 2, 2012
Temperature Converter
The converter I currently have works, but is harder to use. To convert, you have to click on Celsius/Fahrenheit in the menu, then type in the number, then click on the appropriate temperature again in the menu.
Subscribe to:
Posts (Atom)