il mio primo programma in autoit

« Older   Newer »
  Share  
CAT_IMG Posted on 25/1/2011, 20:45     +1   -1

Agli inizi

Group:
Member
Posts:
15
Reputazione:
+1

Status:


eccoci qua!
mentre mi dilettavo nello scoprire i segreti di autoit un amico mi ha chiesto
un programma per listare l'arrivo dei concorrenti di una maratona
quando l'ho scritto non mi aspettavo di pubblicarlo e quindi perdonate
i nomi delle variabili, la stesura del programma ecc...
spero torni utele a qualcuno

SPOILER (click to view)
#include <excel.au3>
#include <guiconstantsex.au3>
#include <buttonconstants.au3>
#include <staticconstants.au3>
#include <datetimeconstants.au3>
#include <date.au3>
#include <windowsconstants.au3>
#include <misc.au3>
#Include <winapi.au3>

Global $pulsante1,$pulsante2,$msg,$numeroconcorrenti=33,$domanda=1,$numeroconcorrenti1=0
Global $posiz = 3,$numeromaglietta,$riga2,$posiz2,$nomeconcorrente,$pritorno,$msg,$msg2
Global $c=3,$x,$x2,$inc=20,$visualizza_tempo,$ins_maglietta,$visualizza_maglietta,$data3, $ultimiarrivi
Global $data,$ultimoarrivi,$sCellValue3,$sCellValue4,$sCellValue5,$BUONTEMPO1,$BUONTEMPO2,$BUONTEMPO3
Global $sCellValue54,$sCellValue55,$data54,$fine,$sCellValue12,$sCellValue22,$pippo,$leggivuoti,$cv,$leggivuoti2
Global $oraarrivo, $numeromagliettaadd,$pulsante3,$trovadoppi,$sCellValue99,$sCellValue9,$trovadoppi2,$data99
Global $cerca3,$sCellValue33,$z,$sCellValue999,$trovadoppi2,$y,$sCellValue888,$vecchiotempo



$sFilePath1 = @DesktopCommonDir & "\BUONTEMPO.xls" ;This file should already exist
$oExcel = _ExcelBookOpen($sFilePath1)


If @error = 1 Then
MsgBox(0, "Errore!", "Impossibile aprire il file dal desktop")

ElseIf @error = 2 Then
While 1
if not StringIsDigit($numeroconcorrenti) Then $numeroconcorrenti = ""
$numeroconcorrenti= InputBox("concorrenti", "inserire il numero dei concorrenti", $numeroconcorrenti, "", _
100, 100,@DesktopWidth/3,@DesktopHeight/3)
If @error = 1 Then
Exit
if not StringIsDigit($numeroconcorrenti) Then $numeroconcorrenti = ""
EndIf
;MsgBox(0, "ok", "fin qui tutto bene",2)
if StringIsDigit($numeroconcorrenti) Then ExitLoop
WEnd

$oExcel = _ExcelBookNew()
_ExcelBookSaveAs($oExcel, @DesktopCommonDir & "\BUONTEMPO.xls")
_ExcelSheetActivate($oExcel, 1)
_ExcelSheetNameSet($oExcel, "tempi")
_ExcelHorizontalAlignSet($oExcel, 1, 1,$numeroconcorrenti+10, 10, "center") ;Centro le celle su Exel
_ExcelWriteCell($oExcel, "POSIZIONE ARRIVO", 3, 2) ;scrive posizione "arrivo" su Exel
_ExcelWriteCell($oExcel, "ORA PARTENZA", 1, 4) ;scrive su Exel
_ExcelWriteCell($oExcel, "ORA ARRIVO", 3, 4) ;scrive su Exel
_ExcelWriteCell($oExcel, "N°MAGLIETTA", 3, 6) ;scrive "maglietta" su Exel
_ExcelWriteCell($oExcel, "NOME", 3, 8) ;scrive "nome" su Exel
_ExcelWriteCell($oExcel, "TEMPO IMPIEGATO", 3, 10) ;scrive su Exel
_ExcelWriteCell($oExcel, $numeroconcorrenti, 2, 2) ;scrive su Exel
_ExcelWriteCell($oExcel, "NUMERO CONCORRENTI", 1, 2) ;scrive su Exel




_ExcelSheetActivate($oExcel, 2)
_ExcelSheetNameSet($oExcel, "concorrenti")
_ExcelHorizontalAlignSet($oExcel, 1, 1,$numeroconcorrenti+10, 10, "center")
For $riga2 = 1 To $numeroconcorrenti ;scrive le posizioni di arrivo
$posiz2 += 1
_ExcelWriteCell($oExcel, $riga2, $posiz2, 2) ;Write to the Cell
Next
_ExcelSheetActivate($oExcel, 1)

EndIf






main()
Func main()
_ExcelBookSave($oExcel)
_ExcelSheetActivate($oExcel, 1)
$numeroconcorrenti= _ExcelReadCell($oExcel, 2, 2)

GUISetState(@SW_HIDE,"BUONTEMPO inserimento nomi")
GUISetState(@SW_HIDE,"BUONTEMPO tempi arrivo")

$BUONTEMPO1=GUICreate("BUONTEMPO",500,300,@DesktopWidth/5,@DesktopHeight/5)
WinSetTrans ($BUONTEMPO1,"BUONTEMPO",0)
GUISetFont (20)
$pulsante1 = GUICtrlCreateButton("inserisci i numeri maglietta in riferimento al nome",90,40, 330, 72,$BS_MULTILINE)
$pulsante2 = GUICtrlCreateButton("parti con la gara",90,140, 330,72,$BS_MULTILINE)
GUISetState()
for $diss=0 to 255 step 3
WinSetTrans ($BUONTEMPO1,"BUONTEMPO",$diss)
Next

GUISwitch($BUONTEMPO1)
GUISetState(@SW_SHOW,"BUONTEMPO")
WinSetOnTop("BUONTEMPO", "", 1)
While 1
Sleep(50)

$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Select
Case $msg = $pulsante1 ;scrive la maglietta e l'ora su exel
ins_concorrenti()
Case $msg = $pulsante2 ;scrive la maglietta sull'ultima posizione
tempi_arrivo()

EndSelect

WEnd
quit()
EndFunc

Func tempi_arrivo()

GUISetState(@SW_SHOW,"BUONTEMPO tempi arrivo")
GUISetState(@SW_HIDE,"BUONTEMPO")
_ExcelSheetActivate($oExcel, 1)

$vecchiotempo= _ExcelReadCell($oExcel, 2, 4)
if $vecchiotempo<>0 Then

$start=MsgBox(4, "START", " la gara parte adesso?"& @LF & @LF &"SI = scrive l'ora di partenza"& @LF &"NO= continua la gara")
if $start=6 Then
$tTime =_Date_Time_GetLocalTime()
$aTime = _Date_Time_SystemTimeToArray($tTime)
$tp = $aTime[3]
$tp &= "."
$tp &= $aTime[4]
$tp &= "."
$tp &= $aTime[5]
_ExcelWriteCell($oExcel,$tp, 2, 4) ;scrive l'ora di partenza
EndIf
Else
$start=MsgBox(0, "START", "premi OK quando parte la gara")

if $start=1 Then
$tTime =_Date_Time_GetLocalTime()
$aTime = _Date_Time_SystemTimeToArray($tTime)
$tp = $aTime[3]
$tp &= "."
$tp &= $aTime[4]
$tp &= "."
$tp &= $aTime[5]
_ExcelWriteCell($oExcel,$tp, 2, 4) ;scrive l'ora di partenza
EndIf

EndIf


For $riga = 1 To $numeroconcorrenti ;scrive le posizioni di arrivo e la formula per la differenza tempo

$posiz += 1
$core = "=D"
$core &= $posiz
$core &= "-D2"

_ExcelWriteCell($oExcel,$core, $posiz, 10) ;scrive su Exel
_ExcelWriteCell($oExcel, $riga, $posiz, 2) ;Write to the Cell
Next

$BUONTEMPO3=GUICreate("BUONTEMPO tempi arrivo",@DesktopWidth/3,600,@DesktopWidth/1.5,0)

GUISetFont (25)
$labelmaglietta = GUICtrlCreateLabel("N°MAGLIETTA",20,30, 280, 65, $SS_CENTER )

$ins_maglietta = GUICtrlCreateInput("",20, 110, 300, 72,$SS_CENTER)
GUICtrlSetTip(-1, "inserisci quì il numero della maglietta poi clicca 'ARRIVO!'")
GUICtrlSetState(-1, $GUI_FOCUS)
GUISetFont (30)
$pulsante1 = GUICtrlCreateButton("ARRIVO!",20,280, 300, 72)
GUISetFont (15)
$pulsante2 = GUICtrlCreateButton("INSERISCI IL NUMERO DELLA MAGLIETTA DEGLI ULTIMI ARRIVATI",20,480, 300,108,$BS_MULTILINE)
GUISetFont (20)
$pulsante3 = GUICtrlCreateButton("CANCELLA ULTIMO ARRIVO",20,380, 300,72,$BS_MULTILINE)
GUISetFont (30)
GUISetState()
GUISwitch($BUONTEMPO3)
WinSetOnTop("BUONTEMPO tempi arrivo", "", 1)
;-----------------------------------------------------------------------------



for $x=4 to $numeroconcorrenti+4
$c=$x
$sCellValue = _ExcelReadCell($oExcel, $x, 4)
If $sCellValue = 0 Then maintempi()
Next

EndFunc


Func maintempi()
HotKeySet("{ENTER}","puls2")
GUISetState(@SW_HIDE,"BUONTEMPO tempi arrivo")
GUISetState(@SW_SHOW,"BUONTEMPO tempi arrivo")



$x=$c

GUISwitch($BUONTEMPO3)
GUICtrlSetState($ins_maglietta, $GUI_FOCUS)



While 1

sleep(33)

if $inc = 20 then visualizzatempo()
$inc = $inc+1

$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
$data = GUICtrlRead($ins_maglietta)
Select
Case $msg = $pulsante1
puls1()
Case $msg = $pulsante2 ;scrive la maglietta sull'ultima posizione
puls2()
Case $msg = $pulsante3
puls3()
EndSelect

WEnd
main()
EndFunc



Func puls1()
$data = GUICtrlRead($ins_maglietta)
if StringIsDigit($data)=0 Then $data=""
for $trovadoppi=4 to $numeroconcorrenti+4
$sCellValue99 = _ExcelReadCell($oExcel,$trovadoppi, 6)
if $data="" Then ExitLoop
if $sCellValue99=$data Then

MsgBox(0, "attenzione", "concorrente inserito 2 volte!",2,$BUONTEMPO3)
_ExcelWriteCell($oExcel,"n°"&$sCellValue99&" doppio!",$c, 7)
for $z=4 to $numeroconcorrenti+4
$sCellValue999 = _ExcelReadCell($oExcel,$z, 6)
if $sCellValue999=$data Then _ExcelWriteCell($oExcel,"n°"&$sCellValue999&" doppio!",$z, 7)

Next
ExitLoop
EndIf
Next


_ExcelSheetActivate($oExcel,2)

$sCellValue54 = _ExcelReadCell($oExcel, $data, 4)
_ExcelSheetActivate($oExcel, 1)
if not $sCellValue54=0 Then _ExcelWriteCell($oExcel,$sCellValue54,$c, 8)




GUICtrlSetData($visualizza_maglietta, $data)
_ExcelWriteCell($oExcel,$data3, $c, 4)
_ExcelWriteCell($oExcel,$data, $c, 6) ;Write to the Cell
$c += 1

if $data>$numeroconcorrenti Then
MsgBox(0, "attenzione numero troppo alto!","eccede il numero dei concorrenti!",3)
_ExcelWriteCell($oExcel,"!", $c-1, 7) ;Write to the Cell
EndIf
GUICtrlSetData($ins_maglietta, "")
GUICtrlSetState($ins_maglietta, $GUI_FOCUS)

_ExcelBookSave($oExcel)

EndFunc


Func puls2()
HotKeySet("{ENTER}")

for $cerca = $numeroconcorrenti+4 to 4 Step -1
$sCellValue2 = _ExcelReadCell($oExcel,$cerca, 6)
If $sCellValue2 <> 0 Then ExitLoop
Next

$c=$cerca+1




While 1
$sCellValue4 = _ExcelReadCell($oExcel,$c, 4)
if $sCellValue4 = 0 Then ExitLoop
Sleep(200)

$ultimiarrivi= InputBox("ultimi arrivi", "inserire il numero degli ultimi arrivati", $ultimiarrivi, "",100, 100,@DesktopWidth/5,@DesktopHeight/5,$BUONTEMPO3)
If @error = 1 Then
GUISwitch($BUONTEMPO3)
GUICtrlSetState($ins_maglietta, $GUI_FOCUS)
$c += 1
ExitLoop
EndIf

for $y=4 to $numeroconcorrenti+4
$sCellValue888 = _ExcelReadCell($oExcel,$y, 6)
if $ultimiarrivi="" Then ExitLoop
if $sCellValue888=$ultimiarrivi Then _ExcelWriteCell($oExcel,"n°"&$sCellValue888&" doppio!",$y, 7)

Next

$data99 = GUICtrlRead($ultimiarrivi)

if $ultimiarrivi>$numeroconcorrenti Then
MsgBox(0, "attenzione numero troppo alto!","eccede il numero dei concorrenti!",3)
_ExcelWriteCell($oExcel,"!",$c, 7)
EndIf
$data99 = GUICtrlRead($ultimiarrivi)
for $trovadoppi2=4 to $numeroconcorrenti+4
if $ultimiarrivi="" Then ExitLoop
$sCellValue9 = _ExcelReadCell($oExcel,$trovadoppi2, 6)
if $sCellValue9=$ultimiarrivi Then

MsgBox(0, "attenzione", "concorrente inserito 2 volte!",2,$BUONTEMPO3)
_ExcelWriteCell($oExcel,"n°"&$ultimiarrivi&" doppio!",$c, 7)
ExitLoop
EndIf
next



if StringIsDigit($ultimiarrivi) Then
_ExcelWriteCell($oExcel,$ultimiarrivi, $c, 6) ;Write to the Cell
$c += 1
$data54 = GUICtrlRead($ultimiarrivi)
_ExcelSheetActivate($oExcel, 2)
$sCellValue55 = _ExcelReadCell($oExcel,$ultimiarrivi, 4)
_ExcelSheetActivate($oExcel, 1)
if not $sCellValue55=0 Then _ExcelWriteCell($oExcel,$sCellValue55,$c-1, 8)
EndIf

if not StringIsDigit($ultimiarrivi) Then
MsgBox(0, "attento","solo numeri!",2)
EndIf


$sCellValue3 = _ExcelReadCell($oExcel,$c, 4)
if $sCellValue3 = 0 Then
GUISwitch($BUONTEMPO3)
GUICtrlSetState($ins_maglietta, $GUI_FOCUS)
ExitLoop
EndIf


WEnd
EndFunc

Func puls3()


for $cerca3 = $numeroconcorrenti+4 to 4 Step -1
$sCellValue33 = _ExcelReadCell($oExcel,$cerca3, 4)
If $sCellValue33 <> 0 Then ExitLoop
Next

$c=$cerca3

if $c=3 Then $c=4
_ExcelWriteCell($oExcel,"", $c, 4)
_ExcelWriteCell($oExcel,"", $c, 6)
_ExcelWriteCell($oExcel,"", $c, 7)
_ExcelWriteCell($oExcel,"", $c, 8)
EndFunc


Func ins_concorrenti()
HotKeySet("{ENTER}")
GUISetState(@SW_HIDE,"BUONTEMPO")
_ExcelSheetActivate($oExcel, 2)




$BUONTEMPO2=GUICreate("BUONTEMPO inserimento nomi", 680, 230, 450,200)
GUISwitch($BUONTEMPO2)
GUISetFont (15)
GUICtrlCreateLabel("N°MAGLIETTA",0,30, 200, 30, $SS_CENTER )
GUISetFont (21)
$numeromaglietta = GUICtrlCreateInput("",45, 72, 100, 43,$SS_CENTER)
GUICtrlSetTip(-1, "inserisci quì il numero della maglietta del concorrente")
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetFont (15)
GUICtrlCreateLabel("NOME CONCORRENTE",200,30, 300, 30, $SS_CENTER )
GUISetFont (21)
$nomeconcorrente = GUICtrlCreateInput("",170, 72, 480, 43,$SS_CENTER)
GUICtrlSetTip(-1, "inserisci quì il nome del concorrente")
GUISetFont (15)
$pritorno = GUICtrlCreateButton("ritorna al menù principale",44,135, 610,54,$BS_MULTILINE)

GUISetState()
WinSetOnTop("BUONTEMPO inserimento nomi", "", 1)

While 1

HotKeySet("{ENTER}", "enter")

$msg2 = GUIGetMsg()
If $msg2 = $GUI_EVENT_CLOSE Then ExitLoop
If $msg2 = $pritorno Then ExitLoop


WEnd
main()

EndFunc




Func enter()
if not StringIsDigit($numeromaglietta) Then $numeromaglietta = ""
for $x2 =1 to $numeroconcorrenti
$sCellValue = _ExcelReadCell($oExcel, $x2, 2)
If $sCellValue = GUICtrlRead($numeromaglietta) Then
_ExcelWriteCell($oExcel,GUICtrlRead($nomeconcorrente),$x2, 4) ;Write to the Cell
$numeromagliettaadd=$x2+1
EndIf
Next


GUICtrlSetData ($numeromaglietta,$numeromagliettaadd)
GUICtrlSetState($numeromaglietta, $GUI_FOCUS)
EndFunc



Func visualizzatempo()

$n = GUICtrlCreateDate("", 2230, 230, 100, 20, $DTS_TIMEFORMAT)
$data3 = GUICtrlRead($n)
GUICtrlSetData ($visualizza_tempo, $data3)

$visualizza_tempo3 = GUICtrlCreateLabel($data3,30, 210, 300, 65, $SS_CENTER )

$inc = 1


$pippo=$c-1
$sCellValue12 = _ExcelReadCell($oExcel,$pippo, 4)
$sCellValue22 = _ExcelReadCell($oExcel,$pippo, 6)
If $sCellValue22<>0 Then
GUICtrlSetState ($pulsante2,$GUI_HIDE)
Else
GUICtrlSetState ($pulsante2,$GUI_SHOW)
EndIf
EndFunc

Func quit()
GUISetState(@SW_HIDE,"BUONTEMPO tempi arrivo")
$fine =MsgBox(4, "fine", "vuoi associare il numero maglietta arrivato al nome concorrente?")
if $fine=6 Then associa()
MsgBox(0, "ciao", "adesso trovi il file compilato nel desktop!",3)
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel,1,0)

Exit
EndFunc

Func associa()
_ExcelSheetActivate($oExcel, 1)
$numeroconcorrenti= _ExcelReadCell($oExcel, 2, 2)
for $cv=4 to $numeroconcorrenti+3

_ExcelSheetActivate($oExcel, 1)
$leggivuoti = _ExcelReadCell($oExcel,$cv, 8)

If $leggivuoti=0 Then
$leggivuoti2 = _ExcelReadCell($oExcel,$cv, 6)
if not $leggivuoti2=0 then
_ExcelSheetActivate($oExcel, 2)
$leggivuoti3 = _ExcelReadCell($oExcel,$leggivuoti2, 4)
_ExcelSheetActivate($oExcel, 1)
_ExcelWriteCell($oExcel,$leggivuoti3,$cv, 8)
EndIf
EndIf
Next

MsgBox(0, "ciao", "adesso trovi il file compilato nel desktop!",3)
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel,1,0)
Exit
EndFunc
 
Top
xMasteRx
CAT_IMG Posted on 25/1/2011, 20:50     +1   -1




sembra buono ^^
però credo io fossi meglio se tu creassi una ListView anziché usare excel lol
 
Top
CAT_IMG Posted on 25/1/2011, 21:07     +1   -1

Agli inizi

Group:
Member
Posts:
15
Reputazione:
+1

Status:


Ok
ma sai essendo alle "prime armi" non ho valutato altre possibilità
ho usato exel come database e l'utente finale lo voleva impaginare e stampare..
nella prima pagina ho inserito l'ora di partenza gara e i numeri dei concorrenti
nel secondo layer exel ho inserito i nomi dei concorrenti in riferimento al numero maglietta
quando inizi ti chede se partire o definire da subito i nomi/maglietta (altrimanti lo fai dopo, durante la gara)
durante la gara si accorge se inserisci i nnumeri due volte e ti avverte, controlla se il numero inserito è piu grande del numero dei concorrenti, puoi cancellare l'ultima inserzione e puoi inserire "il numero gli ultimi arrivati" dopo aver già scritto l'ora (di arrivo)
poi alla fine ti inserisce i nomi dei concorrenti nella posizione di arrivo (li associa)
e salva il file .xls sul desktop

sono interessato a critiche per migliorare il programma (anche se ormai non intendo svilupparlo +) piuttosto per ampliare le possibilità di lavoro con autoit
 
Top
3ad
CAT_IMG Posted on 25/1/2011, 21:32     +1   -1




Non male :P
 
Top
T3rrorisT
CAT_IMG Posted on 25/1/2011, 21:44     +1   -1




bello ma sicuro che sia tuo? XD Mi sembra abbastanza complicato per uno che ha appena iniziato :)
 
Top
/dev/random
CAT_IMG Posted on 25/1/2011, 21:51     +1   -1




Non è che sia complicato, è solo lungo e noioso xD
 
Top
xMasteRx
CAT_IMG Posted on 25/1/2011, 22:23     +1   -1




CITAZIONE (/dev/random @ 25/1/2011, 21:51) 
Non è che sia complicato, è solo lungo e noioso xD

quoto XD
 
Top
6 replies since 25/1/2011, 20:45   269 views
  Share