3 Replies - 7043 Views - Last Post: 30 September 2012 - 07:13 AM Rate Topic: -----

#1 Pdiamond   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-September 12

A couple of beginner problems

Posted 28 September 2012 - 08:27 PM

New to Visual Basic. I hope one of you fine people could help me out.

I'm working on something simple. Select one Radio Button in each group box. One has a set discount(none/10%/20%) and the other has the service offered.(Random shit, each has a specific cost) I then have two buttons and two text boxes. One displays the cost of the service and the discount combined, and the other displays the combined total of the overall purchase.

Calculate: ItemPrice - (Itemprice * Discount)
Clear: Clears it all. (I have this down)

I'm having trouble accumulating the total though.

ItemAmountDecimal = PriceDecimal - (PriceDecimal * CouponDecimal)
        SubtotalDecimal += ItemAmountDecimal
        TotalDecimal = SubtotalDecimal
        CurrentServicesTextBox.Text = ItemAmountDecimal.ToString("C")
        TotalServicesTextBox.Text = TotalDecimal.ToString("C")

I'm also want to add a warning message if one of the radio button services isn't selected in the services group box. Is their a quick and simple way of going about this? Looked all over and haven't found a solution that doesn't include a boolean.

Thank you for your assistance!

Is This A Good Question/Topic? 0
  • +

Replies To: A couple of beginner problems

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: A couple of beginner problems

Posted 30 September 2012 - 04:02 AM

Moved to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#3 the5thelement   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 30-July 12

Re: A couple of beginner problems

Posted 30 September 2012 - 07:00 AM

I suggest using a CheckedListBox. It has an option to only allow one selection.

I tried creating a project so I could try and help as I am new here as well. The code below works however when using the "None/20%" radios the answers are incorrect the "10%" radio is correct. I will still work on this and see if I can find was wrong with it.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If RadioButton1.Checked Or RadioButton2.Checked Or RadioButton3.Checked = True Then
            If RadioButton1.Checked = True Then
                Dim Discount1 As Integer
                Dim Total1 As Integer
                Discount1 = 0
                Total1 = TextBox1.Text
                TextBox2.Text = Total1 / Discount1
                TextBox3.Text = TextBox1.Text - TextBox2.Text
            ElseIf RadioButton2.Checked = True Then
                Dim Discount2 As Integer
                Dim Total2 As Integer
                Discount2 = 10
                Total2 = TextBox1.Text
                TextBox2.Text = Total2 / Discount2
                TextBox3.Text = TextBox1.Text - TextBox2.Text
            ElseIf RadioButton3.Checked = True Then
                Dim Discount3 As Integer
                Dim Total3 As Integer
                Discount3 = 20
                Total3 = TextBox1.Text
                TextBox2.Text = Total3 / Discount3
                TextBox3.Text = TextBox1.Text - TextBox2.Text
            End If
            MsgBox("Select a discount coupon.")
        End If
    End Sub

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: A couple of beginner problems

Posted 30 September 2012 - 07:13 AM

In the checkchanged event of the optionbutton, set a variable to = what was selected for each group. The variables will need to be declared so that they are available throughout the form.

It can be something as simple as setting the variable in each of the options checkchanged event based on it's value. Or combining the handles for each group and using a select case to determine which option is checked and set the variables value accordingly.

Not sure what you mean by not including a boolean as the option buttons are basically a boolean (true being set, false being unset)

Once this is done, perform your calculation against those variables.

you would also add each calculated result to a list(of Double) where you can just use the .Sum method to display the total in your second textbox.

This post has been edited by CharlieMay: 30 September 2012 - 07:21 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1