none
I need help finishing my code! RRS feed

  • Question

  • I have the main code written out but I need the whole code and I can't figure it out. Please help! This is what I have:


    form1.vb

    Public Class Form1
        Private Sub btn_place_order_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_place_order.Click
            Dim adon As Double
            Dim mainc As Double
            Dim subtotal As Double
            Dim total As Double
            Dim tax As Double
    
            If RadioButton1.Checked = True Then
    
                adon = 0.75
                mainc = 6.95
    
            ElseIf RadioButton2.Checked = True Then
    
                adon = 0.5
                mainc = 5.95
    
            ElseIf RadioButton3.Checked = True Then
    
                adon = 0.25
                mainc = 4.95
            End If
    
    
            subtotal = mainc + adon
            tax = 7.75 / 100
            total = (subtotal * tax) + subtotal
    
    
            TextBox1.Text = Convert.ToDouble(subtotal)
            TextBox2.Text = tax
            TextBox3.Text = total
    
            clear()
    
        End Sub
    
        Sub clear()
            CheckBox1.Checked = False
            CheckBox2.Checked = False
            CheckBox3.Checked = False
    
        End Sub
        Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
            GroupBox1.Text = "Add-on Item($.75 each)"
            CheckBox1.Text = "Lettuce Tomato and onion"
            CheckBox2.Text = "Ketchup mustered Mayo "
            CheckBox3.Text = "French Fries"
        End Sub
    
        Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
            GroupBox1.Text = "Add-on Item($.50 each)"
            CheckBox1.Text = "Peperoni"
            CheckBox2.Text = "Sauces "
            CheckBox3.Text = "Olives"
        End Sub
    
        Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
            GroupBox1.Text = "Add-on Item($.25 each)"
            CheckBox1.Text = "Croutons"
            CheckBox2.Text = "Bacon bits"
            CheckBox3.Text = "Bread sticks"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            GroupBox1.Text = "Add-on Item($.75 each)"
            CheckBox1.Text = "Lettuce Tomato and onion"
            CheckBox2.Text = "Ketchup mustered Mayo "
            CheckBox3.Text = "French Fries"
    
        End Sub
    End Class


    Friday, November 17, 2017 12:07 AM

