I haven't figured this out yet:
the original mess:
Dim numEntered As String
Dim numWords As Integer
Dim acronym As String
Dim wordEntered As String
Dim letter As String
Dim fullWord As String
numEntered = InputBox("Number of words", "Enter the number of words in the acronym")
numWords = Val(numEntered)
fullWord = Nothing
For count As Integer = 1 To numWords
wordEntered = InputBox("Word", "Enter the word.")
wordEntered.ToUpper()
letter = wordEntered.Chars(0)
letter = fullWord.Chars(count)
acronym = Nothing
acronym = String.Concat(acronym, letter)
Next count
Tuesday, May 1, 2012
Name Backwards
I made this one far too complicated.
I tried to split up the program to do the first name and last name separately. I also had the characters picked out one by one and... things just got really messy.
The new and improved code:
Dim origName As String = Me.txtName.Text
Dim lengthName As Double = origName.Length
Dim backName As String = Nothing
Dim currentLetter As String
For count As Integer = (lengthName - 1) To 0 Step -1
currentLetter = origName.Chars(count)
backName = String.Concat(backName, currentLetter)
Next count
Me.lblBackwards.Text = backName
Wednesday, April 11, 2012
Remove String
Today's mishap of the day:
Dim newSentence As Char
versus
Dim newSentence As String
That was all it took to make the program mess up. Head-shaking. The program's objective is to, given a sentence and a phrase to remove from that sentence, remove that phrase. For example, if you type "I dislike vegetables," and remove "dis," the new statement should read "I like vegetables." The error above meant only "I" showed up in the new statement.
Dim newSentence As Char
versus
Dim newSentence As String
That was all it took to make the program mess up. Head-shaking. The program's objective is to, given a sentence and a phrase to remove from that sentence, remove that phrase. For example, if you type "I dislike vegetables," and remove "dis," the new statement should read "I like vegetables." The error above meant only "I" showed up in the new statement.
Tuesday, April 10, 2012
CD Calculator
This calculates the number of years for an initial investment to accumulate (thanks to interest) to a certain amount based on given initial amount, final amount, and interest rate.
A few things I learned from this:
a) When setting up a counter, define an initial value for the counter.
years=0
years += 1
b) Argh! Use decimal format for interest rate. It's much more logical.
c) Check signs (ie greater than versus less than).
A few things I learned from this:
a) When setting up a counter, define an initial value for the counter.
years=0
years += 1
b) Argh! Use decimal format for interest rate. It's much more logical.
c) Check signs (ie greater than versus less than).
Thursday, March 29, 2012
Unique Random Numbers
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.
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.
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.
Subscribe to:
Posts (Atom)