Jump to content

How to implement dynamic number auf Gui components?


SpecialK
 Share

Recommended Posts

Hello,

i try to create a little scipt which includes a gui whith different buttons. But before the gui is created i read in the lines of a txt file. Now i'm looking for a way to include a button for each option (=each line) in the ini file. The problem is: I don't know how to handle with a various number of controls.

Here is an example how it doesn't work at the moment. I get an empty gui.

#include <Constants.au3>
#include <file.au3>
#Include <string.au3>
#include <array.au3>
#include <GUIConstants.au3>
$inifile = FileOpen ("c:\temp\druckerauswahl.txt", 0)

GUICreate("Test", 280, 300)
While 1
    $line = FileReadLine($inifile)
    ;MsgBox (1, "Test",FileReadLine ($inifile))
    GUICtrlCreateLabel ($line,  10, 10, 550)  ; this line seems not do do what i want it to do
    If @error = -1 Then ExitLoop
    if $line = "" Then ExitLoop 
WEnd


GUISetState ()

While 1
   $msg = GUIGetMsg()
   Switch $msg
    Case $GUI_EVENT_CLOSE
        Exit
        ExitLoop
   EndSwitch

 Wend

GUISetState(@SW_HIDE)
sleep (2000)
exit

I hope you can show me the right direction.

Best regards

Sven

Edited by SpecialK
Link to comment
Share on other sites

Why not use the INI Functions to Read the INI Files?

Edit: Have a look at this Example >>

Edited by guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Have a look at #Post9 by BrewManNH in the Example I provided. There is also an Example by Melba23 in the Forums too. (I will try and Find It!)

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Couldn't find Melba's Example but did find this >>

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Your script creates all those Label controls right on top of each other because you don't increment the POS values. This demo creates dynamic GUI height, the dynamic number of Label controls, and keeps all the control IDs in an array for future reference in the script:

#include <GUIConstantsEx.au3>
#include <file.au3>

Global $sFile, $aFile[1]
Global $hGUI, $iGuiW = 300, $iGuiH = 80
Global $aLabels[1] = [0], $iX = 20, $iY = 20

; Get file
$sFile = FileOpenDialog("Select File", @ScriptDir, "Text files (*.txt)")
If @error Then Exit

; Read file
_FileReadToArray($sFile, $aFile)
If Not @error Then
    ReDim $aLabels[UBound($aFile)]
    $aLabels[0] = $aFile[0]

    $iGuiH += $aFile[0] * 30
Else
    MsgBox(16, "Error", "Error reading file:  " & $sFile)
    Exit
EndIf

; Create GUI
$hGUI = GUICreate("Test", $iGuiW, $iGuiH)
For $n = 1 To $aFile[0]
    $aLabels[$n] = GUICtrlCreateLabel($aFile[$n], $iX, $iY, $iGuiW - 40, 20)
    $iY += 30
Next
$idButton = GUICtrlCreateButton("DO SOMETHING", Int($iGuiW / 2) - 50, $iGuiH - 50, 100, 30)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            MsgBox(64, "Dit it", "Done something")
    EndSwitch
WEnd

:)

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

Most of the code is working so far, but i still have one problem: I'm not able to link a variable to the checkbox and read out the state (checked or not checked) later on.

I can't assign a fixed variable name to the checkbox because the number of the checkboxes depends on the txt file. Here is my code:

#include <Constants.au3>
#include <file.au3>
#Include <string.au3>
#include <array.au3>
#include <GUIConstants.au3>

Dim $abstand, $Button

FileDelete ("c:\temp\druckerauswahl.txt")
Local $pid = Run(@ComSpec & " /c adprintx /l", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
$array=StringSplit($output,@CRLF,1)
$inifile = FileOpen ("c:\temp\druckerauswahl.txt", 1)
for $x = 1 to $array[0]
    if StringInStr ($array[$x], "TEM") Then
        if StringInStr ($array[$x], "SERVER") Then
            FileWriteLine ($inifile, StringReplace ($array[$x], "SERVER NAME:  ", ""))
        EndIf
    EndIf
Next
FileClose ($inifile)

$inifile = FileRead ("c:\temp\druckerauswahl.ini")
$array2=StringSplit ($inifile,@CRLF)

GUICreate("Komponentenauswahl", 280, $array2[0] * 15)

$i = 0
For $x = 1 to $array2[0]
    $abstand = $abstand + 10

        Local $Button[$array2[0]]
        if StringInStr ($array2[$x], "kie") Then
        $Button[$x] = GUICtrlCreateCheckbox ($array2[$x], 10, $abstand)  ; I'm not sure if i can use $Button[$x] for giving an individual id to the checkbox
        EndIf

    Next

GUISetState ()
While 1
   $msg = GUIGetMsg()
Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
EndSwitch

For $i = 1 to $array2[0]
    If GUICtrlRead($Button[$i]) = $GUI_CHECKED Then   ; doesn't work. I want to adress the checkbox and read the state
        $output = $array2[$i] & @CRLF
    EndIf
Next


 Wend
GUISetState(@SW_HIDE)


MsgBox (1, "Drucker", "Du hast folgende Drucker gewählt: " & $output)

exit

I've put my questions in the comments. This is my test code and it isn't optimized yet.

Sven

Link to comment
Share on other sites

You need to realize that the integer returned from GuiCtrlRead() on a checkbox represents several possible states, not just checked/unchecked, so simple "=" isn't enough to test with. Try this:

If BitAnd(GUICtrlRead($Button[$i]), $GUI_CHECKED) Then

:)

Edited by PsaltyDS
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

Try this, I added the ability to show what Checkbox was Clicked, see ; <<<<<<

#include <Constants.au3>
#include <file.au3>
#include <string.au3>
#include <array.au3>
#include <GUIConstants.au3>

Dim $abstand, $Button

FileDelete("c:\temp\druckerauswahl.txt")
Local $pid = Run(@ComSpec & " /c adprintx /l", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($pid)
$output = StdoutRead($pid)
$array = StringSplit($output, @CRLF, 1)
$inifile = FileOpen("c:\temp\druckerauswahl.txt", 1)
For $x = 1 To $array[0]
    If StringInStr($array[$x], "TEM") Then
        If StringInStr($array[$x], "SERVER") Then
            FileWriteLine($inifile, StringReplace($array[$x], "SERVER NAME:  ", ""))
        EndIf
    EndIf
Next
FileClose($inifile)

$inifile = FileRead("c:\temp\druckerauswahl.ini")
$array2 = StringSplit($inifile, @CRLF)

GUICreate("Komponentenauswahl", 280, $array2[0] * 15)

$i = 0
Local $Button[$array2[0]]
$StartDummy = GUICtrlCreateDummy()
For $x = 1 To $array2[0]
    $abstand += 10
    If StringInStr($array2[$x], "kie") Then $Button[$x] = GUICtrlCreateCheckbox($array2[$x], 10, $abstand) ; I'm not sure if i can use $Button[$x] for giving an individual id to the checkbox
Next
$EndDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $StartDummy To $EndDummy ; <<<<<<
            For $i = 1 To $Button[0]
                    If $Msg = $Button[$i] Then
                        ConsoleWrite("Checkbox " & $Button[$i] & " was Pressed." & @CRLF)
                        ExitLoop
                    EndIf
                Next
    EndSwitch

    For $i = 1 To $Button[0]
        If _IsChecked($Button[$i]) Then $output = $Button[$i] & @CRLF
    Next
WEnd
GUISetState(@SW_HIDE)
MsgBox(1, "Drucker", "Du hast folgende Drucker gewählt: " & $output)
Exit

Func _IsChecked($iControl)
    Return BitAND(GUICtrlRead($iControl), 1) = 1
EndFunc   ;==>_IsChecked
Edited by guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@PsaltyDS:

When i use your code i get the same error message saying:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.
If BitAnd(GUICtrlRead($Button[$i]), $GUI_CHECKED) Then
If BitAnd(GUICtrlRead(^ ERROR

This is the part where the error occurs:

For $i = 1 to $array2[0]
    If BitAnd(GUICtrlRead($Button[$i]), $GUI_CHECKED) Then
    $output = $array2[$i] & @CRLF
    EndIf
Next

@guinness

I don't get your code to work. I don't get an error message but nothing happens.

Best regards

Sven

Edited by SpecialK
Link to comment
Share on other sites

Can you provide the details of druckerauswahl.txt please!

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You declared the $Button array incorrectly:

Local $Button[$array2[0] + 1]

 ; -- or --

Local $Button[Ubound($array2)]

:)

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

I also did a little modifying as well >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <Constants.au3>
#include <File.au3>
#include <String.au3>
#include <Array.au3>
#include <GUIConstants.au3>

Global $Output, $Top, $Msg

FileDelete("C:\temp\druckerauswahl.txt")
Global $PID = Run(@ComSpec & " /c adprintx /l", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($PID)
$Output = StdoutRead($PID)

GLobal $aArray_1 = StringSplit($Output, @CRLF, 1)
Global $hINIFile = FileOpen("C:\temp\druckerauswahl.txt", 1)
For $i = 1 To $aArray_1[0]
    If StringInStr($aArray_1[$i], "TEM") Then
        If StringInStr($aArray_1[$i], "SERVER") Then
            FileWriteLine($hINIFile, StringReplace($aArray_1[$i], "SERVER NAME:  ", ""))
        EndIf
    EndIf
Next
FileClose($hINIFile)

$hINIFile = FileRead("c:\temp\druckerauswahl.ini")
Global $aArray_2 = StringSplit($hINIFile, @CRLF)

GUICreate("Komponentenauswahl", 280, $aArray_2[0] * 35)

Global  $Button[$aArray_2[0] + 1]
For $i = 1 To $aArray_2[0]
    $Top += 25
    If StringInStr($aArray_2[$i], "kie") Then
        $Button[$i] = GUICtrlCreateCheckbox($aArray_2[$i], 10, $Top)
        $Button[0] += 1
    EndIf
Next
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case Else
            If $Msg >= $Button[1] And $Msg <= $Button[$Button[0]] Then
                For $i = 1 To $Button[0]
                    If $Msg = $Button[$i] Then
                        ConsoleWrite("Checkbox " & $Button[$i] & " was Pressed." & @CRLF)
                        ExitLoop
                    EndIf
                Next
            EndIf

    EndSwitch

    For $i = 1 To $Button[0]
        If _IsChecked($Button[$i]) Then $Output = $Button[$i] & @CRLF
    Next
WEnd
GUISetState(@SW_HIDE)
If $Output <> "" Then MsgBox(1, "Drucker", "Du hast folgende Drucker gewählt: " & $Output)
Exit

Func _IsChecked($iControl)
    Return BitAND(GUICtrlRead($iControl), 1) = 1
EndFunc   ;==>_IsChecked

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...