If, then, and elseif statement question.

Hello,

I am taking my first Visual Basic .NET programming class and I've run into a bit of a problem on my second programming project. Basically what I'm dealing with is two groups of radio buttons, and the status of these radio buttons determines the text that is displayed in a message label.

Individually they pose no problem to me, but I am somehow supposed to concatenate these two groups of radio buttons together in the same message label. The first group of radio buttons are "Charge", "COD", and "Money Order". The second group is "Express" and "Ground". Say that the "Charge" and "Ground" radio buttons are checked, then the message label should read "You have selected ground shipping and a charge payment."

Any idea on what the code should look like on this? I know that it will be an "if" statement, but I'm not sure exactly how to code it. Any help would be greatly appreciated.

Jason

Comments

  • [b][red]This message was edited by leekeng81 at 2004-10-31 11:15:50[/red][/b][hr]
    It's not difficult actually... so I just take your example to do...

    Assume your radio button "Charge" named as optCharge.
    Assume your radio button "Ground" named as optGround.
    Assume your message label named as lblDisplay.

    [code]
    If optCharge.Value = True And optGround.Value = True Then
    lblDisplay.Caption = "You have selected ground shipping and a charge payment"
    ElseIf optCOD.Value = True And optExpress.value = True Then
    lblDisplay.Caption = "You have selected COD and Express."
    End If

    [/code]

    Note: That's one of the ways... and not flexible enough. It's better if you use String and combine both together which I showed below..

    [code]
    Dim strGroup1 as String
    Dim StrGroup2 as String

    If optCharge.Value = True Then
    strGroup1 = "charge payment"
    End If

    If optGround.Value = True Then
    strGroup2 = "ground shipping"
    End If

    lblDisplay.Caption = "You have selected " & strGroup2 & " and a " & strGroup1 & "."
    [/code]



  • : [b][red]This message was edited by leekeng81 at 2004-10-31 11:15:50[/red][/b][hr]
    : It's not difficult actually... so I just take your example to do...
    :
    : Assume your radio button "Charge" named as optCharge.
    : Assume your radio button "Ground" named as optGround.
    : Assume your message label named as lblDisplay.
    :
    : [code]
    : If optCharge.Value = True And optGround.Value = True Then
    : lblDisplay.Caption = "You have selected ground shipping and a charge payment"
    : ElseIf optCOD.Value = True And optExpress.value = True Then
    : lblDisplay.Caption = "You have selected COD and Express."
    : End If
    :
    : [/code]
    :
    : Note: That's one of the ways... and not flexible enough. It's better if you use String and combine both together which I showed below..
    :
    : [code]
    : Dim strGroup1 as String
    : Dim StrGroup2 as String
    :
    : If optCharge.Value = True Then
    : strGroup1 = "charge payment"
    : End If
    :
    : If optGround.Value = True Then
    : strGroup2 = "ground shipping"
    : End If
    :
    : lblDisplay.Caption = "You have selected " & strGroup2 & " and a " & strGroup1 & "."
    : [/code]
    :
    :
    :
    :
    [red]#############################################################[/red]

    The cool thing about programming that there is no one way of doing things. Might I offer this suggestion:
    [code]
    Dim strPay as String
    Dim strShip as String

    If optCharge.Value = True Then
    strPay = "charge"
    ElseIf optCOD.Value = True Then
    strPay = "COD"
    ElseIf optMoneyOrder.Value = True Then
    strPay = "money order"
    End If

    If optGround.Value = True Then
    strShip = "ground"
    ElseIf optExpress.Value = True Then
    strShip = "express"
    End If

    lblDisplay.Caption = "You have selected " & strShip & " shipping and a " & strPay & " payment."[/code]

  • Ive got an even better suggestion stay away from .NET :P
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories