ARPFre Posted March 1, 2022 Share Posted March 1, 2022 (edited) Could you please teach me what I'm doing wrong? I've tried several possibilities and none of them I got what I want. The script works perfectly without the RadioButton conditions, But I couldn't do with that ONLY this function within a script was enabled and disabled with Radios On/Off. I don't want to close the script, I want only this function to be disabled. Could you guide me? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <String.au3> #include <GuiButton.au3> #include <ComboConstants.au3> #include <Constants.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <GuiStatusBar.au3> #include <AutoItConstants.au3> #Region ### START Koda GUI section ### Form= $gui = GUICreate("T3.0.01b" , 1079, 663, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_MAXIMIZE,$WS_TABSTOP,$DS_MODALFRAME)) $RadioOn = GUICtrlCreateRadio("On", 208, 72, 33, 17) $RadioOff = GUICtrlCreateRadio("Off", 160, 72, 41, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlCreateGroup("NetWork Active Info:", 15, 630, 835, 65) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $RadioOn $Label1 = GUICtrlCreateLabel("Download speed: ", 30, 665, 200, 15) $Label2 = GUICtrlCreateLabel("Max download speed:", 250, 665, 200, 15) $Label5 = GUICtrlCreateLabel("Upload speed: ", 30, 650, 200, 15) $Label8 = GUICtrlCreateLabel("Max upload speed:", 250, 650, 200, 15) $objWMIServiceNTW = ObjGet("winmgmts:\\localhost\root\CIMV2") ;detect the active network card $oSelect_active_network_cards = $objWMIServiceNTW.ExecQuery('Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True', "WQL") for $oSelect_active_network_card in $oSelect_active_network_cards $active_network_card = stringright($oSelect_active_network_card.Description, 6) ;get part of the name of the active network card Next $threshhold_download = 0 $threshhold_upload = 0 $average_download_speed = 0 $average_upload_speed = 0 case $RadioOff EndSwitch update_speeds() sleep(1) WEnd func update_speeds() ;get the download and upload speed $oNetwork_cards = $objWMIServiceNTW.ExecQuery("SELECT BytesReceivedPerSec, BytesSentPerSec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE name LIKE '%" & $active_network_card & "%'", "WQL") For $oNetwork_card In $oNetwork_cards $current_download_speed = Round($oNetwork_card.BytesReceivedPerSec / 1024) $current_upload_speed = Round($oNetwork_card.BytesSentPerSec / 1024) GUICtrlSetData($Label1, "Real time download speed: " & $current_download_speed & " kB/s") GUICtrlSetData($Label5, "Real time upload speed: " & $current_upload_speed & " kB/s") ;calculate the average download speed if $current_download_speed > $threshhold_download then $average_download_speed = Round(($current_download_speed + $average_download_speed) / 2) GUICtrlSetData($Label2, "Average download speed: " & $average_download_speed & " kB/s") EndIf ;calculate the average upload speed if $current_upload_speed > $threshhold_upload Then $average_upload_speed = Round(($current_upload_speed + $average_upload_speed) / 2) GUICtrlSetData($Label8, "Average upload speed: " & $average_upload_speed & " kB/s") EndIf Next EndFunc Edited March 1, 2022 by Jos fixed codebox Link to comment Share on other sites More sharing options...
Solution ad777 Posted March 31, 2022 Solution Share Posted March 31, 2022 @ARPFre you mean like this: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Global $Send Global $threshhold_upload, $threshhold_download, $average_download_speed, $average_upload_speed Global $objWMIServiceNTW = ObjGet("winmgmts:\\localhost\root\CIMV2"), $active_network_card, $Label1, $Label2, $Label5, $Label8 #Region ### START Koda GUI section ### Form= $gui = GUICreate("T3.0.01b", 1079, 663, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MAXIMIZE, $WS_TABSTOP, $DS_MODALFRAME)) $RadioOn = GUICtrlCreateRadio("On", 208, 72, 33, 17) $RadioOff = GUICtrlCreateRadio("Off", 160, 72, 41, 17) $Label1 = GUICtrlCreateLabel("Download speed: ", 30, 665, 200, 15) $Label2 = GUICtrlCreateLabel("Max download speed:", 250, 665, 200, 15) $Label5 = GUICtrlCreateLabel("Upload speed: ", 30, 650, 200, 15) $Label8 = GUICtrlCreateLabel("Max upload speed:", 250, 650, 200, 15) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlCreateGroup("NetWork Active Info:", 15, 630, 835, 65) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $RadioOn $Send = '_on' ;detect the active network card $oSelect_active_network_cards = $objWMIServiceNTW.ExecQuery('Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True', "WQL") for $oSelect_active_network_card in $oSelect_active_network_cards $active_network_card = stringright($oSelect_active_network_card.Description, 6) ;get part of the name of the active network card Next $threshhold_download = 0 $threshhold_upload = 0 $average_download_speed = 0 $average_upload_speed = 0 case $RadioOff $Send = '_off' EndSwitch update_speeds() sleep(1) WEnd func update_speeds() ;get the download and upload speed $oNetwork_cards = $objWMIServiceNTW.ExecQuery("SELECT BytesReceivedPerSec, BytesSentPerSec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE name LIKE '%" & $active_network_card & "%'", "WQL") For $oNetwork_card In $oNetwork_cards if $Send = '_off' Then GUICtrlSetData($Label1, "Real time download speed: ") GUICtrlSetData($Label5, "Real time upload speed: ") GUICtrlSetData($Label2, "Average download speed: ") GUICtrlSetData($Label8, "Average upload speed: ") Elseif $Send = '_on' Then $current_download_speed = Round($oNetwork_card.BytesReceivedPerSec / 1024) $current_upload_speed = Round($oNetwork_card.BytesSentPerSec / 1024) GUICtrlSetData($Label1, "Real time download speed: " & $current_download_speed & " kB/s") GUICtrlSetData($Label5, "Real time upload speed: " & $current_upload_speed & " kB/s") ;calculate the average download speed if $current_download_speed > $threshhold_download then $average_download_speed = Round(($current_download_speed + $average_download_speed) / 2) GUICtrlSetData($Label2, "Average download speed: " & $average_download_speed & " kB/s") EndIf ;calculate the average upload speed if $current_upload_speed > $threshhold_upload Then $average_upload_speed = Round(($current_upload_speed + $average_upload_speed) / 2) GUICtrlSetData($Label8, "Average upload speed: " & $average_upload_speed & " kB/s") EndIf EndIf Next EndFunc ;==>update_speeds ARPFre 1 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. 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