ยินดีต้อนรับแขกผู้มาเยือน กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน
ส่งอีเมล์ยืนยันการใช้งาน?
 
Please Login!

ผู้เขียน หัวข้อ: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)  (อ่าน 4833 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)
« ตอบกลับ #20 เมื่อ: 02 มีนาคม 2012, 12:02:18 »
ความรู้เพิ่มเติมเกี่ยวกับตัวแปร Global

ท่านทราบหรือไม่ว่า.. เมื่อใด? ที่เราจำเป็นตัองประกาศตัวแปรไว้เป็น Global

ประกาศไว้เป็นตัวแปรชนิดอื่นไม่ได้ ทั้งๆที่มีตัวแปรให้เลือกใช้อยู่หลายชนิด

คำตอบ คือ ถ้าเขียนคำสั่งต่างๆออกมาเป็นรูปแบบ Function

ตัวแปรของ Object ต่างๆที่อยู่ใน Function นั้นๆ จะถูกจำกัดวงให้ทำงานเฉพาะในฟังก์ชั่นที่ตัวเองอยู่เท่านั้น

ไม่สามารถทำงานข้ามไปฟังก์ชั่นอื่นได้ เหมือนกับจะเข้าไปในบ้านใคร ก็ต้องบอกให้เจ้าของบ้านทราบก่อน

ลองดูกับโคีดด้านล่าง ..ถ้าเราไม่ประกาศตัวแปรเป็น Global ให้ Object จะเกิดอะไร?ขึ้น

โค๊ด: [Select]
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

main()
Func main()
    GUICreate("Form1", 242, 107, 192, 124)
    Local $Progress1 = GUICtrlCreateProgress(16, 24, 206, 17)
    Local $Progress2 = GUICtrlCreateProgress(16, 64, 206, 17)
    GUICtrlSetData(-1, 100)
GUISetState(@SW_SHOW)
    _Progress1()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
        EndSwitch
    WEnd
EndFunc

Func _Progress1()
For $i = 0 To 100
GUICtrlSetData($Progress1, $i)
Sleep(100)
Next
   _Progress2()
EndFunc

Func _Progress2()
For $i = 100 To 0 Step -1
GUICtrlSetData($Progress2, $i)
Sleep(100)
Next
EndFunc
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 02 มีนาคม 2012, 13:22:54 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • OS: WindowsBrowser: Firefox
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)
« ตอบกลับ #21 เมื่อ: 02 มิถุนายน 2012, 12:41:50 »
ตัวอย่างการขียนคำสั่ง: ลงทะเบียนโปรแกรมในรีจิสรีย์ (Register to Registry)

โค๊ด: [Select]
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$RootKey   = "HKEY_LOCAL_MACHINE\SOFTWARE"
$KeyName   = "HKEY_LOCAL_MACHINE\SOFTWARE\TestRegister"
$UseValueName = "User"
$PassValueName = "Serial"
$TypeName  = "REG_SZ"
MsgBox(64, "User Info", "2ช่องต่อไปนี้เป็นการตั้งชื่อและพาสเวิร์ดของผู้ใช้"&@CrLf& _
                          "ถ้าตั้งชื่อและพาสเวิร์ดไว้แล้วก็จะข้ามไปที่ช่องตรวจสอบ")
For $i = 1 To 100
    $Ret = RegEnumKey($RootKey, $i)
If $Ret = "TestRegister" Then
   ;MsgBox(0, "", $Ret)
ExitLoop       ;ถ้ายังไม่มีการสร้างโฟลเดอร์เก็บข้อมูล โปรแกรมจะสร้างให้อัตโนมัติ.
ElseIf $Ret = "" Then
$UseVar = InputBox("User Confirm", "Enter: Your name", "", "", 200, 115, 300, 300)
If $UseVar = "" Then Exit
RegWrite($KeyName, $UseValueName, $TypeName, $UseVar)
$PassVar = InputBox("Password Confirm", "Enter: Your Password", "", "", 200, 115, 300, 300)
If $PassVar = "" Then Exit
RegWrite($KeyName, $PassValueName, $TypeName, $PassVar)
ExitLoop
EndIf
Next
MsgBox(64, "User Info", "ขั้นตอนต่อไปนี้ เป็นการตรวจสอบ User name และ Password ที่สร้างไว้")

$i = 0
Do
   $i += 1
   $RnumVal = RegEnumVal($KeyName, $i)
$Rread = RegRead($KeyName, $RnumVal)
    If $Rread <> "" Then
    ExitLoop
Else
Exit
    EndIf
Until $RnumVal = ""

$Form1 = GUICreate("Register Software Sample", 304, 126, -1, -1)
$Input1 = GUICtrlCreateInput("", 112, 16, 121, 21)
$Input2 = GUICtrlCreateInput("", 112, 48, 121, 21)
$Label1 = GUICtrlCreateLabel("Usename:", 56, 16, 52, 17)
$Label2 = GUICtrlCreateLabel("Password:", 56, 48, 53, 17)
$Button1 = GUICtrlCreateButton("OK", 136, 88, 75, 25)
$Label3 = GUICtrlCreateLabel("Reset Password", 8, 96, 81, 17)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
        Case $Button1
If GUICtrlRead($Input1) = RegRead($KeyName, $UseValueName) And _
   GUICtrlRead($Input2) = RegRead($KeyName, $PassValueName) Then
   MsgBox(64, "", "ข้อมูลถูกต้อง")
Else
    MsgBox(0, "", "ข้อมูลผิด! ลองใหม่")
EndIf
Case $Label3
RegDelete($KeyName)
If Not @error Then MsgBox(64, "", "ลบข้อมูลเรียบร้อย")
GUIDelete()
Exit
EndSwitch
WEnd
Coolfirmed by (0)สมาชิก:
 
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • OS: WindowsBrowser: Firefox
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)
« ตอบกลับ #22 เมื่อ: 09 มิถุนายน 2012, 21:01:09 »
Loop InputBox

โค๊ด: [Select]
Do
    $Ret = InputBox("Loop Input", "Enter: Yourname", "", "", 200, 116, 400, 300)
    If @error = 1 Then ExitLoop
    Select
        Case $Ret = ""
            MsgBox(0, "", "Press yourname in to the box")
Case Else
            MsgBox(64, "Info", "Yourname is " & $Ret)
    EndSelect
Until $Ret <> ""
OR
โค๊ด: [Select]
Do
    $Ret = InputBox("Loop Input", "Enter: Yourname", "", "", 200, 116, 400, 300)
    If @error = 1 Then ExitLoop
    Switch $Ret
        Case ""
            MsgBox(0, "", "Press yourname in to the box")
        Case Else
            MsgBox(64, "Info", "Yourname is " & $Ret)
    EndSwitch
Until $Ret <> ""
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 12 มิถุนายน 2012, 04:47:59 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • OS: WindowsBrowser: Firefox
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)
« ตอบกลับ #23 เมื่อ: 05 มีนาคม 2013, 19:43:22 »
OemLogo Creater: โปรแกรมสร้างโลโก้และรายละเอียดลงใน System Properties

โค๊ด: [Select]
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $sINI = Concat(@SystemDir, "\oeminfo.ini")
Global $Image = Concat(@SystemDir, "\oemlogo.bmp")
Global $Section1 = "General", $Section2 = "Support Information"
Global $sFile = ConCat(@SystemDir, "\readme.txt")
Global $OemLogo = ConCat(@SystemDir, "\oemlogo.bmp")
Global $fLine, $i, $fLine, $nMsg, $sData2 = ""
Global $sFile = @SystemDir & "\oeminfo.txt"
Global $bmpPicture = ConCat(@SystemDir, "\oemlogo.bmp")

