Jump to content

Wiki Challenge Part 2


czardas
 Share

Wiki Challenge II  

21 members have voted

  1. 1. Which of the examples (in posts 2 and 3) do you think is most suited for a beginner?

    • Example 1
      0
    • Example 2
    • Example 3
    • Example 4
    • Example 5
      0
    • Example 6


Recommended Posts

A Note to Voters
The entries for this challenge appear in the following two posts below this one. The purpose here is to demonstrate AutoIt to a beginner. The code should be easy to follow if you are a beginner. Speculation about the authors is expected, but remember it is the code you are voting for, not the person who wrote it. Before casting a vote please read the 7 criteria listed below. You are entitled to cast one vote for one piece of code which you think would make a good example for the wikipedia article.
 
A Note to Participants
Although it may be tempting, I would like it if you refrain from dropping hints to the voters once voting begins.
 
Deadline for Voting
Voting will last approximately 3 days until midnight GMT on 23rd of February.
 
In the Event of a Tie
If there is no clear winner after the period for voting has ended, finalists will be selected and voting will go to sudden death, whereby whichever of the the remaining contestants has the most votes at a time determined without forewarning by the arbiter, will be declared the winner. If it is still neck and neck after this period has elapsed, the winner will be selected using a formula.
;
$iWinner = Mod(StringLen("JohnOne" & "Xandy"), 2)
;

Now we've seen what the community can do, it's time for us MVPs to be judged by the community. What has been suggested is that a second example ought to be written to demonstrate a simple automation task to an absolute beginner. So let's show the community what we can do! You are allowed no more than 32 lines of code including comments.
 
As before, the new example should:
 
1. comply to standard coding practices
2. be easy to follow
3. do something useful
4. be of interest to a wide audience
5. comply with the rules of the forum
6. not be longer than exactly 32 lines of code
7. convey the ease of use of AutoIt to beginners
 
Names will be removed from submissions by an independant arbiter before being judged.
The community will vote for the code they like best.
Only current MVPs are allowed to enter, and no MVP is entitled to vote for the winner.
Team efforts can also be submitted.
 
The deadline for submissions will be 20th February 2015. The arbiter is jaberwacky once more. All submissions should be sent to the arbiter. The community will be given three days to vote for the winner, once jaberwacky has posted the examples we send to him. After voting has finished jaberwacky will reveal the name of the MVP whose code you like best. Good luck to everyone!
 

The winning examples from both challenges will be added to the Wikipedia page.
Edited by czardas
Link to comment
Share on other sites

Example 1

Opt('MustDeclareVars', 1) ; require that variables are decalared

#include <MsgBoxConstants.au3>  ; for MsgBox constants
#include <Date.au3>             ; for date functions

Local $sProgram = "C:\PROGRAM FILES\CCLEANER\CCLEANER.EXE " ; program to run
Local $sParm = "/auto"                                      ; parm for program
Local $iRun_Interval = 0                                    ; how often to run program

; Get user input for how often to run this program, set default to 15 minutes and only accept values between 1 and 60
While $iRun_Interval < 1 Or $iRun_Interval > 60

    $iRun_Interval = InputBox('Auto Run Interval', 'Enter # of minutes between automatic runs of' & @CRLF & _   ; continue statement on next line
            $sProgram & @CRLF & @CRLF & '              (Value must be between 1 and 60)' & @CRLF & @CRLF, 15, "", 300, 160)

    ; if the cancel button was pushed inform the user and exit in 5 seconds
    If @error = 1 Then Exit MsgBox($MB_ICONINFORMATION, 'Application Canceled', 'Application canceled by user action', 5)

    ; if anything else went wrong warn the user and wait for user input
    If @error > 1 Then Exit MsgBox($MB_ICONERROR, 'InputBox Error', 'Error = ' & @error)

WEnd

; Main Loop / wait for $iRun_Interval minutes then run program / Loop until user stops the program using the tray or kills it
Local $Last_Run = _NowCalc() ; set time of last scan to current date/time

While 1 ; loop forever

    If _DateDiff('n', $Last_Run, _NowCalc()) >= $iRun_Interval Then ; if the number of minutes from the last run is GT or EQ to the scan interval then
        _RunProgram($sProgram, $sParm)                              ;    1 - call the function to run the program with the parm
        $Last_Run = _NowCalc()                                      ;    2 - reset the date/time of last run to now
    EndIf

    Sleep(1000) ; idle the processor for 1 second

WEnd

; function to run program / requires program name and parm / the parm can be "" (blank)
Func _RunProgram($pgm, $prm)
    ShellExecute($pgm, $prm, "", "", @SW_HIDE) ; see Help file for parm definition
EndFunc   ;==>_RunProgram


Example 2

#include <Array.au3>
#include <MsgBoxConstants.au3>
Global $iInput1 = 12345, $fResult
$fResult = ConvertDatatype($iInput1, "MiB", "KiB")
If @error Then
    MsgBox($MB_ICONERROR, "ERROR", "An error has occured. Error code: " & @error)
Else
    MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), "Base 1024", $iInput1 & " MiBytes = " & $fResult)
EndIf

Func ConvertDatatype($fNumber, $sSourceBase, $sDestBase, $iPrefix = 1024, $bSuffix = True) ;binary prefix = 1024, decimal = 1000
    If Not Number($fNumber) Then Return SetError(1, 0, 0) ;check whether input of 1st parameter is a number
    If $iPrefix <> 1000 And $iPrefix <> 1024 Then Return SetError(2, 0, 0) ;check whether bases are within range of 1000 / 1024
    ;create 2 arrays for the prefix calculations, one for decimal calculation and one of binary calculation
    Local $aData_Dec[9][2] = [["B", $iPrefix ^ 0], ["KB", $iPrefix ^ 1], ["MB", $iPrefix ^ 2], ["GB", $iPrefix ^ 3], ["TB", $iPrefix ^ 4], ["PB", $iPrefix ^ 5], ["EiB", $iPrefix ^ 6], ["ZB", $iPrefix ^ 7], ["YB", $iPrefix ^ 8]]
    Local $aData_Bin[9][2] = [["B", $iPrefix ^ 0], ["KiB", $iPrefix ^ 1], ["MiB", $iPrefix ^ 2], ["GiB", $iPrefix ^ 3], ["TiB", $iPrefix ^ 4], ["PiB", $iPrefix ^ 5], ["EiB", $iPrefix ^ 6], ["ZiB", $iPrefix ^ 7], ["YiB", $iPrefix ^ 8]]
    Local $iPos1, $iPos2, $sSuffix = $bSuffix ? $sDestBase & "ytes" : "" ;declare some variables and suffix for the ouput if enabled in function parameter $bSuffix
    Switch $iPrefix ;depending on the $iPrefix variable do the calculation
        Case 1000 ;decimal
            $iPos1 = _ArraySearch($aData_Dec, $sSourceBase) ;search in the array for the source base
            If @error Then Return SetError(3, 0, 0) ;if not found exit function and set error flag
            Local $iPos2 = _ArraySearch($aData_Dec, $sDestBase) ;search in the array for the destination base
            If @error Then Return SetError(4, 0, 0) ;if not found exit function and set error flag
            Return $fNumber * $aData_Dec[$iPos1][1] / $aData_Dec[$iPos2][1] & " " & $sSuffix ;do the calculation and return the result
        Case 1024 ;binary
            $iPos1 = _ArraySearch($aData_Bin, $sSourceBase) ;search in the array for the source base
            If @error Then Return SetError(5, 0, 0) ;if not found exit function and set error flag
            Local $iPos2 = _ArraySearch($aData_Bin, $sDestBase) ;search in the array for the destination base
            If @error Then Return SetError(6, 0, 0) ;if not found exit function and set error flag
            Return $fNumber * $aData_Bin[$iPos1][1] / $aData_Bin[$iPos2][1] & " " & $sSuffix ;do the calculation and return the result
    EndSwitch
EndFunc   ;==>ConvertDatatype


Example 3

#include <File.au3>                             ; needed for _FileListToArrayRec
#include <array.au3>                            ; needed for  _ArrayToString
#include <FileConstants.au3>                    ; needed for file constants (FileOpen)
#include<MsgBoxConstants.au3>                   ; needed for message box constants

Local $sOutFl = @ScriptDir & '\FileList.txt'    ; output file for file list (@ScriptDir = the directory that the script runs in)
Local $sDir = 'K:\'                             ; top level dir to start search

Local $aFLst = _FileListToArrayRec($sDir, '*.au3', $FLTAR_FILES, $FLTAR_RECUR, Default, $FLTAR_FULLPATH)

if @ERROR = 1 then exit (msgbox($MB_ICONERROR,'ERROR','Error returned from _FileListToArrayRec = ' & @EXTENDED))

Local $hFL = FileOpen($sOutFl, $FO_OVERWRITE)   ; open file for write (erases file)

if $hFL = -1 then exit (msgbox($MB_ICONERROR,'ERROR','FileOpen failed for file = ' & $sOutFl))

FileWrite($hFL, _ArrayToString($aFLst, @CRLF))  ; write file converting array returned from  _FileListToArrayRec to a CRLF delimited string
FileClose($hFL)                                 ; close file
ShellExecute($sOutFl)                           ; display file
Edited by jaberwacky
Link to comment
Share on other sites

Example 4

#include <GDIPlus.au3>

_GDIPlus_Startup()
Global $hBitmap_YinYang = _GDIPlus_BitmapCreateYinYang(500)
_GDIPlus_ImageSaveToFile($hBitmap_YinYang, @ScriptDir & "\YinYang.png")
ShellExecute(@ScriptDir & "\YinYang.png")
_GDIPlus_BitmapDispose($hBitmap_YinYang)
_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateYinYang($iSize, $fAngle = 0)
    If Not IsNumber($iSize) Or Not IsNumber($fAngle) Then Return SetError(1, 0, 0)
    $iSize = ($iSize < 10) ? 10 : ($iSize > 5000) ? 5000 : $iSize  ;limit image dimensions
    Local $iW = $iSize - 1, $iH = $iSize - 1 ;minus 1 to fit the ellipse border to visible area
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW + 1, $iH + 1)
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    Local Const $hPen = _GDIPlus_PenCreate(0xFF000000), $hBrushB = _GDIPlus_BrushCreateSolid(), $hBrushW = _GDIPlus_BrushCreateSolid(0xFFFFFFFF), $hMatrix = _GDIPlus_MatrixCreate(), $hPath = _GDIPlus_PathCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $iW / 2, $iH / 2) ;move graphics to the center otherwise rotation is at 0,0
    _GDIPlus_MatrixRotate($hMatrix, $fAngle) ;rotate graphic
    _GDIPlus_GraphicsSetTransform($hGfx, $hMatrix) ;apply rotation
    ;draw YinGang whereas 0, 0 is -$iW / 2, -$iH / 2 because 0, 0 is moved to the bitmap center
    _GDIPlus_PathAddEllipse($hPath, -$iW / 2, -$iH / 2, $iW - 1, $iH - 1) ;draw and fill main ellipse (white ellipse with black border)
    _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrushW)
    _GDIPlus_GraphicsFillPie($hGfx, -$iW / 2, -$iH / 2, $iW - 1, $iH - 1, -90, 180, $hBrushB) ;fill the right half of the ellipse black
    _GDIPlus_GraphicsFillEllipse($hGfx, -$iW / 2 + $iW / 4, -$iH / 2, $iW / 2, $iH / 2, $hBrushW) ;draw white ellipse in the upper area
    _GDIPlus_GraphicsFillEllipse($hGfx, -$iW / 2 + $iW / 4, 0, $iW / 2, $iH / 2, $hBrushB);draw black ellipse in the lower area
    _GDIPlus_GraphicsFillEllipse($hGfx, -$iW / 2 + 5 * $iW / 12, -$iH / 2 + $iH / 6, $iW / 6, $iH / 6, $hBrushB) ;draw black eye (upper)
    _GDIPlus_GraphicsFillEllipse($hGfx, -$iW / 2 + 5 * $iW / 12, -$iH / 2 + 4 * $iH / 6, $iW / 6, $iH / 6, $hBrushW) ;draw white eye (lower)
    ;cleanup resources
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushW)
    _GDIPlus_BrushDispose($hBrushB)
    _GDIPlus_GraphicsDispose($hGfx)
    Return $hBitmap
EndFunc


Example 5

#Include <File.au3> ; Include an AutoIt instruction file, that contains details for the _FileCreate function.
Global $count = 1, $examplefolder = @MyDocumentsDir & "\AutoIt Example Directory", $examplefile = "Example File.txt" ; Reserve memory & Assign variables in Global scope.
Global $answer, $character, $length, $name, $position, $wait = 5, $examplepath = $examplefolder & "\" & $examplefile ; Reserve memory & Assign variables in Global scope.
Global $exampletext = "Hello Jon, welcome to the Beginner's Example for programming with AutoIt." ; Reserve memory & Assign text to a variable.
DirCreate($examplefolder) ; Create a folder (directory) in My Documents for the example file.
_FileCreate($examplepath) ; Create or overwrite the example file.
$name = InputBox("Beginner's Example", "Please enter your name.", "Jon", " M", 200, 130) ; Get a mandatory name.
If $name <> "" Then ; If $name variable is not blank, continue, else exit program.
    $exampletext = StringReplace($exampletext, "Jon", $name) ; Replace the name Jon in variable, with the name entered by user.
    SplashTextOn("", "Please Wait!", 200, 120, -1, -1, 33) ; Show user a splash screen so they know something is happening.
    ShellExecute($examplepath) ; Open the default program for text files.
    WinWaitActive($examplefile, "", $wait) ; Wait for up to 5 seconds for text file program window to open.
    SplashOff() ; Turn splash screen off.
    If WinActive($examplefile, "") Then ; If text file program window is open, continue with example, else exit program.
        Send($exampletext) ; Send the text content of $exampletext variable to the text file program window.
        Send("{ENTER 2}") ; Send ENTER twice
        $exampletext = "You can also send each character individually." ; Assign new text to existing variable.
        $length = StringLen($exampletext) ; Gets the total number of characters in $exampletext
        For $position = 1 To $length ; The value of $position increments every NEXT.
            $character = StringMid($exampletext, $position, $count) ; Get one character.
            Send($character) ; Send the text character to the text file program window.
            Sleep(50) ; Pause for 50 milliseconds.
        Next ; Loop until the total number of characters is reached (has been processed).
        Send("{ENTER}") ; Send ENTER once.
        Send("^s") ; Send the SAVE hotkey.
        $answer = MsgBox(262177, "Cleanup Query", "Remove the Example folder and file?") ; Query example removal.
        If $answer = 1 Then ; If response is OK, then proceed with cleanup, else exit program.
            WinClose($examplefile, "") ; Close the text file program window.
            DirRemove($examplefolder, 1) ; Delete the Example folder (directory) and its contents.
        EndIf ; Exit the response process.
    EndIf ; Exit the active window process.
EndIf ; Exit the successful name process.
Exit ; Exit the program.


Example 6

; Make available a library of constant values.
#include <MsgBoxConstants.au3>

; Display a message box with a timeout of 6 seconds.
MsgBox($MB_OK, "Msg", "Avoid touching the keyboard or mouse during automation", 6)

; Run the Windows Calculator.
Run("calc.exe")

; Wait for the calculator to become active.
WinWaitActive("Calculator")

; Automatically type the current year into the calculator.
Send(@YEAR)

; Let's slow the script down a bit so we can see what's going on.
Sleep(600)

; Automatically type in 'divide by 4', and then sleep 600 ms.
Send("/4")
Sleep(600)

; Hit the return key to display the result, and sleep 600 ms.
Send("{ENTER}")
Sleep(600)

; Copy the result to the clipboard using the Windows shortcut Ctrl+C.
Send("^c")

; Declare, and assign the contents of the clipboard to, a variable.
Local $fResult = ClipGet()

; Check to see if the variable contains a decimal point or not.
If StringInStr($fResult, ".") Then
    ; Display a message box with a timeout of 5 seconds.
    MsgBox($MB_OK, "Leap Year", @YEAR & " is not a leap year.", 5)
Else
    ; This message will only display if the current year is a leap year.
    MsgBox($MB_OK, "Leap Year", @YEAR & " is a leap year.", 5)
EndIf

; Close the Windows calculator - always tidy up afterwards.
WinClose("Calculator")
Edited by jaberwacky
Link to comment
Share on other sites

  • Moderators

Czardas can correct me, but from the conversation he and I had on this subject it was really to be open to the community at large; a chance to see what the MVPs come up with. I would say just post submissions here, without names, and let discussion take place. Multiple threads, and who can see them is (in my 2cents) counter productive to the goal of the challenge.

Edit: If you want to maintain some semblance of order, reference the Post # of each submission in the OP on this thread.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I guess if I keep the codes anonymous.  There is a question of who to invite? 

Anyone who posts in the thread for an invite, simple.

Really should be private among the voters though, just as the other one was.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

J1, this is honestly just a clarification question, no more: Can you explain why the voting should be private and not open to all who can access this forum?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

The other was not, though. jaberwacky made the call. The only discussion I recall in the MVP thread was after the fact, on whether we should change some variable names used, no voting.

I am open either way czardas wants to go; just think we end up with a better product if everyone votes/discusses openly.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

My understanding of the mechanism was the submissions were sent privately to jaberwacky as the arbiter. He then presented his #1 and #2 to MVPs, there was some discussion on cleaning up variable names with the writers' permission, and the choices were published. Unless something more happened via PM (doubtful), that is it in a nutshell from the MVP forum.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Don't know about any #1 and #2, cannot find any reference to that anywhere.

Just that MVP's vote on them, perhaps there were only 2 entries which would be beside the point, which is that MVP's voted privately on the entries, and I think the same should apply to this one.

Anyway, I don't want this to become a big issue, just the same as you, I'm happy what czardas and jaberwacky decide, just voicing my opinion is all.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

jaberwacky made the call.

I did? 

I'm happy what czardas and jaberwacky decide

I don't really have much of any say in this.  Just a simple minded arbiter tis all.  :P

My stance is pretty much: czardas' challenge, czardas' rules.

Link to comment
Share on other sites

You raise a good point JohnOne. There's nothing stopping anyone starting a group PM to discuss the code in private. If I had the ability to create a private voting area, I might have considered it. MVPs should not be afraid of have their code discussed in public, otherwise do not enter. Votes will be made public to ensure that all votes are legitimate and voting by proxy is not allowed.

It was only after some consideration that I made the decision to create a second challenge. The entries received in the first challenge, including yours, were considered a little too advanced for an absolute beginner. It was suggested that if the example were to be placed alongside a simpler example, then there would be no problem. What I thought was missing was an example of automation of 3rd party software, which is what makes AutoIt special. Things are a little bit improvised, and it might have been better to create a panel of judges, but that would have meant voting for every member of the panel and quite a delay. Maybe it's an idea for the future.
 


There are two more days remaining. If you are planning on participation, please be sure to meet the deadline.

Edited by czardas
Link to comment
Share on other sites

@JohnOne - The problem with my Cinderella programming, is that I will need some Fairy Godmother to disguise it else many will recognize my signature style. Slip ..... er ... into a pumpkin anyone? :sorcerer:

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Wrong fairy tale, sleeping beauty .... try snowed in until you're white.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...