mila Posted May 10, 2010 Share Posted May 10, 2010 Hi All ... I have a program to calculate the value in input text. I create 3 rows and 3 coloumns with looping. Here is the format : total1 val1.1 val1.2 val1.3 total2 val2.1 val2.2 val2.3 total3 val3.1 val3.2 val3.3 total1 = val1.1+val1.2+val1.3 ... My Question is how to calculate to get total1, total2, total3 with looping. I dont want to declare one by one. I need help to solve this problem. Thank you. Link to comment Share on other sites More sharing options...
DW1 Posted May 10, 2010 Share Posted May 10, 2010 Can you show what code you have... it would be easier to help, as I am unsure exactly what you are asking. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
mila Posted May 10, 2010 Author Share Posted May 10, 2010 Hi DanWilli ... it's my code : expandcollapse popupdim $menustate, $menustate1, $menustate2, $menustate3, $menustate4, $menustate5, $menu, $menu1, $menu2, $menu3, $menu4, $tot, $tot2, $tot3 Local $btn, $msg, $i, $a, $a1, $a2,$a3, $a4, $a5, $a6, $a7 GUICreate("Expenses", 800, 500, -1, -1, -1) GUICtrlCreateLabel("[1]",280, 80,50) GUICtrlCreateLabel("[2]",355, 80,15) GUICtrlCreateLabel("Total", 670, 95) $i = 1 $a = 120 ;Date (left) $a1 = 120 ;Daily Meal (left) $a2 = 120 ;Hotel/Other Allow (left) $a3 = 120 ;Ticket Plane (left) $a4 = 120 ;Local Transport (left) $a5 = 120 ;Public Transport (left) $a6 = 120 ;Total (left) $a7 = 120 ;Remarks (left) ;$i = 1 ;While $i <= 31 For $i = 1 To 3 GUICtrlCreateLabel($i, 10, $a) $a = $a + 14 $menu = GUICtrlCreateInput("", 250, $a1 , 70, 15 ) ;$menustate1 = GUICtrlRead($menu) ;MsgBox (0,"", $menustate1 ) $a1 = $a1 + 14 $menu1 = GUICtrlCreateInput("", 330, $a2 , 70, 15 ) ;$menustate2 = GUICtrlRead($menu1) ;MsgBox (0,"", $menustate2 ) $a2 = $a2 + 14 GUICtrlCreateInput("", 650, $a6 , 70, 15 ) ;MsgBox (0,"", $tot ) GUICtrlSetBkColor(-1, 0xE0E0E0 ) $a6 = $a6 + 14 Next $btn = GUICtrlCreateButton("Calculate", 650, 200, 70, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $btn $ax = 120 ; MY PROBLEM IN HERE for $i = 1 To 3 $menustate1 = GUICtrlRead($menu) $menustate2 = GUICtrlRead($menu1) $tot3 = $menustate1 + $menustate2 ;GUICtrlCreateInput("", 650, $a6 , 70, 15 ) GUICtrlCreateInput($tot3, 650, $ax, 70, 15 ) GUICtrlSetBkColor(-1, 0xE0E0E0 ) $ax = $ax + 14 Next ;ExitLoop EndSelect WEnd Fill coloumn [1] and [2] then click calculate button. The value is wrong. Have idea for this problem? Link to comment Share on other sites More sharing options...
hawky358 Posted May 10, 2010 Share Posted May 10, 2010 (edited) Ok, I just changed some parts of your code (not a rewrite) so that you can get the basic idea. - What I did was to change to box assignments to arrays, so that you have a record of all the handles for the controls. (Currently you are only keeping track of the last handle. expandcollapse popupdim $menustate, $menustate1, $menustate2, $menustate3, $menustate4, $menustate5, $menu, $menu1, $menu2, $menu3, $menu4, $tot, $tot2, $tot3 Local $btn, $msg, $i, $a, $a1, $a2,$a3, $a4, $a5, $a6, $a7 #include <GUIConstantsEx.au3> Global $menu[4], $menu1[4],$totalbox[4] GUICreate("Expenses", 800, 500, -1, -1, -1) GUICtrlCreateLabel("[1]",280, 80,50) GUICtrlCreateLabel("[2]",355, 80,15) GUICtrlCreateLabel("Total", 670, 95) $i = 1 $a = 120 ;Date (left) $a1 = 120 ;Daily Meal (left) $a2 = 120 ;Hotel/Other Allow (left) $a3 = 120 ;Ticket Plane (left) $a4 = 120 ;Local Transport (left) $a5 = 120 ;Public Transport (left) $a6 = 120 ;Total (left) $a7 = 120 ;Remarks (left) ;$i = 1 ;While $i <= 31 For $i = 1 To 3 GUICtrlCreateLabel($i, 10, $a) $a = $a + 14 $menu[$i] = GUICtrlCreateInput("", 250, $a1 , 70, 15 ) ;$menustate1 = GUICtrlRead($menu) ;MsgBox (0,"", $menustate1 ) $a1 = $a1 + 14 $menu1[$i] = GUICtrlCreateInput("", 330, $a2 , 70, 15 ) ;$menustate2 = GUICtrlRead($menu1) ;MsgBox (0,"", $menustate2 ) $a2 = $a2 + 14 $totalbox[$i] = GUICtrlCreateInput("", 650, $a6 , 70, 15 ) ;MsgBox (0,"", $tot ) ;~ GUICtrlSetBkColor(-1, 0xE0E0E0 ) GUICtrlSetState(-1,$GUI_disable) $a6 = $a6 + 14 Next $btn = GUICtrlCreateButton("Calculate", 650, 200, 70, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $btn $ax = 120 ; MY PROBLEM IN HERE for $i = 1 To 3 $menustate1 = GUICtrlRead($menu[$i]) $menustate2 = GUICtrlRead($menu1[$i]) $tot3 = $menustate1 + $menustate2 ;GUICtrlCreateInput("", 650, $a6 , 70, 15 ) ;~ GUICtrlCreateInput($tot3, 650, $ax, 70, 15 ) GUICtrlSetData($totalbox[$i],$tot3) ;~ GUICtrlSetBkColor(-1, 0xE0E0E0 ) $ax = $ax + 14 Next ;ExitLoop EndSelect WEnd Like I said I just commented out some unnecessary code and changed some stuff, the idea was to keep your code as close to your existing code as possible. Just as a sidenote, you don't have to declare all the variables at the start of the script, they can be declared with values as you need them. (Of course it depens if they are used in a function or global etc.) Edited May 10, 2010 by hawky358 Link to comment Share on other sites More sharing options...
mila Posted May 10, 2010 Author Share Posted May 10, 2010 Hi Hawky Thank U so much ... It's work Link to comment Share on other sites More sharing options...
Malkey Posted May 10, 2010 Share Posted May 10, 2010 Changed a few things.Local $btn, $msg, $i, $idMenu[12] GUICreate("Expenses", 800, 500, -1, -1, -1) GUISetFont(12, 800) GUICtrlCreateLabel("[1]", 160, 80, 50, 20) GUICtrlCreateLabel("[2]", 240, 80, 50, 20) GUICtrlCreateLabel("[3]", 320, 80, 50, 20) GUICtrlCreateLabel("Total", 510, 95, 100, 20) For $i = 0 To 2 GUICtrlCreateLabel("[" & $i + 1 & "]", 10, $i * 20 + 120, 120, 20) $idMenu[$i * 4 + 0] = GUICtrlCreateInput("", 140, $i * 20 + 120, 70, 20) $idMenu[$i * 4 + 1] = GUICtrlCreateInput("", 220, $i * 20 + 120, 70, 20) $idMenu[$i * 4 + 2] = GUICtrlCreateInput("", 300, $i * 20 + 120, 70, 20) $idMenu[$i * 4 + 3] = GUICtrlCreateInput("", 500, $i * 20 + 120, 70, 20) GUICtrlSetBkColor(-1, 0xE0E0E0) Next $btn = GUICtrlCreateButton("Calculate", 650, 200, 120, 20) GUISetState() While $msg <> -3 $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop Case $btn For $i = 3 To UBound($idMenu) - 1 Step 4 GUICtrlSetData($idMenu[$i], GUICtrlRead($idMenu[$i - 1]) + _ GUICtrlRead($idMenu[$i - 2]) + _ GUICtrlRead($idMenu[$i - 3])) Next EndSwitch WEnd 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