Jump to content

How to count letters/digits of drivenames/-spaces?

Recommended Posts

Hello folks,

I'm using the following script to recognize my fixed drives and display them in a window with a variable height (depending on the number of drives found):

#include <GUIConstants.au3>

HotKeySet( "{ESC}", "gotoExit" )

AutoItSetOption("WinTitleMatchMode", 4)

AutoItSetOption ( "RunErrorsFatal", 0 )

AutoItSetOption ( "TrayIconHide", 1 )

Opt("GuiOnEventMode", 1)


Global $FS = 9 ;;Font size 9

Global $B = 800 ;;Bold Text

;;Get System memory info

Global $memget = MemGetStats()

;;Get System RAM & round it down to more human friendly format

Global $SysRam = Round($memget[1]/ 1024)

;;check for setpagefile.exe - not much point in running this GUI if setpagefile.exe isnt on the CD :D

If NOT FileExists( "setpagefile.exe" ) Then

  MsgBox(16, "SetPageFile.exe nicht gefunden!", "Stellen Sie sicher, dass SetPageFile.exe existiert.", 20000)



If WinExists ( "%_SetPageFileGUI_%" ) Then



AutoItWinSetTitle ( "%_SetPageFileGUI_%" )

$title = "Erstelle Pagefile(s)"

$GUIHandle = WinGetHandle ( "Erstelle Pagefile(s)" )

;;count the available fixed-drives for a variable height of the GUI

$yDrives = DriveGetDrive( "FIXED" )

For $nDrv = 1 to $yDrives [0]


$yheight = ($nDrv * 20) + 170

GuiCreate($title, 250, $yheight, 0, 0, $WS_CAPTION) ;;create window, you can change the 0, 0 part to orientate the window on screen

;;I set it to be top left, so those who may not start with 1024x768 will see it without hiding the XPE progress which setting

;;center will do

GUISetFont ($FS, 400) ;;Set general window font

$progressbar1 = GuiCtrlCreateProgress(10, 30, 230, 20,$PBS_SMOOTH)

$Label_1 = GuiCtrlCreateLabel("Status:", 10, 10, 40, 15)

$Label_2 = GuiCtrlCreateLabel("fertig", 50, 10, 140, 15)

$Label_3 = GuiCtrlCreateLabel("Laufwerke auswählen:", 10, 60, 150, 15)

$Label_3a = GuiCtrlCreateLabel("freier Platz", 162, 60, 75, 15, 0x2)

$Label_4 = GuiCtrlCreateLabel("Erstelle Pagefile mit:", 10, $yheight-65, 100, 15)

$Label_5 = GuiCtrlCreateLabel("MB", 220, $yheight-65, 15, 15)

$Combo_5 = GuiCtrlCreateCombo("", 155, $yheight-70, 60, 20)

GUICtrlSetData($Combo_5,"128|256|384|512|768|1024","512") ;;Pagefile sizes - feel free to add/remove your own values

;; The ,"128" part sets the default value displayed, feel free to change this too

GUICtrlSetFont ($Combo_5, $FS, $:D


$drive_letters = DriveGetDrive("FIXED") ;;Get all FIXED drives recognised by the system

$s = 0

;; Just a simple progress bar control to show scanning of fixed drives

$msg = GUIGetMsg()

    For $i = $s To 100 step 1

        $s = 0

      GUICtrlSetData ($progressbar1,$i) ;;update the progress bar

  GUICtrlSetData ($Label_2,"Suche Laufwerke") ;;Show message in status area while scanning



;;check that at least one fixed drive is found, if not (that would be weird), display message in status area and then exit 

  $aDrives = DriveGetDrive( "FIXED" )

  For $nDrv = 1 to $aDrives [0]

    If $nDrv = 0 Then

GUICtrlSetData ($Label_2, "keine Laufwerke gefunden")

Sleep (2000)

MsgBox(16, "Keine Laufwerke gefunden!", "Es kann kein Pagefile erstellt werden." & @CR & "Die Anwendung wird jetzt beendet.", 20000)



If $nDrv = NOT 0 Then

GUICtrlSetData ($Label_2, "Laufwerke gefunden") ;;report drives found





;;this took me ages to figure out, checkboxes and arrays are not fun

;;the long $chkboxes[$i]= line had me pulling my hair out for a good hour getting

;;the syntax right, but well worth it in the end!

dim $chkboxes[$drive_letters[0]+ 1]

$chkboxes[0] = $drive_letters[0]

$Ypos = 80

for $i = 1 to $drive_letters[0]

  $chkboxes[$i] = GuiCtrlCreateCheckbox(StringUpper($drive_letters[$i] & " " & "(" &DriveGetLabel( $drive_letters[$i] ) & ")"), 10, $Ypos, 140, 20)

  GuiCtrlSetState(-1, $GUI_UNCHECKED)

  $Ypos = $Ypos + 20


$Ypos = 80

for $i = 1 to $drive_letters[0]

  $FreeMem = GuiCtrlCreateLabel(Round(DriveSpaceFree( $drive_letters[$i] )) & " MB", 162, $Ypos, 75, 15, 0x2)

  GuiCtrlSetFont ($FreeMem, $FS, $:D

  $Ypos = $Ypos + 20


$SysRam_1 = GuiCtrlCreateLabel("System-RAM:", 10, $yheight-95, 85, 15)

$SysRam_2 = GuiCtrlCreateLabel($SysRam & " MB", 162, $yheight-95, 75, 15, 0x2)

GUICtrlSetFont ($SysRam_2, $FS, $:mad:

$Button_GO = GuiCtrlCreateButton("OK", 10, $yheight-35, 80, 25)

GUICtrlSetOnEvent(-1, "SetPage")

$Button_EXIT = GuiCtrlCreateButton("Abbrechen", 160, $yheight-35, 80, 25)

GUICtrlSetOnEvent(-1, "gotoExit")

While 1

  $msg = GUIGetMsg()



Func GOPressed()

  AdlibEnable( "SetPage", 1 )


Func EXITPressed()

  AdlibEnable( "gotoExit", 1 )


;;finally the main function!

;check which checkbox(es) are checked and set a pagefile on it/them

Func SetPage()

      For $i = 1 to $chkboxes[0]

        if GUICtrlRead ($chkboxes[$i]) =  $GUI_CHECKED then

          GUICtrlSetData ($Label_2, "Erstelle PageFile auf " & StringUpper( $drive_letters[$i] ))

          RunWait ( 'setpagefile.exe ' & $drive_letters[$i] & "\pagefile.sys" & " " & GUICtrlRead($Combo_5), "", @SW_HIDE)





Func gotoExit()



I don't know very much about AutoIt, I just modified this script - which I hadn't build myself - a little bit.

What I found out is that the functions "DriveGetLabel" and "DriveSpaceFree" are used for getting my desired information.

Now I like to know if it's possible to count the letters and digits of the drivenames and the free space?

What I need then is to get the highest number of letters and the highest number of digits, add them and get a variable width for my window.

My other question is if it's possible to count the number of fixed-drives found without using the for/next-loop (like I did in the above script)?

You think this sounds a bit complicated? For me it sounds totally impossible :)

Thanks for any help

cool400 :evil:

Link to post
Share on other sites
  • Moderators

Check out all the "String" options in the help file, and in the forum.

Good Luck!! :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to post
Share on other sites

$yDrives[0] and $drive_letters[0] contain the number of fixed-drives.

Now I like to know if it's possible to count the letters and digits of the drivenames and the free space?

What I need then is to get the highest number of letters and the highest number of digits, add them and get a variable width for my window.

Do you mean like a total of all the drives? What do you mean by the highest numer of letter's? Edited by Burrup


Link to post
Share on other sites

He means he wants to know the highest string length. So he can set his window to be a variable width.

Check the String*() functions. I do believe this to be possible. I dont know how to do it myself, but I am interested to see how you do it. I know someone at some point came up with a way to make a window based on the buttons and such. I dont remember nor have I been able to find that in the Scripts and Scraps forum.

Let me know how this turns out for you,


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to post
Share on other sites


Thanks for your help - finally I found StringLen to count the number of letters of my drive-names!

This is my code:

;;get the longest disk-name and biggest disk-size for a variable width of the GUI
$xDrives = DriveGetDrive( "FIXED" )

dim $len[$xDrives[0] + 1]
dim $wid[$xDrives[0] + 1]

for $xDrv = 1 to $xDrives[0]
  $len[$xDrv] = StringLen(DriveGetLabel( $xDrives[$xDrv] ))
    if $len[$xDrv]>$len[$xDrv-1] then
  $wid[$xDrv] = StringLen(Round(DriveSpaceFree( $xDrives[$xDrv] )))
    if $wid[$xDrv]>$wid[$xDrv-1] then

Any code-optimization is really much appreciated :evil:

Best regards

cool400 :)

Edited by cool400
Link to post
Share on other sites

Hmmm...now I've got another problem: depending on my code I've now got two variables with the number of letters/digits with the highest width.

For a variable width of my GUI I need to convert this value into a pixel-size - and there lies the problem: IMHO the pixel-size of every char varies :evil: E.g. an "i" needs less pixel than a "w"...

The thing is that I have the drive-names with a leading checkbox left-aligned (with a variable width of the name-field!) and the drive-spaces right-aligned. So if I choose a width for the drive-names that is too high, the drive-space beneath it gets deleted when moving the mouse over the checkbox.

I thought about calculating with an average value for a char of 8 pixel, but it seems that this a not a good solution. Even with short drive-names it's too less sometimes...

Any help would be really much appreciated!

Best regards and thanks a lot

cool400 :)

Link to post
Share on other sites

Check out the GUICtrlSetFont() command in the help file's index. According to the Splash... Fonts topic in the appendix, Courier, its derivatives and Lucida Console are all safe fonts to use for this task as they are all included on every OS (almost -- Win95 lacks Lucida Console).

Edited by LxP
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...