Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:28:40+00:00 2026-06-13T11:28:40+00:00

Dim index As Integer Dim choice As String Dim total As Integer total =

  • 0
        Dim index As Integer
        Dim choice As String
        Dim total As Integer

        total = 0

        index = NumericUpDown1.Value


        Dim arr(4) As Integer
        arr(0) = 10
        arr(1) = 5
        arr(2) = 21
        arr(3) = 33




        If index > 0 Then
            choice = (Combobox1.SelectedItem.ToString + " x " + NumericUpDown1.Value.ToString)
            ListBox1.Items.Add(choice)
            CheckedListBox1.Items.Add(choice)
            total += arr(Combobox1.SelectedIndex) * index
            TotalLabel.Text = total.ToString()


      Else
            MsgBox("error.")

        End If

I can calculate the total of single choice, but fail to accumulate to sum.
What’s wrong of the code?

Current Situation:
Step 1:
choose arr(0), index = 2
total = 20

Step 2:
choose arr(2), index = 1
total = 21

Correct Situation:
Step 1:
choose arr(0), index = 2
total = 20

Step 2:
choose arr(2), index = 1
total = 41

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:28:41+00:00Added an answer on June 13, 2026 at 11:28 am

    You’ll need a either a global variable or a class with a public variable. You should create a Transaction class to store the data about the transaction and probably a Product class to store the data about the product. What you put in it is up to you, but I’d start out with something like this:

    Public Class Transaction
        Private _productsList As List(of Product)
        Private _transationNumber As Integer
        '...more stuff...
    
        'you'll want to remember what products are in your "cart" for the transaction
        Public Property ProductsList As List(of Product)
            'your get/set accessors
        End Property
        Public Property TransactionNumber As Integer
            'your get/set accessors
        End Property
        Public Property TotalTransactionCost() As Double
            Get 
                'this will sum of the prices of all of the products you have stored in your 
                'list of products for this transaction
                Return _productsList.Sum(product => product.Price)
            End Get
        End Property
    
        Public Sub New()
            '...constructor stuff
        End Sub
        Public Sub AddProductToTransaction(byval product)
            _productsList.Add(product)
        End Sub
    
    End Class
    
    Public Class Product
        Private _price As Double
        Private _productName As String
        Private _UPC As String
    
        Public Property Price() As Double
            'your get/set accessors
        End Property
        Public Property ProductName() As String
            'your get/set accessors
        End Property
        Public UPC As String () As String
            'your get/set accessors
        End Property
    
        Public Sub New()
           'constructor stuff
        End Sub
    End Class
    

    These are a couple class shells to get you started. If you’re serious about making a product, this is a step in the right direction. If you’re going to write code, write it the right way.

    If you’re just looking for a quick and dirty solution, you can declare a global variable and just keep a running sum. Just don’t forget to clear it out before you start a new transaction.

    You’ll want to do something like:

    Private TransactionCost As Double in your form outside of all your methods.

    Again, I would recommend the first way of going about things. You’ll need at least those two classes and they’ll definitely be more fleshed out for a real product.

    I hope this helps and answers your question. If it does, hit me with an upvote and accept the answer. Welcome to SO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Public Sub textcolorchanged() Dim searchword As String = RichTextBox2.Text.ToString.Trim Dim index1 As Integer =
Private Sub FKeyButton_Click(Index As Integer) Dim curChild As Form Set curChild = frmMain.ActiveForm Dim
How to swap an integer array's value and index in vb macro i(0 to
I am using the clientAPI to query an index (Cards) in RavenDB so: Dim
dim dataType as String toolTip=Marks And Number[String] I want to get the [String] alone.
Dim insert_coupon_query As String = (INSERT INTO qa_discountcoupons (id, status_code) VALUES (AUTO_INCREMENT_ID, 5)) Dim
Public Function MethodOne(ByVal s As String) As String Dim sb As New StringBuilder() sb.Append(s)
First try Dim holdValues() As Integer 'Doesn't Work holdValues(1) = 55 Second try Dim
I have this chunk of code: noObjs = 0 Dim oName As String Dim
I am able to get the index of items added to the BindingList. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.