Sign in to follow this  
Followers 0
AcidCorps

Create $var (number) button(s)

7 posts in this topic

I have a script that after doing some functions gives me a number generated by the amount of files found

I want to be able to take this number and create that amount of buttons on my gui

What I'm doing is scanning for Preset ini files and if there are 5 I want to have 5 buttons one pointing to a different file to load, if there are 10 then 10 buttons one pointing to a different file.

Share this post


Link to post
Share on other sites



Make array of buttons (their variables). So only one variable of array type with dynamic dimension.

There are examples of that concept on the forum already - use Search.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok I got the basic done now I need some help again

I have it so the button shows up with one problem, I don't want the extension to be shown on the button.

Also how would I assign variables to all the buttons so that I can have different actions preformed when they are clicked?

#include <GuiConstants.au3>
#include <Func.au3>

;Assigning Variables
$ProjectName = IniRead("AcidCorps.ini","Info","Project","")
$Author = IniRead("AcidCorps.ini","Info","Author","")
$Version = IniRead("AcidCorps.ini","Info","Beta","")
$Hors = "88" ;horzontal button positioning
$Vert = "30" ;vertical button positioning

;Searching Files
$a = _FileSearch("*.ini",1)

;GUI
GUICreate($Author & ": " & $ProjectName, 600, 600)
GuiCtrlCreateTab(0, 50, 600, 550)
GuiCtrlCreateTabItem("Settings")
GuiCtrlCreateLabel("Presets:",10, 80,50,15)

;Generating Buttons
    $h = 0
    $v = 0
    For $i = 1 To $a[0]
        if $a[$i] <> "Setup" then
            $buttonName = $a[$i]
            GuiCtrlCreateButton($ButtonName, 60 + $Hors * $h, 80 + $Vert * $v, 75, 15)
            $h = $h + 1
            if $h > 2 Then
                $h = 0
                $v = $v + 1
            EndIf
        EndIf
    Next
    
;Back to GUI
GuiCtrlCreateTabItem("About")
GuiCtrlCreateTabItem("")
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        EndSwitch
WEndoÝ÷ Ø[§q«·jëh×6Func _FileSearch($szMask,$nOption)
    $szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]
         While StringInStr($szMask,"\")
              $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
              $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
         Wend
    If $nOption = 0 Then
         _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
         While 1
              $hFile = FileFindFirstFile($szRoot & "*.*")
              If $hFile >= 0 Then
                   $szBuffer = FileFindNextFile($hFile)
                   While Not @ERROR
                        If $szBuffer <> "." And $szBuffer <> ".." And _
                             StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _
                             $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                        $szBuffer = FileFindNextFile($hFile)
                   Wend
                   FileClose($hFile)
              EndIf
              _FileSearchUtil($szRoot, $szMask, $szReturn)
              If $szPathList == "*" Then ExitLoop
              $szPathList = StringTrimLeft($szPathList,1)
              $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
              $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
         Wend
    EndIf
    If $szReturn = "" Then
         $aNULL[0] = 0
         Return $aNULL
    Else
         Return StringSplit(StringTrimRight($szReturn,1),"*")
    EndIf
EndFunc

Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
         $szBuffer = FileFindNextFile($hFile)
         While Not @ERROR
              If $szBuffer <> "." And $szBuffer <> ".." Then _
                   $RETURN = $RETURN & $ROOT & $szBuffer & "*"
              $szBuffer = FileFindNextFile($hFile)
         Wend
         FileClose($hFile)
    EndIf
EndFunc
Edited by AcidCorps

Share this post


Link to post
Share on other sites

Something like this?

The Buttons that are genrated when clicked open the associated ini with whatever your pc opens ini's with.. for me it's notepad .

#include <GuiConstants.au3>
#include <Func.au3>

Global $Button[1]

;Assigning Variables
$ProjectName = IniRead("AcidCorps.ini","Info","Project","")
$Author = IniRead("AcidCorps.ini","Info","Author","")
$Version = IniRead("AcidCorps.ini","Info","Beta","")
$Hors = "88" ;horzontal button positioning
$Vert = "30" ;vertical button positioning

;Searching Files
$a = _FileSearch("*.ini",1)

;GUI
GUICreate($Author & ": " & $ProjectName, 600, 600)
GuiCtrlCreateTab(0, 50, 600, 550)
GuiCtrlCreateTabItem("Settings")
GuiCtrlCreateLabel("Presets:",10, 80,50,15)

;Generating Buttons
$h = 0
$v = 0
For $i = 1 To $a[0]
    if $a[$i] <> "Setup.ini" then
        $Button[0] +=  + 1
        ReDim $Button[$Button[0] + 1]
        $Button[$i] = GuiCtrlCreateButton(StringTrimRight($a[$i], 4), 60 + $Hors * $h, 80 + $Vert * $v, 75, 15)
        $h += + 1
        if $h > 2 Then
            $h = 0
            $v += + 1
        EndIf           
    EndIf
Next
    
;Back to GUI
GuiCtrlCreateTabItem("About")
GuiCtrlCreateTabItem("")
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    For $b = 1 To $Button[0]
        Switch $msg
            Case $Button[$b]
                ShellExecute(@ScriptDir & "\" & GuiCtrlRead($Button[$b]) & ".ini")
        EndSwitch
    Next    
WEnd

Cheers

Share this post


Link to post
Share on other sites

perfect thank you

Share this post


Link to post
Share on other sites

Sorry guys I'm still having some trouble

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    For $b = 1 To $Button[0]
        Switch $msg
            Case $Button[$b]
                $InIFile = GuiCtrlRead($Button[$b])
                $File = IniRead($IniFile,"Info","File","")
                MsgBox(0,"",$File)
        EndSwitch
    Next   
WEnd

how do I assign $IniFile to the file name of the button pressed.

Share this post


Link to post
Share on other sites

NP , your welcome, something like this..

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    For $b = 1 To $Button[0]
        Switch $msg
            Case $Button[$b]
                $File = IniRead(@ScriptDir & "\" & GuiCtrlRead($Button[$b]) & ".ini","Info","File","")
                MsgBox(0,"",$File)              
        EndSwitch
    Next    
WEnd

Cheers

Share this post


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
Sign in to follow this  
Followers 0