Jump to content

Recommended Posts

Posted (edited)

Hi, I'm new to AutoIt (and to scripting in general).

So I've been looking for a way to make a window show up and keep showing varying values while up; I can't seen to find anything in the help menu of with the search. An example of this would be a script that calculates my ping to some server. I tell the script how many times to ping, but I would like for it to show me the current ping on a persistent window. Or maybe a window showing "Working" or "Running".

I tried putting it in a while loop but the loops stops until I hit OK. Is there such a feature?

Also, while I'm here, can someone tell me why AutoIt crashes when I put in the commented-out code?

$sum=0
$i=0
$err=0
$max=0
$min=100000000
$x=inputbox("Count","How many times should I count?","10")
$max=number($x)
while $i<$max
    $var = Ping("PVP.net")
    If $var Then; also possible:  If @error = 0 Then ...
        $sum=$sum+$var
        $i=$i+1
        #comments-start
        if $var>$max Then ;way of finding the max
            $max=$var
        EndIf
        if $var<$min Then ;way of finding the min
            $min=$var
        EndIf   
        #comments-end   
        
    Else
        $err=$err+1;count the errors
        
    EndIf


WEnd
$result=$sum/$i
msgbox(0,"Result","Count= " & $i & @LF & "The average was: " & $result & @LF & "and there were " & $err & " errors.")

Whenever I put the comments in, AutoIt starts but never finishes. When I leave the comment out, it works fine.

PS: Also, I know that I can do this much easier with a Batch file (I have) but I want to learn AutoIt for future reference. Also, AutoIt does the pinging much faster.

Thanks!

Edited by Nacht
Posted (edited)

If you want to display a value that changes as it changes, a MsgBox is not the way to go. Opening a messagebox pauses the execution of the script until the box times out or is closed.

Consider using the Tooltip() function, or designing a GUI.

Edited by Paulie
Posted (edited)

Welcolme to the forums ! Posted Image

Try this

$sum=0
$i=0
$err=0
$max=0
$min=100000000
$x=inputbox("Count","How many times should I count?","10")
$max=number($x)
$_Splash=0
while $i<$max
    $var = Ping("PVP.net")
    If $var Then; also possible:  If @error = 0 Then ...
        $sum=$sum+$var
        $i=$i+1
        #comments-start
        if $var>$max Then ;way of finding the max
            $max=$var
        EndIf
        if $var<$min Then ;way of finding the min
            $min=$var
        EndIf
        #comments-end

    Else
        $err=$err+1;count the errors

    EndIf
    $result=Round ( $sum/$i )
    $message = "Count= " & $i & @LF & "The average was: " & $result & @LF & "and there were " & $err & " errors."
    If Not $_Splash Then
        $_Splash = SplashTextOn ( "Result", $message, 300, 100, -1, -1, 48 )
    Else
        ControlSetText ( $_Splash, "", "Static1", $message )
    Endif
    Sleep ( 500 )
WEnd

See SplashTextOn for more details.

Edited by wakillon

AutoIt 3.3.18.0 X86 - SciTE 5.6.7.0 - WIN 11 24H2 X64 - Other Examples Scripts

Posted

Its been answered and a MsgBox() isn't really the best solution, but a MsgBox's Text can be updated "on the fly" using the AutoIt commandline /AutoIt3ExecuteLine, of course this is just a proof of concept and is a little pointless to use when SplashTextOn or a ProgressBar is better!

Global $ChangeText[4] = [3, "Enable", "Disable", "Quit"]
_MsgBoxEx(3, "My Program", "Monitoring >> 0", 0, $ChangeText)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTimeOut = 0, $aButtonText = "")
    Local $sMsgBox = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeOut & '"))'
    Local $iPID = Run(@AutoItExe & " /AutoIt3ExecuteLine " & $sMsgBox, "", @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($aButtonText) Then
        For $A = 1 To $aButtonText[0]
            ControlSetText($sTitle, "", "Button" & $A, $aButtonText[$A])
        Next
    Else
        ControlSetText($sTitle, "", "Button1", $aButtonText)
    EndIf

    Local $sStdoutRead, $iCount = 0
    While ProcessExists($iPID)
        ControlSetText($sTitle, "", "Static1" ,"Monitoring >> " & $iCount)
        $iCount += 1
        $sStdoutRead = StdoutRead($iPID)
        If Number($sStdoutRead) Then Return $sStdoutRead
        Sleep(1000)
    WEnd
    If IsArray($aButtonText) Then Return SetError(1, 1, 0)
    Return SetError(1, 0, 1)
EndFunc   ;==>_MsgBoxEx

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

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
×
×
  • Create New...