Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando
-- Tutorial de iniciación a Autoit --
Volver al índice del tutorial
____________________________
27.- Bucle For ... Next. While ... When.
___________________________________________
1.- Bucle For ... Next.
- Va acumulando en la variable $todo cada una de las multiplicaciones. Las va mostrando poco a poco.
Bucle For ... Next |
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tabla de multiplicar - Juan A. Villalpando", 434, 426, 192, 132)
$Label1 = GUICtrlCreateLabel("Escribe un número del 1 al 12", 32, 24, 178, 20)
$Input1 = GUICtrlCreateInput("4", 224, 24, 145, 24)
$Button1 = GUICtrlCreateButton("Pulsa", 128, 72, 153, 49)
$Label2 = GUICtrlCreateLabel("Label2", 48, 168, 333, 332)
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
$multiplicando = 0
$multiplicacion = 0
$todo = ""
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
$multiplicando = GUICtrlRead($Input1)
If $multiplicando > 12 Then
MsgBox(0, "Error.", "Número demasiado grande.")
Else
GUICtrlSetState($Button1, $GUI_HIDE) ; Oculta el botón.
$todo = ""
For $n = 1 to 10
$multiplicacion = $multiplicando * $n
$todo = $todo & $multiplicando & " x " & $n & " = " & $multiplicacion & @CRLF
GUICtrlSetData($Label2, $todo)
Sleep (500) ; Poco a poco.
Next
GUICtrlSetState($Button1, $GUI_SHOW) ; Muestra el botón.
Beep(500, 1000) ; Sonido final.
EndIf
EndSelect
Wend
Exit
|
___________________________________________
2.- Bucle While ... Wend.
Bucle While ... Wend |
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tabla de multiplicar - Juan A. Villalpando", 434, 426, 192, 132)
$Label1 = GUICtrlCreateLabel("Escribe un número del 1 al 12", 32, 24, 178, 20)
$Input1 = GUICtrlCreateInput("4", 224, 24, 145, 24)
$Button1 = GUICtrlCreateButton("Pulsa", 128, 72, 153, 49)
$Label2 = GUICtrlCreateLabel("Label2", 48, 168, 333, 332)
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
$multiplicando = 0
$multiplicacion = 0
$todo = ""
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
$multiplicando = GUICtrlRead($Input1)
If $multiplicando > 12 Then
MsgBox(0, "Error.", "Número demasiado grande.")
Else
GUICtrlSetState($Button1, $GUI_HIDE) ; Oculta el botón.
$todo = ""
$n = 1
While $n < 10
$multiplicacion = $multiplicando * $n
$todo = $todo & $multiplicando & " x " & $n & " = " & $multiplicacion & @CRLF
GUICtrlSetData($Label2, $todo)
Sleep (500) ; Poco a poco.
$n = $n + 1
Wend
GUICtrlSetState($Button1, $GUI_SHOW) ; Muestra el botón.
Beep(500, 1000) ; Sonido final.
EndIf
EndSelect
Wend
Exit
|
___________________________________________
3.- If... Then
_________________
|