All replies

  • This is the main code that I made up so far but I don't know how to implement it and turn it into the whole code to make it work. 

    form1.vb

    Public Class Form1

    Private Sub btn_place_order_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_place_order.Click
    Dim adon As Double
    Dim mainc As Double
    Dim subtotal As Double
    Dim total As Double
    Dim tax As Double

    If RadioButton1.Checked = True Then

    adon = 0.75
    mainc = 6.95

    ElseIf RadioButton2.Checked = True Then

    adon = 0.5
    mainc = 5.95

    ElseIf RadioButton3.Checked = True Then

    adon = 0.25
    mainc = 4.95
    End If


    subtotal = mainc + adon
    tax = 7.75 / 100
    total = (subtotal * tax) + subtotal


    TextBox1.Text = Convert.ToDouble(subtotal)
    TextBox2.Text = tax
    TextBox3.Text = total

    clear()

    End Sub

    Sub clear()
    CheckBox1.Checked = False
    CheckBox2.Checked = False
    CheckBox3.Checked = False

    End Sub
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
    GroupBox1.Text = "Add-on Item($.75 each)"
    CheckBox1.Text = "Lettuce Tomato and onion"
    CheckBox2.Text = "Ketchup mustered Mayo "
    CheckBox3.Text = "French Fries"
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
    GroupBox1.Text = "Add-on Item($.50 each)"
    CheckBox1.Text = "Peperoni"
    CheckBox2.Text = "Sauces "
    CheckBox3.Text = "Olives"
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
    GroupBox1.Text = "Add-on Item($.25 each)"
    CheckBox1.Text = "Croutons"
    CheckBox2.Text = "Bacon bits"
    CheckBox3.Text = "Bread sticks"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    GroupBox1.Text = "Add-on Item($.75 each)"
    CheckBox1.Text = "Lettuce Tomato and onion"
    CheckBox2.Text = "Ketchup mustered Mayo "
    CheckBox3.Text = "French Fries"

    End Sub
    End Class

    Thursday, November 16, 2017 5:21 PM
  • Maybe, you should try the VB forum, since you're posting to the C# forum.
    Thursday, November 16, 2017 5:46 PM
  • I have the main code written out but I need the whole code and I can't figure it out.

    What is the difference between the whole code and what you already have?  What exactly is the application supposed to do, and what part of that isn't done yet?

    Friday, November 17, 2017 12:17 AM
  • Sorry, now that I look at the question it does not make sense. That is the code I had and I improved it but it still has errors. This is the code I have now:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Lab10
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                double addon;
                double maincourse;
                double subtotal;
                double total;
                double tax;

                if (radioButton1.Checked)
                {
                    maincourse = 6.95;
                    addon = 0.75;
                }
                else if (radioButton2.Checked)
                {
                    maincourse = 5.95;
                    addon = 0.5;
                }
                else if (radioButton3.Checked)
                {
                    maincourse = 4.95;
                    addon = 0.25;
                }
                subtotal = maincourse;

                if (checkBox1.Checked = true)

                    subtotal = subtotal + addon;
                
                if else (checkBox2.Checked = true)
                
                    subtotal = subtotal + addon
                
                if else (checkBox3.Checked = true)
                   
                    subtotal = subtotal + addon           

                tax = (7.75 / 100)*subtotal
                
                total = tax + subtotal

                textBox1.Text = subtotal.ToString;
                textBox2.Text = tax.ToString("#.##");
                textBox3.Text = total.ToString("#.##");
                
            }

            private void button2_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }

            private void checkBox3_CheckedChanged(object sender, EventArgs e)
            {
                clearTotals();

            }

            private void checkBox2_CheckedChanged(object sender, EventArgs e)
            {
                clearTotals();

            }

            private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                clearTotals();
            }

            private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {
                groupBox1.Text = "Add-on Item($0.75 each)";
                checkBox1.Text = "Lettuce, tomato and onion";
                checkBox2.Text = "Ketchup, mustard and mayo";
                checkBox3.Text = "French fries";

                clearAddOns();
            }

            private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                groupBox1.Text = "Add-on Item ($0.50 each)";
                checkBox1.Text = "Peperoni";
                checkBox2.Text = "Sauces";
                checkBox3.Text = "Olives";

                clearAddOns();
            }

            private void radioButton3_CheckedChanged(object sender, EventArgs e)
            {
                groupBox1.Text = "Add-on Item ($0.25 each)";
                checkBox1.Text = "Croutons";
                checkBox2.Text = "Bacon bits";
                checkBox3.Text = "Bread sticks";

                clearAddOns();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                groupBox1.Text = "Add-on Item($0.75 each)";
                checkBox1.Text = "Lettuce, tomato and onion";
                checkBox2.Text = "Ketchup, mustard and mayo";
                checkBox3.Text = "French fries";

                clearAddOns();
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;

                clearTotals();
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";

            }
        }
    }


    Friday, November 17, 2017 2:14 AM
  • Sorry, now that I look at the question it does not make sense. That is the code I had and I improved it but it still has errors.

    That is not VB code.  In order to get assistance with your application you need to:
    - Post VB code
    - Show the error message that you are seeing
    - Indicate which line of code generates the error
    - Show the values of the variables in that line of code.

    It is usually also worthwhile to provide a description of what the code is expected to do.

    • Edited by Acamar Friday, November 17, 2017 2:30 AM fmt
    Friday, November 17, 2017 2:30 AM
  • This is the main code that I made up so far but I don't know how to implement it and turn it into the whole code to make it work. 

    Hi missmissy11

    I am not sure what you want to do, do you have some problems when you use the code above? Or do you want to achieve by your code? Please provide more detailed info about your question.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 17, 2017 9:09 AM
    Moderator
  • Missy,

    I'm not sure that that's enough information to go on and also, I think this may be homework.

    I'll do what I can to help and in the following, I'm more or less guessing at what the assignment is. If I'm right about this being homework, please let them know that you got help from here.

    I set my form up as follows:

    Hopefully that's close to what you're dealing with?

    If so, the following shows a way that you might consider using (or using some parts of). Note that much of this has been relegated to a class because that's really where it needs to be:

    Public Class Form1
        Private _calculator As MealCalculator
    
    
    
        Private Sub _
            Form1_Load(sender As Object, _
                       e As EventArgs) _
                       Handles MyBase.Load
    
            CheckBox_AddOn1.Checked = False
            CheckBox_AddOn2.Checked = False
            CheckBox_AddOn3.Checked = False
    
        End Sub
    
    
    
        Private Sub _
            Form1_Shown(sender As Object, _
                        e As System.EventArgs) _
                        Handles Me.Shown
    
            ResetOrderToolStripMenuItem_Click(Nothing, Nothing)
    
        End Sub
    
    
    
        Private Sub _
            RadioButton_CheckedChanged(sender As Object, _
                                       e As System.EventArgs) _
                                       Handles rb_Cheeseburger.CheckedChanged, _
                                               rb_Pizza.CheckedChanged, _
                                               rb_Salad.CheckedChanged
    
            CheckBox_AddOn1.Checked = False
            CheckBox_AddOn2.Checked = False
            CheckBox_AddOn3.Checked = False
    
            _calculator = Nothing
            UpdateReceipt()
    
            If DirectCast(sender, RadioButton).Checked Then
                If rb_Cheeseburger.Checked Then
                    GroupBox_AddOns.Text = "Add-on Item($.75 each)"
                    CheckBox_AddOn1.Text = "Lettuce, Tomato, Onion"
                    CheckBox_AddOn2.Text = "Ketchup, Mustard, Mayonnaise"
                    CheckBox_AddOn3.Text = "French Fries"
    
                ElseIf rb_Pizza.Checked Then
                    GroupBox_AddOns.Text = "Add-on Item($.50 each)"
                    CheckBox_AddOn1.Text = "Pepperoni"
                    CheckBox_AddOn2.Text = "Sauces "
                    CheckBox_AddOn3.Text = "Olives"
    
                ElseIf rb_Salad.Checked Then
                    GroupBox_AddOns.Text = "Add-on Item($.25 each)"
                    CheckBox_AddOn1.Text = "Croutons"
                    CheckBox_AddOn2.Text = "Bacon bits"
                    CheckBox_AddOn3.Text = "Bread sticks"
    
                End If
    
                GroupBox_AddOns.Visible = True
                AddOn_CheckedChanged(Nothing, Nothing)
            End If
    
        End Sub
    
    
    
        Private Sub _
            AddOn_CheckedChanged(sender As System.Object, _
                                 e As System.EventArgs) _
                                 Handles CheckBox_AddOn1.CheckedChanged, _
                                         CheckBox_AddOn2.CheckedChanged, _
                                         CheckBox_AddOn3.CheckedChanged
    
            If rb_Cheeseburger.Checked Then
                _calculator = New MealCalculator(MealCalculator.MealType.Cheeseburger)
                UpdateReceipt()
    
            ElseIf rb_Pizza.Checked Then
                _calculator = New MealCalculator(MealCalculator.MealType.Pizza)
                UpdateReceipt()
    
            ElseIf rb_Salad.Checked Then
                _calculator = New MealCalculator(MealCalculator.MealType.Salad)
                UpdateReceipt()
            End If
    
        End Sub
    
    
    
        Private Sub _
            ResetOrderToolStripMenuItem_Click(sender As System.Object, _
                                              e As System.EventArgs) _
                                              Handles ResetOrderToolStripMenuItem.Click
    
            GroupBox_AddOns.Visible = False
            GroupBox_Receipt.Visible = False
    
            With TextBox_Receipt
                .ReadOnly = True
                .ForeColor = Color.Navy
                .BackColor = Me.BackColor
                .BorderStyle = BorderStyle.None
                .TabStop = False
                .Font = New Font("Tahoma", 9, FontStyle.Bold)
            End With
    
            rb_Cheeseburger.Checked = False
            rb_Pizza.Checked = False
            rb_Salad.Checked = False
    
        End Sub
    
    
    
        Private Sub UpdateReceipt()
    
            If _calculator IsNot Nothing Then
                Dim checkedQty As Integer
    
                If CheckBox_AddOn1.Checked Then
                    checkedQty += 1
                End If
    
                If CheckBox_AddOn2.Checked Then
                    checkedQty += 1
                End If
    
                If CheckBox_AddOn3.Checked Then
                    checkedQty += 1
                End If
    
                With TextBox_Receipt
                    .Text = _calculator.CreateReceipt(checkedQty)
                    .SelectionLength = 0
                End With
    
                GroupBox_Receipt.Visible = True
            Else
                TextBox_Receipt.Clear()
                GroupBox_Receipt.Visible = False
            End If
    
        End Sub
    End Class
    
    
    
    
    
    Public NotInheritable Class MealCalculator
        ' Missy,
        '
        ' If this is homework then please let them
        ' know that you got help in this forum.
    
        Public Enum MealType
            NA
            Cheeseburger
            Pizza
            Salad
        End Enum
    
        Private Const taxAmount As Decimal = CDec(7.75 / 100)
    
        Private _mealTypeSelection As MealType
        Private _addOnPriceEach As Decimal
        Private _mainCourse As Decimal
        Private _subTotal As Decimal
        Private _total As Decimal
        Private _tax As Decimal
    
        Public Sub New(ByVal meal As MealType)
    
            Select Case meal
                Case MealType.Cheeseburger
                    _mainCourse = 6.95D
                    _addOnPriceEach = 0.75D
    
                Case MealType.Pizza
                    _mainCourse = 5.95D
                    _addOnPriceEach = 0.5D
    
                Case MealType.Salad
                    _mainCourse = 4.95D
                    _addOnPriceEach = 0.25D
    
                Case MealType.NA
                    Throw New ArgumentException("The meal type must be set.")
            End Select
    
            _mealTypeSelection = meal
    
        End Sub
    
        Public Function CreateReceipt(ByVal qtyOfAddOns As Integer) As String
    
            Dim retVal As String = Nothing
    
            If qtyOfAddOns < 0 Then
                Throw New ArgumentOutOfRangeException("Quantity Of Add-Ons", "Must be a non-negative value." & vbCrLf)
    
            Else
                ComputeTotal(qtyOfAddOns)
                Dim sb As New System.Text.StringBuilder
    
                sb.AppendLine("Meal Type: " & _mealTypeSelection.ToString)
                sb.AppendLine()
                sb.AppendLine("Main Course: " & _mainCourse.ToString("c2"))
    
                If qtyOfAddOns > 0 Then
                    sb.AppendLine("Add-Ons:")
                    sb.AppendLine()
                    For i As Integer = 1 To qtyOfAddOns
                        sb.AppendLine(String.Format("{0}Add-On {1}: {2:c2}", _
                                                    Space(5), i, _addOnPriceEach))
                    Next
                Else
                    sb.AppendLine("Add-Ons: None")
                End If
    
                sb.AppendLine()
                sb.AppendLine(String.Format("Subtotal: {0:c2}", _subTotal))
                sb.AppendLine(String.Format("Tax: {0:c2}", _tax))
                sb.AppendFormat("Total: {0:c2}", _total)
    
                retVal = sb.ToString
            End If
    
            Return retVal
    
        End Function
    
        Private Sub ComputeTotal(ByVal qtyOfAddOns As Integer)
    
            _subTotal = _mainCourse + (qtyOfAddOns * _addOnPriceEach)
            _tax = taxAmount * _subTotal
            _total = _subTotal + _tax
    
        End Sub
    
        Public ReadOnly Property AddOnPriceEach As Decimal
            Get
                Return _addOnPriceEach
            End Get
        End Property
    
        Public ReadOnly Property MainCourse As Decimal
            Get
                Return _mainCourse
            End Get
        End Property
    
        Public ReadOnly Property MealTypeSelection As MealType
            Get
                Return _mealTypeSelection
            End Get
        End Property
    
        Public ReadOnly Property SubTotal As Decimal
            Get
                Return _subTotal
            End Get
        End Property
    
        Public ReadOnly Property Tax As Decimal
            Get
                Return _tax
            End Get
        End Property
    
        Public ReadOnly Property Total As Decimal
            Get
                Return _total
            End Get
        End Property
    End Class

    Running it through the first one (I checked all of them though):

    I hope it helps. If I'm way off base then explain more and maybe show some screenshots about what you're dealing with.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Friday, November 17, 2017 6:56 PM