jazzyjeff Posted November 11, 2009 Share Posted November 11, 2009 I have created the program below with some help on these forums using some borrowed code and some of my own using the help tools. I have only been using AutoIT for a week, so any help is appreciated. I have an IF statement in my script that is supposed to use the value in a variable and display a particular message depending on whether it is greater or less than a fixed number that I have specified. The problem is it's not working correctly. e.g. $Var = 1100 If $var >= 1024 Then GUICTRLCREATELABEL("Variable is bigger than 1024") Else GUICTRLCREATELABEL("Variable is smaller than 1024") With this example, the answer comes out as "Variable is smaller that 1024", which is obviously not right. Any ideas? I have tried for a few days now and I have not been able to figure this out. The actual code is: If $Input_UsedSpace >= 1024 Then GUICtrlCreateLabel("You have exceeded the quota limit set for your Z drive", 10, 15, 400) GUICtrlSetColor(-1, 0xff0000) GUICtrlSetFont(-1, 11.5, 600) Else GUICtrlCreateLabel("You are within the quota limit set for your Z drive", 10, 15, 400) GUICtrlSetColor(-1, 0x0000ff) GUICtrlSetFont(-1, 11.5, 600) EndIf Any help is appreciated. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> _Main() Func _Main() Local $Input_FreeSpace, $Input_UsedSpace, $Input_IPAddress, $Input_HomeShare #Region ### START Koda GUI section ### Form=e:\software\koda\forms\tcaps control panel.kxf Global $MainForm = GUICreate("Home Directory Information", 630, 540) Global $FileMenu = GUICtrlCreateMenu("&File") Global $ExitMenu = GUICtrlCreateMenuItem("&Exit", $FileMenu) Global $NetDriveMenu = GUICtrlCreateMenu("&Network Drives") Global $MapZDrive = GUICtrlCreateMenuItem("Map &Z: Drive", $NetDriveMenu) Global $HelpMenu = GUICtrlCreateMenu("&Help") Global $AboutMenu = GUICtrlCreateMenuItem("About", $HelpMenu) GUICtrlCreateLabel("Z Drive path", 10, 45) GUICtrlCreateLabel("Z: Used Space", 10, 75) GUICtrlCreateLabel("Z: Free Space", 10, 105) GUICtrlCreateLabel("MB", 159, 78) GUICtrlCreateLabel("MB", 159, 108) GUICtrlCreateLabel("IP Address", 10, 135) $Input_HomeShare = GUICtrlCreateInput("" & @HomeShare, 120, 45, 240) $USED = DirGetSize("Z:\") $Input_UsedSpace = GUICtrlCreateInput("" & Round($USED / 1024 / 1024), 120, 75, 35) $FREE = 1024 $Input_FreeSpace = GUICtrlCreateInput("" & Round($FREE - $USED / 1024 / 1024), 120, 105, 35) $Input_IPAddress = GUICtrlCreateInput("" & @IPAddress1, 120, 135, 80) $Pic1 = GUICtrlCreatePic("\\app2\k-12$\logo.bmp", 365, 45, 0, 0) Local $directory, $hListView, $FileList, $DirList, $Dir_Name, $Dir_size, $Dir_t, $Dir_time, $item, $File_Name, $File_size, $File_t, $File_time $directory = "Z:\" $FileList = _FileListToArray($directory, '*.*', 1) ; Only files $DirList = _FileListToArray($directory, '*.*', 2) ; Only directories $listview = GUICtrlCreateListView("File Name |Size (MB) |creation Time (YYYY/MM/DD HH:MM:SS ", 10, 200, 615, 300) ;Directories For $n = 1 To UBound($DirList) - 1 $Dir_Name = $DirList[$n] $Dir_size = DirGetSize($directory & "\" & $Dir_Name, 0) $Dir_t = FileGetTime($directory & "\" & $Dir_Name, 1) $Dir_time = $Dir_t[0] & "/" & $Dir_t[1] & "/" & $Dir_t[2] & " " & $Dir_t[3] & ":" & $Dir_t[4] & ":" & $Dir_t[5] $item = GUICtrlCreateListViewItem($Dir_Name & "|" & Round($Dir_size / 1024 / 1024, 2) & "|" & $Dir_time, $listview) GUICtrlSetImage($item, "shell32.dll", 4) Next ; Files For $n = 1 To UBound($FileList) - 1 $File_Name = $FileList[$n] $File_size = FileGetSize($directory & "\" & $File_Name) $File_t = FileGetTime($directory & "\" & $File_Name, 1) ; creation Time $File_time = $File_t[0] & "/" & $File_t[1] & "/" & $File_t[2] & " " & $File_t[3] & ":" & $File_t[4] & ":" & $File_t[5] $item = GUICtrlCreateListViewItem($File_Name & "|" & Round($File_size / 1024 / 1024, 2) & "|" & $File_time, $listview) If GUICtrlSetImage(-1, $directory & "\" & $File_Name, 1) = 0 Then ; If a default icon cannot be found ; the default icon of the file should be set here GUICtrlSetImage($item, "shell32.dll", 1) EndIf Next If $Input_UsedSpace >= 1024 Then GUICtrlCreateLabel("You have exceeded the quota limit set for your Z drive", 10, 15, 400) GUICtrlSetColor(-1, 0xff0000) GUICtrlSetFont(-1, 11.5, 600) Else GUICtrlCreateLabel("You are within the quota limit set for your Z drive", 10, 15, 400) GUICtrlSetColor(-1, 0x0000ff) GUICtrlSetFont(-1, 11.5, 600) EndIf GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _GUICtrlListView_RegisterSortCallBack($listview) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MapZDrive DriveMapAdd("Z:", @HomeShare, 1) MsgBox(0, "Successful", "The Z: Drive is now mapped") Case $ExitMenu ExitLoop Case $AboutMenu MsgBox(0, "Home Directory Information", "Version 1.2") Case $listview _GUICtrlListView_SortItems($listview, GUICtrlGetState($listview)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($listview) Exit EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 11, 2009 Moderators Share Posted November 11, 2009 jazzyjeff,First, welcome to the Autoit forums. The variable you are using in the If statement is actually the ControlID of an Input control:$Input_UsedSpace = GUICtrlCreateInput("" & Round($USED / 1024 / 1024), 120, 75, 35So unless you have over 1023 controls in your GUI this value will never reach 1024. I believe you should be using $USED, which is derived here:$USED = DirGetSize("Z:\")If anything is unclear, please ask.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 11, 2009 Share Posted November 11, 2009 jazzyjeff, First, welcome to the Autoit forums. The variable you are using in the If statement is actually the ControlID of an Input control: $Input_UsedSpace = GUICtrlCreateInput("" & Round($USED / 1024 / 1024), 120, 75, 35 So unless you have over 1023 controls in your GUI this value will never reach 1024. I believe you should be using $USED, which is derived here: $USED = DirGetSize("Z:\") If anything is unclear, please ask. M23 You are right, but he does some maths on it (converts $USED to MB) and the puts that value in the $Input_UsedSpace input control. So what I think he is really wanting to compare is the value from that control: If Number(GuiCtrlRead($Input_UsedSpace)) >= 1024 Then Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jazzyjeff Posted November 12, 2009 Author Share Posted November 12, 2009 Thank you both for your responses. They both have helped me understand this a lot better. I used the following code in my script and it worked great! If Number(GuiCtrlRead($Input_UsedSpace)) >= 1024 Then 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