Dim MonPrice As Decimal
       


        If RadioBtnMon20.Checked Then
            TxBxPRICE.Text = TxBxPRICE.Text
            MonPrice = MonPrice + 120
            ListBox1.Items.Add(RadioBtnMon20.Text)

        End If

        If RadioBtnMonHD.Checked Then
            TxBxPRICE.Text = TxBxPRICE.Text
            MonPrice = MonPrice + 140
            ListBox1.Items.Add(RadioBtnMonHD.Text)

        End If

        If RadioBtnMonFullHD.Checked Then
            MonPrice = MonPrice - 140 + 170
            ListBox1.Items.Add(RadioBtnMonFullHD.Text)

        ElseIf RadioBtnMoniterStand.Checked Then
            ListBox1.Items.Add(RadioBtnMoniterStand.Text)



        End If
        TxBxPRICE.Text = TxBxPRICE.Text + MonPrice

i want to add only one price if selected but with this one if i choose another option then its keep adding price instead of removing previous price and put selected price..

can you help sove this pleasee
thanxxx

Recommended Answers

All 9 Replies

Well, you keep adding to monprice over and over again in each if statement
This is going to keep adding them over and over again. Instead of the monprice statements try something simpler like

monprice = 120

monprice = 140

monprice = 170

Also, the lines

TxBxPRICE.Text = TxBxPRICE.Text

Don't do anything.

Thanx m8..actually. Txtbxprice is the actual price which I want to add monprice to it.
For insteant txbxprice =txbxprice + monprice
but monprice has diffrent price depending on what user select then adds It to total txtbxprice if they select another
Mon then it should add that price rather than addin on privous price

I'd say create a variable called baseprice and set txbxprice.text = baseprice
Then you can modify modprice however in each sub, and then let txbxprice.text = monprice + baseprice, and make the monprice changes above

Example

Dim MonPrice As Decimal
Dim BasePrice as Decimal 
 

'put whatever value you want here, I used 100.00
'If you want to use whatever's in the text box already
'just put BasePrice = txtBxPrice.Text
BasePrice = 100.00  

        If RadioBtnMon20.Checked Then
            MonPrice = 120
            ListBox1.Items.Add(RadioBtnMon20.Text)
 
        End If
 
        If RadioBtnMonHD.Checked Then
            MonPrice = 140
            ListBox1.Items.Add(RadioBtnMonHD.Text)
 
        End If
 
        If RadioBtnMonFullHD.Checked Then
            MonPrice = 170
            ListBox1.Items.Add(RadioBtnMonFullHD.Text)
 
        ElseIf RadioBtnMoniterStand.Checked Then
            ListBox1.Items.Add(RadioBtnMoniterStand.Text)
 
 
        End If

   
        TxBxPRICE.Text = BasePrice + MonPrice

than x 4 replay....i tried this but still keep adding price... basically i have three forms and three forms has radio button contains item name & price.. this is how i want to make it work.. user selects one item and the that item price is add to text box so user can see, 2nd form has different items with different price if they select item then add to text box which shows the cost so far...but what if user want to select another item then it should remove previous item price replacing with selected item but with my one it keep adding as i said..

Hi,

You should do it like this:

Public Class Form1
    Dim MonPrice As Decimal


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub

    Private Sub RadioBtnMon20_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioBtnMon20.CheckedChanged
        If Not RadioBtnMon20.Checked Then
            TxBxPRICE.Text = "100"
        Else
            MonPrice = 120
            ListBox1.Items.Add(RadioBtnMon20.Text)

            TxBxPRICE.Text = Val(TxBxPRICE.Text + MonPrice)

        End If
    End Sub

    Private Sub RadioBtnMonHd_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioBtnMonHd.CheckedChanged
        If Not RadioBtnMonHd.Checked Then

            TxBxPRICE.Text = "100"
        Else
            MonPrice = 140
            ListBox1.Items.Add(RadioBtnMonHd.Text)
            TxBxPRICE.Text = Val(TxBxPRICE.Text + MonPrice)
        
        End If
    End Sub

    Private Sub RadioBtnMonFullHD_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioBtnMonFullHD.CheckedChanged
        If Not RadioBtnMonFullHD.Checked Then

            TxBxPRICE.Text = "100"
        Else
            MonPrice = 170
            ListBox1.Items.Add(RadioBtnMonFullHD.Text)
            TxBxPRICE.Text = Val(TxBxPRICE.Text + MonPrice)
        End If
    End Sub
End Class

Hey there... than x for replay

with your answer when you defined TxBxPRICE.Text= 100....i have value that im forwarding from FORM 1 so i cant set the price cos i want to add radio button price to that text box i making seance loll

Hi,

If the value for TxBxPRICE.Text is coming from a Form1 value.
The you can try something like this if the value is coming from a Textbox:

TxBxPRICE.Text = Form1.Nameoftextbox.Text

hey thanx for replay.


i already done that...but i have tabs in form and i have diffrent radiobutton in each tabs if you no what i mean.

Hi,

Add this in the Radiobutton event in your Form1.
To test it I gave the radiobutton this name: RadioButtonName

If Not RadioButtonName.Checked Then
            Form2.TxBxPRICE.Text = "100"
        Else
            Form2.MonPrice = 120
            Form2.ListBox1.Items.Add(RadioButtonName.Text)

            Form2.TxBxPRICE.Text = Val(Form2.TxBxPRICE.Text + Form2.MonPrice)

        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.