Results 1 to 11 of 11

Thread: OptionButton question

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56

    OptionButton question

    3 option buttons,
    a=10
    b=11
    c=12
    If I select a,
    the numbers (10) will show in a label.
    if b button,show "11"
    if c ,show "12"
    How can I do that?Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub opta_Click()
    2. Label1.Caption = "10"
    3. End Sub
    4.  
    5. Private Sub optb_Click()
    6. Label1.Caption = "11"
    7. End Sub
    8.  
    9. Private Sub optc_Click()
    10. Label1.Caption = "12"
    11. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56
    Thanks a lot.
    If I do not want write code in option button and use If statement,what can I do?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub Command1_Click()
    2. If opta.Value = True Then
    3.    Label1.Caption = "10"
    4. ElseIf optb.Value = True Then
    5.    Label1.Caption = "11"
    6. Else
    7.    Label1.Caption = "12"
    8. End If
    9. End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56
    Can you help me with the code I attach.
    The pizza Size does bot show,I do not know why.
    Last edited by shiyu; Oct 10th, 2002 at 02:30 PM.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Your zip file contains a .vbp (project file) and a .vbw (workspace file) but no form.

    Why not just make it easier, and post the code you have that isn't working.

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56
    ok

    Code:



    Option Explicit

    Const msngSmall As Single = 10.25
    Const msngMedium As Single = 15.75
    Const msngLarge As Single = 19.95
    Const msngTsmall As Single = 1.25
    Const msngTmedium As Single = 1.45
    Const msngTlarge As Single = 1.75
    Dim mcurSmall As Currency
    Dim mcurMedium As Currency
    Dim mcurLarge As Currency
    Dim mstrSize As String
    Dim mcurBasic As Currency
    Dim mcurTopping As Currency
    Dim intToppingcount As Integer
    Dim curPizzanumber As Currency
    Dim intPizza As Integer
    Dim mcurTotal As Currency
    Private Sub chkShowdate_Click()
    If chkShowdate.Value = 1 Then
    lblDate.Caption = Date
    Else
    lblDate.Caption = ""
    End If

    End Sub

    Private Sub cmdClear_Click()
    'Clear all

    optSmall.Value = False
    optMedium.Value = False
    optLarge.Value = False
    chkMushroom.Value = 0
    chkTomato.Value = 0
    chkPepperoni.Value = 0
    chkPepper.Value = 0
    chkOnion.Value = 0
    chkHam.Value = 0
    txtPizzanumber.Text = ""
    lblShowPizza.Caption = ""
    lblShowtopping.Caption = ""
    lblShowtotal.Caption = ""
    chkShowdate.Value = 0

    End Sub

    Private Sub cmdDisplay_Click()
    'display topping number
    'Select Pizza Size

    If optSmall.Value = True Then
    mcurBasic = msngSmall
    mstrSize = "Small"
    mcurTopping = msngTsmall
    lblShowPizza.Caption = "Small"
    ElseIf optMedium.Value = True Then
    mcurBasic = msngMedium
    mstrSize = "Medium"
    mcurTopping = msngTmedium
    Else
    optLarge.Value = True
    mcurBasic = msngLarge
    mstrSize = "Large"
    mcurTopping = msngTlarge
    End If


    If chkOnion.Value = 1 Then
    intToppingcount = intToppingcount + 0
    End If

    If chkHam.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If

    If chkOnion.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If

    If chkPepper.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If

    If chkPepperoni.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If

    If chkTomato.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If

    If chkMushroom.Value = 1 Then
    intToppingcount = intToppingcount + 1
    End If



    'Show topping number
    lblShowtopping.Caption = Val(intToppingcount)

    'Show Pizza Size Ordered

    lblShowPizza.Caption = Val(mstrSize)

    'Show Unit Cost

    lblUnit.Caption = FormatCurrency(mcurBasic)

    'get the price

    intPizza = Val(txtPizzanumber.Text)
    lblTotal.Caption = FormatCurrency(mcurTotal)
    mcurTotal = mcurBasic * intPizza + intToppingcount * mcurTopping

    End Sub

    Private Sub cmdExit_Click()
    'exit the program


    End Sub


    Private Sub Form_Load()
    'when form load

    optSmall.Value = False
    optMedium.Value = False
    optLarge.Value = False

    End Sub

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    What isn't working?

    The whole thing?

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56
    no,

    when I click the display button,"lblShowPizza" shows me"0".
    It should be show me Pizza Size"Small" "Medium" and "Large"
    VB Code:
    1. 'Select Pizza Size
    2.  
    3.   If optSmall.Value = True Then
    4.   mcurBasic = msngSmall
    5.   mstrSize = "Small"
    6.   mcurTopping = msngTsmall
    7.   lblShowPizza.Caption = "Small"
    8.   ElseIf optMedium.Value = True Then
    9.   mcurBasic = msngMedium
    10.   mstrSize = "Medium"
    11.   mcurTopping = msngTmedium
    12.   Else
    13.   optLarge.Value = True
    14.   mcurBasic = msngLarge
    15.   mstrSize = "Large"
    16.   mcurTopping = msngTlarge
    17.   End If

    is this code right?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    It looks right.

    Put a "Stop" right before this code executes, and, using F8, walk through the code. Move your mouse over the variables to see what they actually contain.

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    56
    Thanks a lot...I will check it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width