<?
If Ucase(strSeat) = "BOX"
        
lblPrice.Caption "$75.00"
    
Else
        If 
Ucase(strSeat) = "PAVILLION" Then
            lblPrice
.Caption "$30.00"
        
Else
            If 
Ucase(strSeat) = "LAWN" Then
                lblPrice
.Caption "$21.00"
            
Else
                
MsgBox ("Incorrect Seat Location")
                
lblPrice.Caption ""
            
End if
        
End If
    
End If
?>
<?
Dim strSeat 
As String
    strSeat 
txtSeat.Text

    Select 
Case Ucase(strSeat)
        Case 
"BOX"
            
lblPrice.Caption "$75.00"
        
Case "PAVILLION"
            
lblPrice.Caption "$30.00"
        
Case "LAWN"
            
lblPrice.Caption "$21.00"
        
Case Else
            
MsgBox ("Incorrect Seat Location")
            
lblPrice.Caption ""
    
End Select
?>
Visual Basic 6 Help!!! :P - TranceAddict Forums - Chill Out Room
return to tranceaddict TranceAddict Forums Archive > Main Forums > Chill Out Room

Pages: [1] 2 
Visual Basic 6 Help!!! :P
View this Thread in Original format
Starfox
Hello,

I rarely ask for help, but Im stuck. :P

can anyone help me out on this. It might be easy.

The price of a concert ticket depends on the seat location entered in a text box named txtSeat. Display the price in the lblPrice control. Use the chart below. (The seat location could be entered by the user in either uppercase or lowercase.) Assign the text box contents to the strSeat variable.

Seat Location.................Concert Ticket Price

Box...........................$75.00
Pavilion......................$30.00
Lawn..........................$21.00

(Any other seat location would result in an "Incorrect Seat Location" message.)

a. Write the visual basic code. Use If...Then...Else selection structure.

b. Write the visual basic code. Use the Case selection structure.


Thanks and Many Greetings,

f0x
escee
I havent programmed in vb in ages so ill just lay it in some structed english and you can work out the syntax (you can work out the syntax right? :) )

a)
If (seatLocation = Box)
lblPrice = $75.00
else if (seatLocation = Pavilion)
lblPrice = $30.00
else if (seatLocation = Lawn)
lblPrice = $21.00
else
lblPrice = You typed the location in wrong

b)

Case 1: seatLocation = Box
lblPrice = $75.00

Case 2: seatLocation = Pavilion
lblPrice = $30.00

Case 3: seatLocation = Lawn
lblPrice = $21.00

Case Default: lblPrice = You typed the location in wrong


if the spacing is ed up, its the forums fault not mine. Syntax is probably no where near of that of vb, ask me for it in java and it would be spot on! :) Hope that helps a bit.
Agent_WD40
Here ya go. For both make a form with a command button named cmdPrice, label named lblPrice, and text box named txtSeat and plug the code into the cmdPrice_Click() procedure.

a)

Dim strSeat As String
strSeat = txtSeat.Text

If strSeat = "Box" Or strSeat = "box" Then
lblPrice.Caption = "$75.00"
End If

If strSeat = "Pavilion" Or strSeat = "pavilion" Then
lblPrice.Caption = "$30.00"
End If

If strSeat = "Lawn" Or strSeat = "lawn" Then
lblPrice.Caption = "$21.00"
End If

If strSeat <> "Box" And strSeat <> "box" _
And strSeat <> "Pavilion" And strSeat <> "pavilion" _
And strSeat <> "Lawn" And strSeat <> "lawn" Then

MsgBox ("Incorrect Seat Location")
lblPrice.Caption = ""
End If

b)

Dim strSeat As String
strSeat = txtSeat.Text

Select Case strSeat
Case "Box"
lblPrice.Caption = "$75.00"
Case "box"
lblPrice.Caption = "$75.00"
Case "Pavilion"
lblPrice.Caption = "$30.00"
Case "pavilion"
lblPrice.Caption = "$30.00"
Case "Lawn"
lblPrice.Caption = "$21.00"
Case "lawn"
lblPrice.Caption = "$21.00"
Case Else
MsgBox ("Incorrect Seat Location")
lblPrice.Caption = ""
End Select

Hope that works for ya. Let me know if there's any problems.
Starfox
Hello Agent_WD40,

Many Thanks for this. I appreciate alot.

Thanks again,

Many Greetings,

f0x
JohnSmith
Yep, you are pretty much right, just one correction:

quote:
Originally posted by Agent_WD40
Here ya go. For both make a form with a command button named cmdPrice, label named lblPrice, and text box named txtSeat and plug the code into the cmdPrice_Click() procedure.

a)

Dim strSeat As String
strSeat = txtSeat.Text

If Ucase( strSeat [b])[\b] = "BOX"
lblPrice.Caption = "$75.00"
End If


if you use Ucase() you don't need the 2 conditions, and it will work for Box, BOX, or even bOx. those pesky users, you never know what they are going to type in! you can fix the rest of the if...thens like that too.

You can also do this to avoid the bottom part:

PHP:



b)

and you can do the same thing on the select case and cut the code in half:

PHP:



just a little more efficient, and it will also catch any combination of upper and lowercase letters.
Agent_WD40
Your right JohnSmith. I just typed those up real quick off the top of my head. Greetz.
Starfox
omG!
You guys rock.

would you mind helping me with another problem tomorrow?

thanks and many greetings,

f0x
JohnSmith
no problem dude! anything for you! i told you if you needed anything to ask! :D

i'm a programmer by trade, and am on the internet pretty much 24/7 so just pm me if you need help..

but anyway.. i'm off to bed now..
my girlfriend is pretty mad at me for neglecting her and spending time answering questions for people on the 'net!

i'm a web page programmer, and she's a waitress, and she is programming our website! lol.. anyway..

:) so , yeah, i'll see you tommorow! :)
JohnSmith
well, you never came back 'fox i was waiting for you.. oh well, cya later.
Starfox
to John:

can you help me with 2.

many thanks,

f0x

#1

-------------------

#2 - Done. Thanks Agent W40 =)

^^
done!

Agent_WD40
I couldn't resist :D Here's how I set up the form. I kept the names simple.

form name = frmMain

two cmmand buttons (I'm sure you can handle the exit button)
cmdRun, cmdPrint

six label controls lblOne, lblTwo and so on

plug this code in cmdRun_Click() event procedure

lblOne.Caption = Int((54 - 1 + 1) * Rnd + 1)
lblTwo.Caption = Int((54 - 1 + 1) * Rnd + 1)
lblThree.Caption = Int((54 - 1 + 1) * Rnd + 1)
lblFour.Caption = Int((54 - 1 + 1) * Rnd + 1)
lblFive.Caption = Int((54 - 1 + 1) * Rnd + 1)
lblSix.Caption = Int((54 - 1 + 1) * Rnd + 1)

and this in the cmdPrint_Click() event procedure

cmdPrint.Visible = False
cmdRun.Visible = False
cmdExit.Visible = False
frmMain.PrintForm
cmdPrint.Visible = True
cmdRun.Visible = True
cmbExit.Visible = True

Should be all good. Greetz
Starfox
Thanks again... Can you help me now with #1?

thanks,

f0x
CLICK TO RETURN TO TOP OF PAGE
Pages: [1] 2 
Privacy Statement