Results 1 to 8 of 8

Thread: code prob****RESOLVED****

Threaded View

  1. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    I want to substract maximum value and minimum value which the values are from column 'Sampel1' to column 'Sampel5'(pls see attachment).
    My prob is, the result for the subtraction for column 'Julat' (pls see the attachment)
    is diiferent if I calculate manually.

    For instance( row 5) :
    Max value = 354
    Min value = 10.6
    Subtraction = 354 - 10.6 = 343.4
    The answer should be 343.4, not 343

    Row 6 :
    Max value = 21.3
    Min value = 2.5
    Subtraction = 21.3 - 2.5 = 18.8
    The answer should be 18.8, not 19

    I cant figure out what is wrong with the code.
    Please help.
    Thank U in advance.

    Snippet code :

    VB Code:
    1. 'add column
    2.       MSFlexGrid7.Cols = MSFlexGrid7.Cols + 1
    3.       MSFlexGrid7.TextMatrix(0, 6) = "Purata"
    4.       MSFlexGrid7.Cols = MSFlexGrid7.Cols + 1
    5.       MSFlexGrid7.TextMatrix(0, 7) = "Julat"
    6.  
    7.       'mean for column Purata
    8.       Dim X
    9.       For X = 1 To MSFlexGrid7.Rows - 1
    10.         MSFlexGrid7.TextMatrix(X, 6) = (Val(MSFlexGrid7.TextMatrix(X, 1)) + Val(MSFlexGrid7.TextMatrix(X, 2)) + Val(MSFlexGrid7.TextMatrix(X, 3)) + Val(MSFlexGrid7.TextMatrix(X, 4)) + Val(MSFlexGrid7.TextMatrix(X, 5))) / 5
    11.       Next
    12.  
    13.     'range for column Julat
    14.     Dim row As Long
    15.     Dim column As Long
    16.     Dim Max As Long
    17.     Dim Min As Long
    18.  
    19.     With MSFlexGrid7
    20.  
    21.      For row = 1 To .Rows - 1
    22.  
    23.          Max = Val(.TextMatrix(row, 1))
    24.          Min = Val(.TextMatrix(row, 1))
    25.  
    26.          'loop only for column 1 to column 5
    27.          For column = 1 To 5
    28.          
    29.              If Min > Val(.TextMatrix(row, column)) Then
    30.                  Min = Val(.TextMatrix(row, column))
    31.              End If
    32.  
    33.              If Max < Val(.TextMatrix(row, column)) Then
    34.                  Max = Val(.TextMatrix(row, column))
    35.              End If
    36.              
    37.              Dim h
    38.              h = Max - Min
    39.              .TextMatrix(row, 7) = h
    40.  
    41.         Next
    42.  
    43.      Next
    44.     End With
    Attached Images Attached Images  

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