Pilot123 Posted July 11, 2015 Share Posted July 11, 2015 (edited) Hi, I need help please.I have code that returns an array, and then writes the results to a message box. There is three possible 2-d arrays. 1.) 2-d array with 2 rows2.) 2-d array with 1 rows3.) 2-d array with no rows Is there a better way to get the results in the message box with the three given arrays as example? The format in the message boxes should stay the same. #include <Array.au3> Local $arr[2][2] = [["20:00","22:00"], ["14:00","18:00"]] ;Array 1: 2-d array with two rows ;Local $arr[1][2] = [["20:00","22:00"]] ; Array 2: 2-d array with one rows ;Local $arr[0][0] = [[]] ; Array 3: 2-d array with 'no' data ;_ArrayDisplay($arr, "My Array1") Local $iRows = UBound($arr, $UBOUND_ROWS) ; Total number of rows found in the array. ;MsgBox($MB_SYSTEMMODAL, "$arr", "The array has " & $iRows & " rows") If $iRows = 0 then MsgBox($MB_SYSTEMMODAL, "$arr", "Sorry!! No rows") Else Endif If $iRows = 1 then $var1 = $arr[0][0] $var2 = $arr[0][1] MsgBox($MB_SYSTEMMODAL, "$arr", "Has " & $iRows & " row:" & @CRLF & "Group 1: " & $var1 & " - " & $var2) Else Endif If $iRows = 2 then $var1 = $arr[0][0] $var2 = $arr[0][1] $var3 = $arr[1][0] $var4 = $arr[1][1] MsgBox($MB_SYSTEMMODAL, "$arr", "Has " & $iRows & " rows:" & @CRLF & "Group 1: " & $var1 & " - " & $var2 & @CRLF & "Group 2: " & $var3 & " - " & $var4 ) Else Endif Edited July 11, 2015 by Pilot123 Link to comment Share on other sites More sharing options...
SadBunny Posted July 12, 2015 Share Posted July 12, 2015 Maybe something like this?#include <Array.au3> Local $arr[2][2] = [["20:00", "22:00"], ["14:00", "18:00"]] ;Array 1: 2-d array with two rows ;~ Local $arr[1][2] = [["20:00","22:00"]] ; Array 2: 2-d array with one rows ;~ Local $arr[0][0] = [[]] ; Array 3: 2-d array with 'no' data ;_ArrayDisplay($arr, "My Array1") Local $iRows = UBound($arr, $UBOUND_ROWS) ; Total number of rows found in the array. ;MsgBox($MB_SYSTEMMODAL, "$arr", "The array has " & $iRows & " rows") If $iRows = 0 Then MsgBox($MB_SYSTEMMODAL, "$arr", "Sorry!! No rows") Else $s = "Has " & $iRows & " row" & ($iRows > 1 ? "s" : "") & ":" & @CRLF For $i = 0 to $iRows - 1 $var1 = $arr[$i][0] $var2 = $arr[$i][1] $s &= "Group " & $i + 1 & ": " & $var1 & " - " & $var2 & @CRLF Next MsgBox(0, 0, $s) EndIf Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
iamtheky Posted July 12, 2015 Share Posted July 12, 2015 (edited) #include<array.au3> Local $arr[2][2] = [["20:00","22:00"], ["14:00","18:00"]] ;Array 1: 2-d array with two rows ;~ Local $arr[1][2] = [["20:00","22:00"]] ; Array 2: 2-d array with one rows ;~ Local $arr[0][0] = [[]] ; Array 3: 2-d array with 'no' data msgbox(0, '' , ubound($arr) > 0 ? "There are " & ubound($arr) & " rows." & @CRLF & _ArraytoString($arr , " | ") : "no rows available") and with varsLocal $arr[2][2] = [["20:00","22:00"], ["14:00","18:00"]] ;Array 1: 2-d array with two rows ;~ Local $arr[1][2] = [["20:00","22:00"]] ; Array 2: 2-d array with one rows ;~ Local $arr[0][0] = [[]] ; Array 3: 2-d array with 'no' data for $i = 0 to ubound($arr) - 1 assign("var" & $i , $arr[$i][0]) assign("var" & $i & "c1" , $arr[$i][1]) Next $TopLine = "There are " & ubound($arr) & " rows." & @LF $data = "" for $i = 0 to ubound($arr) - 1 $data &= "Group " & $i + 1 & ": " & execute("$var" & $i) & " - " & execute("$var" & $i & "c1") & @LF Next msgbox(0, '' , $TopLine & $data) Edited July 12, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Pilot123 Posted July 12, 2015 Author Share Posted July 12, 2015 Thanks boththose and SadBunny, I appreciate your help. Your suggestions worked for me 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