radio buttons and listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bflyrose
    New Member
    • Feb 2007
    • 7

    radio buttons and listbox

    Hi I need some help I am trying to connect my radio buttons to show prices in the listbox with the name of the movie selected this is what I have so far
    my problem is I don't know how to get the selected radio button to output to the listbox or the name of selected movie to also display I have tried if statements included in my with statement doesn't work I set up my radiobutton control all in one event (6 of them and they are already working to display prices in my label but I am stumped on how to output to listbox


    Code:
    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
            Dim strTotal As String
            Dim strDisTotal As String
    
            Dim strFormat As String = "{0:C}" & ControlChars.Tab & "{1:N}"
            Dim strLine As String = "-"
    
    
    
            decSubTotal = Reg_Price * City_Tax
    
            decTotal = decSubTotal + Reg_Price
            decSubDisTotal = Discount_Price * City_Tax
    
            decDisTotal = decSubDisTotal + Discount_Price
            decReg = Reg_Price
            decTax = City_Tax
            decDis = Discount_Price
            
    
            With lstTransHistory
                lstTransHistory.Items.Clear()
                strTotal = (decTotal + Reg_Price).ToString("c")
                strDisTotal = (decDisTotal + Discount_Price).ToString("c")
                lstTransHistory.Items.Add(String.Format(strFormat, "Movie", "Quantity", "Price"))
                lstTransHistory.Items.Add("-----------------------------------------------------")
    
                lstTransHistory.Items.Add(String.Format(strFormat, "Total", (strTotal)))
                If radOne.Checked Then
                    lstTransHistory.Items.Add("The Butterfly Effect")
    
                End If
    
    
            End With
            
    
        End Sub
    
     Private Sub frmEverettTheater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'displays main picture 
    
            Image1 = Image.FromFile("mm.jpg")
            lblPic.Image = Image1
    
    
            'opens and displays movie title choices
            Dim movie(9) As String
            Dim price(9) As String
            Dim sr As IO.StreamReader = IO.File.OpenText("Movies.txt")
            Dim arrMovie As Integer = 0
            Do While (sr.Peek() <> -1)
                movie(arrMovie) = sr.ReadLine
                price(arrMovie) = sr.ReadLine
                cboMovie.Items.Add(movie(arrMovie))
                arrMovie = arrMovie + 1
                
            Loop
            sr.Close()
    
            'displays current system date
            lblDate.Text = DateTime.Now.ToLongDateString
    
        End Sub
    
    
     Private Sub radOne_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radOne.CheckedChanged, radTwo.CheckedChanged, _
        radThree.CheckedChanged, _
        radFour.CheckedChanged, _
        radFive.CheckedChanged, _
        radSix.CheckedChanged
           
    
            'calculations
            decSubTotal = Reg_Price * City_Tax
            decTotal = decSubTotal + Reg_Price
            decSubDisTotal = Discount_Price * City_Tax
            decDisTotal = decSubDisTotal + Discount_Price
    
            ' calculate and output to label total + tax and amount of tickets wanted
    
            If (radOne.Checked) Then
                lblCalculate.Text = decTotal.ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = decDisTotal.ToString("c")
    
            End If
            If (radTwo.Checked) Then
                lblCalculate.Text = (decTotal * 2).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 2).ToString("c")
            End If
            If (radThree.Checked) Then
                lblCalculate.Text = (decTotal * 3).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 3).ToString("c")
    
            End If
            If (radFour.Checked) Then
                lblCalculate.Text = (decTotal * 4).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 4).ToString("c")
    
            End If
            If (radFive.Checked) Then
                lblCalculate.Text = (decTotal * 5).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 5).ToString("c")
    
            End If
            If (radSix.Checked) Then
                lblCalculate.Text = (decTotal * 6).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 6).ToString("c")
    
            End If

    I have declared global constants so they will function in all my controls

    I am really so confused right now and its probably something very easily done but can't untwist it any help would be much appreciated
    Last edited by Killer42; Mar 14 '07, 01:55 AM. Reason: Please use CODE.../CODE tags around your code.
  • bflyrose
    New Member
    • Feb 2007
    • 7

    #2
    [QUOTE=bflyrose]Hi I need some help I am trying to connect my radio buttons to show prices in the listbox with the name of the movie selected this is what I have so far
    my problem is I don't know how to get the selected radio button to output to the listbox or the name of selected movie to also display I have tried if statements included in my with statement doesn't work I set up my radiobutton control all in one event (6 of them and they are already working to display prices in my label but I am stumped on how to output to listbox


    Code:
    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
            Dim strTotal As String
            Dim strDisTotal As String
    
            Dim strFormat As String = "{0:C}" & ControlChars.Tab & "{1:N}"
            Dim strLine As String = "-"
    
    
    
            decSubTotal = Reg_Price * City_Tax
    
            decTotal = decSubTotal + Reg_Price
            decSubDisTotal = Discount_Price * City_Tax
    
            decDisTotal = decSubDisTotal + Discount_Price
            decReg = Reg_Price
            decTax = City_Tax
            decDis = Discount_Price
            
    
            With lstTransHistory
                lstTransHistory.Items.Clear()
                strTotal = (decTotal + Reg_Price).ToString("c")
                strDisTotal = (decDisTotal + Discount_Price).ToString("c")
                lstTransHistory.Items.Add(String.Format(strFormat, "Movie", "Quantity", "Price"))
                lstTransHistory.Items.Add("-----------------------------------------------------")
    
                lstTransHistory.Items.Add(String.Format(strFormat, "Total", (strTotal)))
                If radOne.Checked Then
                    lstTransHistory.Items.Add("The Butterfly Effect")
    
                End If
    
    
            End With
            
    
        End Sub
    
     Private Sub frmEverettTheater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'displays main picture 
    
            Image1 = Image.FromFile("mm.jpg")
            lblPic.Image = Image1
    
    
            'opens and displays movie title choices
            Dim movie(9) As String
            Dim price(9) As String
            Dim sr As IO.StreamReader = IO.File.OpenText("Movies.txt")
            Dim arrMovie As Integer = 0
            Do While (sr.Peek() <> -1)
                movie(arrMovie) = sr.ReadLine
                price(arrMovie) = sr.ReadLine
                cboMovie.Items.Add(movie(arrMovie))
                arrMovie = arrMovie + 1
                
            Loop
            sr.Close()
    
            'displays current system date
            lblDate.Text = DateTime.Now.ToLongDateString
    
        End Sub
    
    
     Private Sub radOne_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radOne.CheckedChanged, radTwo.CheckedChanged, _
        radThree.CheckedChanged, _
        radFour.CheckedChanged, _
        radFive.CheckedChanged, _
        radSix.CheckedChanged
           
    
            'calculations
            decSubTotal = Reg_Price * City_Tax
            decTotal = decSubTotal + Reg_Price
            decSubDisTotal = Discount_Price * City_Tax
            decDisTotal = decSubDisTotal + Discount_Price
    
            ' calculate and output to label total + tax and amount of tickets wanted
    
            If (radOne.Checked) Then
                lblCalculate.Text = decTotal.ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = decDisTotal.ToString("c")
    
            End If
            If (radTwo.Checked) Then
                lblCalculate.Text = (decTotal * 2).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 2).ToString("c")
            End If
            If (radThree.Checked) Then
                lblCalculate.Text = (decTotal * 3).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 3).ToString("c")
    
            End If
            If (radFour.Checked) Then
                lblCalculate.Text = (decTotal * 4).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 4).ToString("c")
    
            End If
            If (radFive.Checked) Then
                lblCalculate.Text = (decTotal * 5).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 5).ToString("c")
    
            End If
            If (radSix.Checked) Then
                lblCalculate.Text = (decTotal * 6).ToString("c")
            ElseIf (chkDiscount.Checked) Then
                lblCalculate.Text = (decDisTotal * 6).ToString("c")
    
            End If

    I have declared global constants so they will function in all my controls

    I am really so confused right now and its probably something very easily done but can't untwist it any help would be much appreciated[/QUOTE

    is my code such a mess ???

    Comment

    • knychtell
      New Member
      • Jan 2007
      • 66

      #3
      nope, your is just too critical i think, if your problem is only adding a selected radiobutton to listbox as an output maybe you should first declare the radiobutton within the listbox, it may sound bad but, im sure it will work, i used it a lot of time....



      here's sample code i know youd understand this one,

      in lstbox1_event (code)

      add this
      if radiobtn1.text= true then' im not quite sure of this 1st line but it should be an option when a user selected the 1st radiobtn lstbox will add the txt of that crtl.
      listbox1.items. add(radiobtn1.t ext)
      end if

      Comment

      Working...