Results 1 to 7 of 7

Thread: [Urgent] how to net a value with a list of value?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Exclamation [Urgent] how to net a value with a list of value?

    Dear all,

    I am stuck over with the question below , please kindly help.. thank you in advance.


    I have the following table with sample data as below:

    Date, Fund, Unit, Clear?
    1-Mar, A, 3.1, N
    2-Mar, A, 2.2, N
    3-Mar, A, 4.7, N

    Each day, user will input the "Unit of Fund A" to this table.

    Before inserting, this inputted unit has to be netted the unit that already in the table.

    Say, for example:

    In 4-Mar, user input -7 as the unit

    This -7 unit would be netted the unit in 1-Mar (i.e. 3.1 unit)
    then, -3.9 unit would be remained.

    This -3.9 unit would be further netted the unit in 2-Mar (i.e. 2.2 unit)
    then, -1.7 unit would be remained.

    This -1.7 unit would be further netted the unit in 3-Mar (i.e. 4.7 unit)
    then, +3 unit will be remained on 4-Mar

    This +3 unit will be inserted into the above table and since all the records that before 4-Mar have been netted off,
    they are "Cleared".

    Finally, the table would look like this:

    Date, Fund, Unit, Clear?
    1-Mar, A, 3.1, Y
    2-Mar, A, 2.2, Y
    3-Mar, A, 4.7, Y
    4-Mar, A, 3.0, N


    I supposed I have to upload all the "unclear" record from the table into an array in the first state. Then, I have to compare the inputted value with the "unit" columns of the array.

    But how? any functions in VB can help me to perform this comparsion?

    Thank you.

    (P.S. the above values are just examples, in realistic, the unit in the table and the inputted value can be both -ve and +ve)
    Last edited by lok1234; Mar 8th, 2010 at 03:32 AM.
    I can still live in my current job because I am here

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Urgent] how to net a value with a list of value?

    In short you are adding the current value to the sum of all the units till date. for example

    -7+(3.1+2.2+4.7)
    =3

    now where is this table and what kind of table is it?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: [Urgent] how to net a value with a list of value?

    Quote Originally Posted by koolsid View Post
    In short you are adding the current value to the sum of all the units till date. for example

    -7+(3.1+2.2+4.7)
    =3

    now where is this table and what kind of table is it?
    Hi ..koolsid
    this table is from an MS Access database.
    The table will be loaded into an array. (this part has been coded)

    Yes, your short is correct
    But, you know, it is just an example. It can be:

    8+(-3.1)+(-3.9)
    = 1
    I can still live in my current job because I am here

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Urgent] how to net a value with a list of value?

    You can use SQL query to get the sum from the table

    SELECT SUM(expression) FROM TABLENAME

    Where expression is the Unit Field (Which I hope you have set it as numeric) and TABLENAME is the name of the table.

    When you get that simply sum it up as I mentioned above and then use SQL Insert to add the new record...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: [Urgent] how to net a value with a list of value?

    Quote Originally Posted by koolsid View Post
    You can use SQL query to get the sum from the table

    SELECT SUM(expression) FROM TABLENAME

    Where expression is the Unit Field (Which I hope you have set it as numeric) and TABLENAME is the name of the table.

    When you get that simply sum it up as I mentioned above and then use SQL Insert to add the new record...
    this is possible if I dont have to do the record keeping.

    In realistic, I have to mark which units (or more precisely, which date's unit) have been used to net-off the user's inputted unit. Therefore, it has a "clear" field in the table.

    Besides, in case the query has returned a positive value, and user inputs a positive value, what user has inputted should be directly inserted into the table.

    Therefore, I prefer to do it in VB rather than in SQL query. Thanks..

    (My latest comment: Koolsid, it seems your method is work :>, let me further clarify )
    Last edited by lok1234; Mar 8th, 2010 at 04:49 AM.
    I can still live in my current job because I am here

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: [Urgent] how to net a value with a list of value?

    Koolsid, in case I use your suggestion, how to overcome this issue:

    1. If the sum(units) = 10 units on or before 1-Mar
    2. User inputs 10 units on 2-Mar

    Then, I want to insert a record of 10 units with Date 2-Mar into the table rather than insert a (10+10) units = 20 units in the table.
    I can still live in my current job because I am here

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Urgent] how to net a value with a list of value?

    A simple If-Endif loop can take care of that. Check if the inputted value is > than the sum(units).
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width