A
Amy
Hi,
I have 6 If Then Else statements I was supposed to write. I did so but I
know that they have to be wrong because they all look the same. Could
someone take a look at them and point me in the right direction about what I
am not doing correctly?
1.. Write an If Then Else statement that displays the string "Pontiac" in
the CarMakeLabel control if the CarTextBox control contains the string
"Grand Am" (in any case).
(In this one I am trying to make "Gand Am" be true in any case so I used the
UCase to just change all of the letters to uppercase before comparing it. Is
that right?)
Dim strCar as String
strCar = UCase(Me.CarTextBox.Text)
If strCar = "Grand Am" Then
Me.CarMakelabel.Text = "Pontiac"
Else
Me.CarMakeLabel.Text = "Input Error"
End If
2.. Write an If. Then. Else statement that displays the string "Entry
Error" in the MessageLabel control if the intUnits variable contains a
number that is less than 0; otherwise, display the string "Valid Number".
(this one seems ok to me)
Dim intUnits as Integer
intUnits = Val(InputBox("Enter a number equal to or greater than 0",
"Number"))
If intUnits < 0 Then
Me.MessageLabel.Text = "Entry Error"
Else
Me.Messagelabel.Text = "Valid Number"
End If
3.. Write an If. Then. Else statement that displays the string "Reorder"
in the MessageLabel control if the sngPrice variable contains a number that
is less than 10; otherwise, display the string "OK".
(I would say that this one seems ok but the sng worries me a bit, isn't
that a floating point number? and the number 10 is a whole number. Do I need
to do some kind of calulation to change it?)
Dim sngPrice as Single
sngPrice = Val(InputBox("How many items are left on the shelf?", "Number"))
If sngPrice < 10 Then
Me.MessageLabel.Text = "Reorder"
Else
Me.MessageLabel.Text = "OK"
End If
4.. Write an If Then Else Statement that assigns the number 10 to the
sngBonus variable if the sngSales variable contains a number that is less
than or equal to $250; otherwise, assign the number 50.
(This looks ok??? Does the currency sign make a difference?)
Dim sngSales, sngBonus as Single
If sngSales <= 250 Then
sngBonus = 10
Else
sngBonus = 50
End If
5.. Write an If. Then.. Else statement that displays the number 25 in the
ShippingLabel control if the strState variable contains the string "Hawaii"
(in any case); otherwise display the number 50.
(I am a little confused about the comapring a string inany case. Does the
Ucase make that happen. So it does not matter how someone enters it. I just
make all of the letters uppercase and then see if they match?)
Dim strState as String
strState = Me.ShippingTextBoxl.Text
strState = UCase(strState)
If strState = "Hawaii" Then
Me.ShippingLabel.Text = "25"
Else
Me.ShippingLabel.Text = "50"
End If
I have 6 If Then Else statements I was supposed to write. I did so but I
know that they have to be wrong because they all look the same. Could
someone take a look at them and point me in the right direction about what I
am not doing correctly?
1.. Write an If Then Else statement that displays the string "Pontiac" in
the CarMakeLabel control if the CarTextBox control contains the string
"Grand Am" (in any case).
(In this one I am trying to make "Gand Am" be true in any case so I used the
UCase to just change all of the letters to uppercase before comparing it. Is
that right?)
Dim strCar as String
strCar = UCase(Me.CarTextBox.Text)
If strCar = "Grand Am" Then
Me.CarMakelabel.Text = "Pontiac"
Else
Me.CarMakeLabel.Text = "Input Error"
End If
2.. Write an If. Then. Else statement that displays the string "Entry
Error" in the MessageLabel control if the intUnits variable contains a
number that is less than 0; otherwise, display the string "Valid Number".
(this one seems ok to me)
Dim intUnits as Integer
intUnits = Val(InputBox("Enter a number equal to or greater than 0",
"Number"))
If intUnits < 0 Then
Me.MessageLabel.Text = "Entry Error"
Else
Me.Messagelabel.Text = "Valid Number"
End If
3.. Write an If. Then. Else statement that displays the string "Reorder"
in the MessageLabel control if the sngPrice variable contains a number that
is less than 10; otherwise, display the string "OK".
(I would say that this one seems ok but the sng worries me a bit, isn't
that a floating point number? and the number 10 is a whole number. Do I need
to do some kind of calulation to change it?)
Dim sngPrice as Single
sngPrice = Val(InputBox("How many items are left on the shelf?", "Number"))
If sngPrice < 10 Then
Me.MessageLabel.Text = "Reorder"
Else
Me.MessageLabel.Text = "OK"
End If
4.. Write an If Then Else Statement that assigns the number 10 to the
sngBonus variable if the sngSales variable contains a number that is less
than or equal to $250; otherwise, assign the number 50.
(This looks ok??? Does the currency sign make a difference?)
Dim sngSales, sngBonus as Single
If sngSales <= 250 Then
sngBonus = 10
Else
sngBonus = 50
End If
5.. Write an If. Then.. Else statement that displays the number 25 in the
ShippingLabel control if the strState variable contains the string "Hawaii"
(in any case); otherwise display the number 50.
(I am a little confused about the comapring a string inany case. Does the
Ucase make that happen. So it does not matter how someone enters it. I just
make all of the letters uppercase and then see if they match?)
Dim strState as String
strState = Me.ShippingTextBoxl.Text
strState = UCase(strState)
If strState = "Hawaii" Then
Me.ShippingLabel.Text = "25"
Else
Me.ShippingLabel.Text = "50"
End If