Answer to Question #173891 in Visual Basic for William

Question #173891

How to program a button to calculate pricing and adding to a list box:

my teacher was very vague on how to do this, we are using else/if statements to do this, my question is how would I go about adding information using radio buttons and pricing them and then adding them to the list box using Else/if statements


1
Expert's answer
2021-04-01T01:21:30-0400

Form1.Designer.vb file:


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form


    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub


    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer


    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.RadioButtonItemPrice10 = New System.Windows.Forms.RadioButton()
        Me.RadioButtonItemPrice15 = New System.Windows.Forms.RadioButton()
        Me.RadioButtonItemPrice20 = New System.Windows.Forms.RadioButton()
        Me.ListBoxPrices = New System.Windows.Forms.ListBox()
        Me.ButtonCalculate = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'RadioButtonItemPrice10
        '
        Me.RadioButtonItemPrice10.AutoSize = True
        Me.RadioButtonItemPrice10.Checked = True
        Me.RadioButtonItemPrice10.Location = New System.Drawing.Point(43, 46)
        Me.RadioButtonItemPrice10.Name = "RadioButtonItemPrice10"
        Me.RadioButtonItemPrice10.Size = New System.Drawing.Size(92, 17)
        Me.RadioButtonItemPrice10.TabIndex = 1
        Me.RadioButtonItemPrice10.TabStop = True
        Me.RadioButtonItemPrice10.Text = "Item price $10"
        Me.RadioButtonItemPrice10.UseVisualStyleBackColor = True
        '
        'RadioButtonItemPrice15
        '
        Me.RadioButtonItemPrice15.AutoSize = True
        Me.RadioButtonItemPrice15.Location = New System.Drawing.Point(43, 84)
        Me.RadioButtonItemPrice15.Name = "RadioButtonItemPrice15"
        Me.RadioButtonItemPrice15.Size = New System.Drawing.Size(92, 17)
        Me.RadioButtonItemPrice15.TabIndex = 2
        Me.RadioButtonItemPrice15.Text = "Item price $15"
        Me.RadioButtonItemPrice15.UseVisualStyleBackColor = True
        '
        'RadioButtonItemPrice20
        '
        Me.RadioButtonItemPrice20.AutoSize = True
        Me.RadioButtonItemPrice20.Location = New System.Drawing.Point(43, 123)
        Me.RadioButtonItemPrice20.Name = "RadioButtonItemPrice20"
        Me.RadioButtonItemPrice20.Size = New System.Drawing.Size(92, 17)
        Me.RadioButtonItemPrice20.TabIndex = 3
        Me.RadioButtonItemPrice20.Text = "Item price $20"
        Me.RadioButtonItemPrice20.UseVisualStyleBackColor = True
        '
        'ListBoxPrices
        '
        Me.ListBoxPrices.FormattingEnabled = True
        Me.ListBoxPrices.Location = New System.Drawing.Point(245, 46)
        Me.ListBoxPrices.Name = "ListBoxPrices"
        Me.ListBoxPrices.Size = New System.Drawing.Size(142, 95)
        Me.ListBoxPrices.TabIndex = 1
        '
        'ButtonCalculate
        '
        Me.ButtonCalculate.Location = New System.Drawing.Point(43, 176)
        Me.ButtonCalculate.Name = "ButtonCalculate"
        Me.ButtonCalculate.Size = New System.Drawing.Size(169, 23)
        Me.ButtonCalculate.TabIndex = 2
        Me.ButtonCalculate.Text = "Calculate"
        Me.ButtonCalculate.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(434, 235)
        Me.Controls.Add(Me.ButtonCalculate)
        Me.Controls.Add(Me.ListBoxPrices)
        Me.Controls.Add(Me.RadioButtonItemPrice20)
        Me.Controls.Add(Me.RadioButtonItemPrice15)
        Me.Controls.Add(Me.RadioButtonItemPrice10)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()


    End Sub
    Friend WithEvents RadioButtonItemPrice10 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButtonItemPrice15 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButtonItemPrice20 As System.Windows.Forms.RadioButton
    Friend WithEvents ListBoxPrices As System.Windows.Forms.ListBox
    Friend WithEvents ButtonCalculate As System.Windows.Forms.Button


End Class



Form1.vb file:

Public Class Form1
    ''' <summary>
    ''' Calculate Button
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ButtonCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalculate.Click


        Dim price As Double = 0
        'Select the price using the RadioButtons
        If RadioButtonItemPrice10.Checked Then
            price = 10
        End If
        If RadioButtonItemPrice15.Checked Then
            price = 15
        End If
        If RadioButtonItemPrice20.Checked Then
            price = 20
        End If
        'Add the price to listbox
        ListBoxPrices.Items.Add("Current price is " + price.ToString("C"))
    End Sub
End Class



Example:



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS