Sign in to follow this  
Followers 0
decerte

please help me rewrite for shorter .

3 posts in this topic

#1 ·  Posted (edited)

im writing a program to monitoring my computers working times . i want it count how many time my computers working , and write it to excel . i need monitoring 10 computer , i wrote for 2 computer , but im newbie , after 2 computer , my .au3 is too long , could anyone please help me fix it for shorter ?

#include <GUIConstants.au3>
#Include <File.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#Include <Array.au3>
#include<Date.au3>
#include<Excel.au3>
global $hden,$mden,$hve,$mve,$tglams,$tglamc,$tglam,$hdens,$hves,$hdenc,$hvec,$i
GUICreate( "my bot", 500 , 760)
GUICtrlCreateLabel("comp1:", 0, 0, 43, 16)
$button_1 = GUICtrlCreateButton ("Start",  10, 20, 70)
$button_3 = GUICtrlCreateButton ( "rest",  250, 20, 70)
$button_2 = GUICtrlCreateButton ("Stop",  90, 20, 70 )
$button_4 = GUICtrlCreateButton ("Broken",  170, 20, 70 )
GUICtrlCreateLabel("comp2:", 0, 55, 43, 16)
$button_5 = GUICtrlCreateButton ("start",  10, 70, 70)
$button_7 = GUICtrlCreateButton ( "rest",  250, 70, 70)
$button_6 = GUICtrlCreateButton ("stop",  90, 70, 70 )
$button_8 = GUICtrlCreateButton ("Broken",  170, 70, 70 )
GUISetState ()
While 1
        $msg = GUIGetMsg() ; this checks for a message/input from the GUI.
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        Exit ; this states, on an exit event, exit the loop.
     Case $msg = $button_2
     giove()
                    case $msg = $button_1
                     gioden()
                        case $msg = $button_3
                        cophep()
       case $msg = $button_4
                        Khongphep()
      Case $msg = $button_6
     giove1()
                    case $msg = $button_5
                     gioden1()
                        case $msg = $button_7
                        cophep1()
       case $msg = $button_8
                        Khongphep1()
    
      EndSelect
Wend[/color][/font][/size]

[size=3][font=arial, sans-serif][color=#333333]func gioden()
   $hden= @HOUR
   $mden =@MIN
   $hden= $hden+$mden/60
   if $hden <12 Then
   $hdens=$hden
   EndIf
    if $hden >12 Then
   $hdenc=$hden
   EndIf
   $hdens=8 ; set for test
   $hdenc=13 ; set for test

EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func giove()
   $hve= @HOUR
   $mve =@MIN
   $day=@MDAY
   $hve= $hve+$mve/60
  $hves=11 ; set for test
  $hvec=17;set for test
   $tglams= $hves - $hdens
      $tglamc = $hvec - $hdenc
   $tglam= $tglamc + $tglams
$sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, $tglam, $day, 5) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func khongphep()
   $day=@MDAY
    $sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, 0 , $day, 5) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func cophep()
   $day=@MDAY
    $sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, 100 , $day, 5) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc[/color][/font][/size]

[size=3][font=arial, sans-serif][color=#333333]func gioden1()
   $hden= @HOUR
   $mden =@MIN
   $hden= $hden+$mden/60
   if $hden <12 Then
   $hdens=$hden
   EndIf
    if $hden >12 Then
   $hdenc=$hden
   EndIf
   $hdens=8 ; set for test
   $hdenc=13 ; set for test

EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func giove1()
   $hve= @HOUR
   $mve =@MIN
   $day=@MDAY
   $hve= $hve+$mve/60
  $hves=11 ; set for test
  $hvec=17;set for test
   $tglams= $hves - $hdens
      $tglamc = $hvec - $hdenc
   $tglam= $tglamc + $tglams
$sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, $tglam, $day, 4) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func khongphep1()
   $day=@MDAY
    $sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, 0 , $day, 4) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc[/color][/font][/size]
[size=3][font=arial, sans-serif][color=#333333]func cophep1()
   $day=@MDAY
    $sFilePath1 = "test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
   _ExcelWriteCell($oExcel, 100 , $day, 4) ;Write to the Cell
   _ExcelBookClose($oExcel)
EndFunc

testmeo 2.au3

Edited by decerte

Share this post


Link to post
Share on other sites



Try this.

#include <GUIConstants.au3>
#include <File.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>
#include<Date.au3>
#include<Excel.au3>

Global $hden, $mden, $hve, $mve, $tglams, $tglamc, $tglam, $hdens, $hves, $hdenc, $hvec, $i
Global $aArr[21][5]
GUICreate("my bot", 500, 800)

For $i = 1 To UBound($aArr) - 1
    GUICtrlCreateLabel("comp" & $i & ":", 0, 3 + ($i - 1) * 40, 43, 16)
    $aArr[$i][1] = GUICtrlCreateButton("Start", 10, 18 + ($i - 1) * 40, 70, 18)
    $aArr[$i][2] = GUICtrlCreateButton("Stop", 90, 18 + ($i - 1) * 40, 70, 18)
    $aArr[$i][3] = GUICtrlCreateButton("Broken", 170, 18 + ($i - 1) * 40, 70, 18)
    $aArr[$i][4] = GUICtrlCreateButton("rest", 250, 18 + ($i - 1) * 40, 70, 18)
Next

GUISetState()
While 1
    $msg = GUIGetMsg() ; this checks for a message/input from the GUI.
    For $i = 1 To UBound($aArr) - 1
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit ; this states, on an exit event, exit the loop.
            Case $aArr[$i][2]
                giove($i)
            Case $aArr[$i][1]
                gioden($i)
            Case $aArr[$i][3]
                cophep($i)
            Case $aArr[$i][4]
                Khongphep($i)
        EndSwitch
    Next
WEnd


Func gioden($iNum)
    $hden = @HOUR
    $mden = @MIN
    $hden = $hden + $mden / 60
    If $hden < 12 Then
        $hdens = $hden
    EndIf
    If $hden > 12 Then
        $hdenc = $hden
    EndIf
    $hdens = 8 + $iNum ; set for test
    $hdenc = 13 ; set for test
    MsgBox(0, "test", "$hdens + 8 = " & $hdens, 2) ; <=== Test
EndFunc   ;==>gioden

Func giove($iNum)
    $hve = @HOUR
    $mve = @MIN
    $day = @MDAY
    $hve = $hve + $mve / 60
    $hves = 11 ; set for test
    $hvec = 17;set for test
    $tglams = $hves - $hdens
    $tglamc = $hvec - $hdenc
    $tglam = $tglamc + $tglams
    $sFilePath1 = "test.xls"
    $oExcel = _ExcelBookOpen($sFilePath1, 0)
    _ExcelWriteCell($oExcel, $tglam, $day, 3 + $iNum) ;Write to the Cell
    _ExcelBookClose($oExcel)
EndFunc   ;==>giove

Func khongphep($iNum)
    $day = @MDAY
    $sFilePath1 = "test.xls"
    $oExcel = _ExcelBookOpen($sFilePath1, 0)
    _ExcelWriteCell($oExcel, 0, $day, 3 + $iNum) ;Write to the Cell
    _ExcelBookClose($oExcel)
EndFunc   ;==>khongphep

Func cophep($iNum)
    $day = @MDAY
    $sFilePath1 = "test.xls"
    $oExcel = _ExcelBookOpen($sFilePath1, 0)
    _ExcelWriteCell($oExcel, 100, $day, 3 + $iNum) ;Write to the Cell
    _ExcelBookClose($oExcel)
EndFunc   ;==>cophep
1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thank God ! thank Malkey , you helped me alot :)

thank again and again ;)

Edited by decerte

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0