Results 1 to 4 of 4

Thread: help me with arrays... hu hu hu

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Location
    Penang
    Posts
    4

    Red face help me with arrays... hu hu hu

    write a procedure to calculate the column total and the the row total only. Use the array table below. The table is declared as mcItems (1 to 4, 1 to 5)

    Code:
    No of items                            Row total
    5  7  8  3  2                                  25
    4  2  3  8  2                                  19
    5  1  6  0  5                                  17
    4  6  8  9  2                                  29
    
    Column Total
    18 16 25 20 11
    i wrote a procedure about printing the total.. but my lecturer wants to store the total value.. i haven't hav a clue!
    please
    Last edited by si_the_geek; Nov 27th, 2006 at 11:09 AM. Reason: added Code tags for clearer formatting

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: help me with arrays... hu hu hu

    Welcome to VBForums

    As this question is not related to databases, I have moved it from our Database Development forum to the Classic VB forum.

    I would recommend creating two extra arrays, one for the Row totals, and one for the Column totals. You can then use loops to read the mcItems array, and store the totals in these new arrays.

  3. #3
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: help me with arrays... hu hu hu

    Here is a sample of how to add the totals, this does not display it on your page, you will have to do that yourself.

    VB Code:
    1. Private mcItems(1 To 4, 1 To 5) As Byte
    2.  
    3. Private Sub CalcTotals()
    4.  
    5.     Dim ColTotals(1 To 5) As Long
    6.     Dim RowTotals(1 To 4) As Long
    7.     Dim i As Long, ii As Long    
    8.    
    9.     For i = 1 To 5
    10.         For ii = 1 To 4
    11.             ColTotals(i) = ColTotals(i) + mcItems(ii, i)
    12.             RowTotals(ii) = RowTotals(ii) + mcItems(ii, i)
    13.         Next ii
    14.     Next i
    15.    
    16.     'instead of using Msgbox you can save them to a textbox or whatever you need
    17.     For i = 1 To 4
    18.         MsgBox RowTotals(i)
    19.     Next i
    20.     For i = 1 To 5
    21.         MsgBox ColTotals(i)
    22.     Next i
    23.  
    24. End Sub
    25.  
    26. Private Sub Form_Load()
    27.  
    28.      'set ur array values in mcItems first
    29.  
    30.      mcItems(1, 1) = 5
    31.      '...
    32.  
    33.      CalcTotals
    34.  
    35. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Location
    Penang
    Posts
    4

    Re: help me with arrays... hu hu hu

    thanks a lot... this really help.... THANK YOU!

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