Answers to Comparing Strings Using LCase() Function Exercise

 To avoid problems with inconsistent case we should use the ToUpper( ) or ToLower( )  method or Ucase( )  or Lcase( )  functions.

 The LCase( )  and UCase( ) functions convert the string passed to them to all lowercase or all uppercase respectively.

The ToUpper( ) or ToLower( )  methods do the same thing.

What would the result be if the user entered the following strings in the txtState textbox?

txtState.Text

strState

Output

1)    Oregon

oregon

Shipping Charge = $30

2)   California

california

Shipping Charge = $32.50

3)   Illinois

illinois

Incorrect State

4)   california

california

Shipping Charge = $32.50

 

Note: contents of strState is always in all lowercase. Comparison is to all lowercase string constants.

 
 

   Dim strState As String

   strState = txtState.Text.ToLower

  

   If strState = "hawaii" Then

        msgBox("Shipping Charge = $25")

   ElseIf strState = "oregon" Then

        msgBox("Shipping Charge = $30")

   ElseIf strState = "california" Then

        msgBox("Shipping Charge = $32.50")

   Else

        msgBox("Incorrect State")

   End If