Results 1 to 13 of 13

Thread: [RESOLVED] breaking amout

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Resolved [RESOLVED] breaking amout

    Dear All,

    Good Day,

    I am using VB6, I have a Issue Breaking Amount in Chunk of 1,000,000/-

    Case 1 - Suppose my amount is 1,500,000/- then it should break in 1st amount = 1,000,000/- & 2nd 500,000/-

    Case 2 - Suppose my amount is 3,000,100/- then it should break in 1st amount = 1,000,000/- & 2nd 1000,000/- 3rd 1000,000/- & 4th 100/-


    I have used function mode but it is working randomly!

    Please assist

    Thanks

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: breaking amout

    Post your algorithm and we'll try to debug it for you.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: breaking amout

    i am using input from a excel file, pasting the extract of it

    basically i have to break the Amount & Save in Access database

    Insert & Excel File modules are working fine, issue is with Breaking Values through Mode, this Code is working fine randomly, sometimes it skip the values & sometimes it return/insert 0 as amount

    Code:
     If Val(rsExcel("Amount")) > "1000000" Then
        
        temp_amount = Val(rsExcel("Amount"))
        Call InsertValues(1000000)
        
        
        tcount = Round(Val(rsExcel("Amount")) / 1000000, 0)
        temp_remaining = Val(rsExcel("Amount")) Mod 1000000
           
        
        For i = 1 To tcount - 1
            Call InsertValues(temp_remaining)
        Next
    
    End if

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: breaking amout

    Please also note, there will be values which are less then 1M (1,000,000/-) & will not be break

    only values above 1M will be beaked

    Thanks

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: breaking amout

    First off, your IF statement is wrong....you are tying to compare a value (numeric) with a string ("1000000")

    I'll look at the rest in a moment

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: breaking amout

    Looks strange.
    Say Amount is 5,500,000
    Your first call would input 1000000
    Then t_count would be 5 (correct?)
    Then, you next calls in your loop would put the SAME value (temp_value) in 5 times.
    What you want, I think, is 1000000 put in 5 times and 500,000 put in once. Also correct?

    On my iPad so can't experiment, but if my logic is correct, do your loop based on t_count, but put in 10000000, that number of times, and THEN, after the loop, put in temp_remaining once

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: breaking amout

    Someone will solve this for you, if you don't, before I can get to my pc.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: breaking amout

    as i mention b4 its working randomly...

    is there any alternative way to do this pls

    Thanks

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: breaking amout

    Did you change your IF statement to look at 1000000, versus "10000000"?

  10. #10
    Member
    Join Date
    Nov 2012
    Posts
    62

    Re: breaking amout

    try this:
    Code:
    While temp_amount > 1000000
    'will loop for each chunk of 1,000,000
    temp_amount = temp_amount - 1000000
    wend
    'process the last chunk

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: breaking amout

    HEllo Welshman & SamOscarBrown

    Welshman
    i have tested your code, actually i want to break the amount in part but each part should not be more then 1,000,000/- as per ur code its decreasing the amount but the value is more then 1,000,000/-

    looking for help

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: breaking amout

    Thanks alot all

    i have fixed it

    gr8!

  13. #13
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] breaking amout

    Code:
    Const CHUNK = 1000000#
    Dim temp_amount As Double, i As Long
    
    temp_amount = Val(rsExcel("Amount"))
    
    If temp_amount > CHUNK Then
        For i = 1& To temp_amount \ CHUNK
            Call InsertValues(CHUNK)
        Next
    End If
    
    Call InsertValues(temp_amount Mod CHUNK)
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

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