Global $hGui = GUICreate("OEMLogo Creater", 400, 417, -1, -1)
GUICtrlCreateLabel("Manufacturer :", 16, 16, 73, 17)
Global $Input1 = GUICtrlCreateInput("", 90, 13, 289, 21)
GUICtrlCreateLabel("Model :", 39, 41, 39, 17)
Global $Input2 = GUICtrlCreateInput("", 90, 38, 289, 21)
GUICtrlCreateLabel("Support info :", 16, 61, 67, 17)
Global $hEdit = GUICtrlCreateEdit("", 88, 64, 258, 145)
Global $Btn_txt = GUICtrlCreateButton("...", 352, 72, 23, 21)
GUICtrlCreateLabel("Open logo :", 19, 222, 59, 17)
Global $Inp_picture = GUICtrlCreateInput("", 88, 219, 257, 21)
Global $Btn_Logo = GUICtrlCreateButton("...", 355, 218, 23, 21)
GUICtrlCreateGraphic(88, 245, 182, 112, BitOR($SS_ETCHEDFRAME,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlCreateLabel("Logo preview :", 12, 248, 74, 17)
GUICtrlCreateLabel("Image(180 x114)", 140, 300, 100, 17)
Global $Btn_Save = GUICtrlCreateButton("Save", 16, 376, 75, 25)
GUICtrlSetCursor (-1, 0)
Global $Btn_del = GUICtrlCreateButton("Delete", 112, 376, 75, 25)
GUICtrlSetCursor (-1, 0)
Global $Btn_view = GUICtrlCreateButton("Test", 208, 376, 75, 25)
GUICtrlSetCursor (-1, 0)
Global $Btn_close = GUICtrlCreateButton("Exit", 304, 376, 75, 25)
GUICtrlSetCursor (-1, 0)
Global $hPic = GUICtrlCreatePic("", 128, 256, 100, 100)
GUISetState(@SW_SHOW)

_ReadOemInfo()

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $Btn_close
      GUIDelete()
      ExitLoop
        Case $Btn_Logo
            Dim $ImagePath
      $ImagePath = FileOpenDialog("Choose Picture", Concat(@DesktopDir,"\"), "Images File (*.bmp)", 1 + 4, "", $hGui)
      If $ImagePath Then
          GUICtrlSetData($Inp_picture, $ImagePath)
          GUICtrlSetImage($hPic, $ImagePath)
      EndIf
    Case $Btn_txt
      Dim $text, $files, $read
      $text = FileOpenDialog("Choose Text", Concat(@DesktopDir,"\"), "Text File (*.txt)", 1 + 4, "", $hGui)
      If $text Then
         $files = FileOpen($text, 0)
        $read = FileRead($files)
        GUICtrlSetData($hEdit, $read)
        FileClose($files)
      EndIf
    Case $Btn_Save
      If FileExists($sINI) Then FileDelete($sINI)
      _WriteOemInfo()
    Case $Btn_del
      _DelOemInfo()
    Case $Btn_view
        ShellExecute("sysdm.cpl")
    EndSwitch
WEnd

Global $data1, $data2
Func ConCat($data1="", $data2="")
  Return ($data1&$data2)
EndFunc

Func _ReadOemInfo()
    Local $array[31]
    Local $Section = "Support Information"
    Local $aData = ""
    GUICtrlSetData($Input1, IniRead($sINI, "General", "Manufacturer", ""))
    GUICtrlSetData($Input2, IniRead($sINI, "General", "Model", ""))
    $array[0] = IniRead($sINI, $Section, "Line1", "")
    $array[1] = IniRead($sINI, $Section, "Line2", "")
    $array[2] = IniRead($sINI, $Section, "Line3", "")
    $array[3] = IniRead($sINI, $Section, "Line4", "")
    $array[5] = IniRead($sINI, $Section, "Line5", "")
    $array[4] = IniRead($sINI, $Section, "Line6", "")
    $array[5] = IniRead($sINI, $Section, "Line7", "")
    $array[6] = IniRead($sINI, $Section, "Line8", "")
    $array[7] = IniRead($sINI, $Section, "Line9", "")
    $array[8] = IniRead($sINI, $Section, "Line10", "")
    $array[9] = IniRead($sINI, $Section, "Line11", "")
    $array[10] = IniRead($sINI, $Section, "Line12", "")
    $array[11] = IniRead($sINI, $Section, "Line13", "")
    $array[12] = IniRead($sINI, $Section, "Line14", "")
    $array[13] = IniRead($sINI, $Section, "Line15", "")
    $array[14] = IniRead($sINI, $Section, "Line16", "")
    $array[15] = IniRead($sINI, $Section, "Line17", "")
    $array[16] = IniRead($sINI, $Section, "Line18", "")
    $array[17] = IniRead($sINI, $Section, "Line19", "")
    $array[18] = IniRead($sINI, $Section, "Line20", "")
    $array[19] = IniRead($sINI, $Section, "Line21", "")
    $array[20] = IniRead($sINI, $Section, "Line22", "")
    $array[21] = IniRead($sINI, $Section, "Line23", "")
    $array[22] = IniRead($sINI, $Section, "Line24", "")
    $array[23] = IniRead($sINI, $Section, "Line25", "")
    $array[24] = IniRead($sINI, $Section, "Line26", "")
    $array[25] = IniRead($sINI, $Section, "Line27", "")
    $array[26] = IniRead($sINI, $Section, "Line28", "")
    $array[27] = IniRead($sINI, $Section, "Line29", "")
    $array[28] = IniRead($sINI, $Section, "Line30", "")
$array[29] = IniRead($sINI, $Section, "Line31", "")
For $i = 0 To UBound($array)-1
        $aData &= $array[$i] & @CRLF
Next
        GUICtrlSetData($hEdit, $aData)
GUICtrlSetImage($hPic, $Image)
EndFunc

Func _WriteOemInfo()
    IniWrite($sINI, $Section1, "Manufacturer", GUICtrlRead($Input1))
    IniWrite($sINI, $Section1, "Model", GUICtrlRead($Input2))
    FileWrite($sFile, ControlGetText($hGui, "", $hEdit))
    If Not @error Then
For $i = 1 to 30
        $fLine =FileReadLine($sFile, $i)
        $sData2 &= "LINE" & $i & "=" & $fLine & @CRLF
Next
FileClose($fLine)
FileDelete($sFile)
IniWriteSection($sINI, $Section2, $sData2)
        If GUICtrlRead($Inp_picture)<> "" Then FileCopy($ImagePath, $bmpPicture, 1)
EndIf
EndFunc

Func _DelOemInfo()
    FileDelete($sINI)
  GUICtrlSetData($Input1, "")
  GUICtrlSetData($Input2, "")
  GUICtrlSetData($hEdit, "")
  GUICtrlSetData($Inp_picture, "")
  FileDelete($bmpPicture)
  GUICtrlSetImage($hPic, "")
EndFunc
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 05 มีนาคม 2013, 21:32:28 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ BHNJMK18

  • นักเรียนอนุบาล
  • *
  • โพสต์: 4
  • คูลเฟิร์ม: 3
  • zula: 1.5
    • ดูรายละเอียด
  • OS: WindowsBrowser: Chrome

  • ล็อคอิน @ 23 เมษายน 2013, 10:49:29
Re: รวมความรู้เกี่ยวกับ AutoIt ปี 2555 (Update)
« ตอบกลับ #24 เมื่อ: 23 เมษายน 2013, 07:27:24 »
ขอบใจมากครับผม
Coolfirmed by (0)สมาชิก: