Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. sum the two value

sum the two value

Scheduled Pinned Locked Moved Visual Basic
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isaii
    wrote on last edited by
    #1

    Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks

    C S 2 Replies Last reply
    0
    • I isaii

      Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're kidding, right ? Use Convert.ToInt32 to get ints, then use the + operator to add them. Your code is pretty messy, if you know the values, why are you calling Mid, or is that not what this is doing ? Christian Graus - Microsoft MVP - C++

      I 1 Reply Last reply
      0
      • I isaii

        Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks

        S Offline
        S Offline
        Steve Pullan
        wrote on last edited by
        #3

        The Case blocks are separate blocks of code - in other words the case for handling "441210" does NOT drop through to case "41110". What you'll need to do as create a separate variable to hold the sum of these cases viz: Dim totalAmt as Integer totalAmt = 0 Select Case .... Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt totalAmt = totalAmt + amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt totalAmt = totalAmt + amt End Select The variable totalAmt will hold the sum of the two cases and you can then use this in your program. ...Steve

        1 Reply Last reply
        0
        • C Christian Graus

          You're kidding, right ? Use Convert.ToInt32 to get ints, then use the + operator to add them. Your code is pretty messy, if you know the values, why are you calling Mid, or is that not what this is doing ? Christian Graus - Microsoft MVP - C++

          I Offline
          I Offline
          isaii
          wrote on last edited by
          #4

          I use Mid function because the value is from my source which is text file and it automatically extract the data from it.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups