rony2006 Posted May 10, 2016 Share Posted May 10, 2016 Hello, I have a listview and I converted the values from it in a 2D array and I need to calculate average, total and the biggest of the data from one column. the 2d array is named $lt1 $lt1[0][0] = is the number of rows (how many values I have) This number will change so one time $lt1[0][0] is 10 for ex, another time $lt1[0][0] is 4 or can be any number. The number of elements is not exact (n+1) my values are in $lt1[1 to n+1][12] So I need to calculate the average for the number $lt1[1][12], $lt1[2][12], $lt1[3][12], $lt1[n+1][12] . How I can do this please? Link to comment Share on other sites More sharing options...
Trong Posted May 11, 2016 Share Posted May 11, 2016 Maybe: Local $average For $n = 1 To $lt1[0][0] $average += $lt1[$n][12] Next $average = $average / $lt1[0][0] 4 Local $average For $n = 1 To 4 $average += $lt1[$n][12] Next $average = $average / 4 Regards, Link to comment Share on other sites More sharing options...
rony2006 Posted May 11, 2016 Author Share Posted May 11, 2016 For the average is ok, but how I can calculate de maximum value that is in the array and the sum ? Link to comment Share on other sites More sharing options...
jchd Posted May 11, 2016 Share Posted May 11, 2016 Within the same loop: Local $average, $total, $max For $n = 1 To $lt1[0][0] $average += $lt1[$n][12] $total += $lt1[$n][12] If $lt1[$n][12] > $max Then $max = $lt1[$n][12] Next $average = $average / $lt1[0][0] Skysnake 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Trong Posted May 11, 2016 Share Posted May 11, 2016 Local $average, $BigVar = 0 For $n = 1 To $lt1[0][0] If $lt1[$n][12] > $BigVar Then $BigVar = $lt1[$n][12] $average += $lt1[$n][12] Next $average = $average / $lt1[0][0] ConsoleWrite("! Average: " & $average & @CRLF) ConsoleWrite("! Bigger Number: " & $BigVar & @CRLF) Regards, Link to comment Share on other sites More sharing options...
rony2006 Posted May 12, 2016 Author Share Posted May 12, 2016 Hello guys, I tried both script but no one is working correct when calculating the maximum value from the array. So I have this values: 0 0 0 0 3 0 6 0 0 144 Average value is: 15.3 Big value is: 6 Total 153 Why big value is 6 and not 144? I used this code: $lt1 = _GUIListViewEx_ReadToArray($listatickete, 1) _ArrayDisplay($lt1, "1D display") Local $average, $total, $max For $n = 1 To $lt1[0][0] $average += $lt1[$n][14] $total += $lt1[$n][14] If $lt1[$n][14] > $max Then $max = $lt1[$n][14] Next $average = $average / $lt1[0][0] Msgbox (0, "average", $average) Msgbox (0, "bigvar", $max) Msgbox (0, "total", $total) Link to comment Share on other sites More sharing options...
jchd Posted May 12, 2016 Share Posted May 12, 2016 Probably because you've stored your values as strings and not integers or reals. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
rony2006 Posted May 12, 2016 Author Share Posted May 12, 2016 and how i can convert them to integers? I take the data from a listview Link to comment Share on other sites More sharing options...
jchd Posted May 12, 2016 Share Posted May 12, 2016 This detail was omitted from the OP. Try this: Local $average, $total, $max For $n = 1 To $lt1[0][0] $average += $lt1[$n][12] $total += $lt1[$n][12] If Number($lt1[$n][12]) > $max Then $max = Number($lt1[$n][12]) Next $average = $average / $lt1[0][0] This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
rony2006 Posted May 12, 2016 Author Share Posted May 12, 2016 Working now, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now