dragancla Posted September 9, 2017 Share Posted September 9, 2017 Hey guys, I'm trying to create some sort of download speed test in AutoIT, but I'm at a loss on how to call a function ONLY when I press a certain button. My script looks something like this: $SpeedTestButton = GUICtrlCreateButton("Test Download Speed", 10,50,120,35) $SpeedTestLabel = GUICtrlCreateEdit("Download Speed is: " & DownloadSpeed(), 170, 57, 190, 20, $ES_READONLY) Func DownloadSpeed() Local $Download = "http://bitdefender.com/tv" Local $TempFile = @TempDir & "\Temp.temp" $Size = InetGetSize($Download) If $Size = 0 Then Return "(Not Connected)" $Time = TimerInit() $Success = InetGet($Download, $TempFile, 1, 0) If $Success = 0 Then Return "(Not Connected)" $Time = TimerDiff($Time) $Rate = ($Size / $Time) FileDelete($TempFile) Return Round($Rate) & " KB/Sec" EndFunc Currently it calls the function when I run the script, I want it to call the function when I press the button. Any idea? Link to comment Share on other sites More sharing options...
dragancla Posted September 9, 2017 Author Share Posted September 9, 2017 And maybe only show the Edit once the button is pressed, that would make sense. Link to comment Share on other sites More sharing options...
water Posted September 9, 2017 Share Posted September 9, 2017 Welcome to AutoIt and the forum! When asking for help please post a working reproducer What you are looking for is described in the help file for GUICtrlCreateButton. I wouldn't use an Edit control but a Label to display the result of your speed calculation. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Danyfirex Posted September 9, 2017 Share Posted September 9, 2017 Hello welcome to the forum check GUISetOnEvent or GUIGetMsg and use GUICtrlSetData to se the data to the edit control. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Simpel Posted September 9, 2017 Share Posted September 9, 2017 (edited) Hi. Welcome to the forum. You can loop a "while 1 - wend" and wait for pressing the button. If button is pressed run DownloadSpeed() and update the edit: expandcollapse popup#include <GuiConstants.au3> GUICreate("SpeedTest") GUICtrlCreateDummy() Local $hSpeedTestButton = GUICtrlCreateButton("Test Download Speed", 10,50,120,35) Local $hSpeedTestLabel = GUICtrlCreateLabel("", 170, 57, 190, 20) GUISetState(@SW_SHOW) Local $msg Local $iSpeed While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $hSpeedTestButton GUICtrlSetData($hSpeedTestLabel, "") $iSpeed = DownloadSpeed() GUICtrlSetData($hSpeedTestLabel, "Download Speed is: " & $iSpeed) EndSwitch Sleep(10) WEnd Func DownloadSpeed() SplashTextOn("Wait", "Download-Test running...", 300, 50) Local $Download = "http://bitdefender.com/tv" Local $TempFile = @TempDir & "\Temp.temp" Local $Size = InetGetSize($Download) If $Size = 0 Then Return "(Not Connected)" Local $Time = TimerInit() Local $Success = InetGet($Download, $TempFile, 1, 0) If $Success = 0 Then Return "(Not Connected)" $Time = TimerDiff($Time) Local $Rate = ($Size / $Time) FileDelete($TempFile) SplashOff() Return Round($Rate) & " KB/Sec" EndFunc I inserted a splash while waiting. Conrad Edited September 9, 2017 by Simpel GoogleGonnaSaveUs and dragancla 1 1 SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
dragancla Posted September 9, 2017 Author Share Posted September 9, 2017 6 hours ago, Simpel said: Hi. Welcome to the forum. You can loop a "while 1 - wend" and wait for pressing the button. If button is pressed run DownloadSpeed() and update the edit: expandcollapse popup#include <GuiConstants.au3> GUICreate("SpeedTest") GUICtrlCreateDummy() Local $hSpeedTestButton = GUICtrlCreateButton("Test Download Speed", 10,50,120,35) Local $hSpeedTestLabel = GUICtrlCreateLabel("", 170, 57, 190, 20) GUISetState(@SW_SHOW) Local $msg Local $iSpeed While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $hSpeedTestButton GUICtrlSetData($hSpeedTestLabel, "") $iSpeed = DownloadSpeed() GUICtrlSetData($hSpeedTestLabel, "Download Speed is: " & $iSpeed) EndSwitch Sleep(10) WEnd Func DownloadSpeed() SplashTextOn("Wait", "Download-Test running...", 300, 50) Local $Download = "http://bitdefender.com/tv" Local $TempFile = @TempDir & "\Temp.temp" Local $Size = InetGetSize($Download) If $Size = 0 Then Return "(Not Connected)" Local $Time = TimerInit() Local $Success = InetGet($Download, $TempFile, 1, 0) If $Success = 0 Then Return "(Not Connected)" $Time = TimerDiff($Time) Local $Rate = ($Size / $Time) FileDelete($TempFile) SplashOff() Return Round($Rate) & " KB/Sec" EndFunc I inserted a splash while waiting. Conrad That is awesome! Do you have any idea how I would integrate this in my own GUI? I would like to add that to a panel - code would go under _AddControlsToPanel($aPanel[1]) - and, if I just add the 2 Local variables and the while loop to it, it just hangs on Run until I hit CTRL-Break Link to comment Share on other sites More sharing options...
Simpel Posted September 9, 2017 Share Posted September 9, 2017 Therefor we have to see your code. Could be a lot of reasons. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
dragancla Posted September 10, 2017 Author Share Posted September 10, 2017 This is it System Assessment Tool.au3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now