Jump to content

Array for a list.


Recommended Posts

Im looking to have text in a list, but when the user clicks it, it opens the files path.

Right now, my program only opens what it says in the list box.

Im 99% sure I use an array for this.

--

I have a FileOpenDialog for the path, and it puts what the path is in the list box. I also have a rename button. I want it to retain the files path as what it opens, but I want the list box to say what the rename is.

ex:

Say, I open a file at C:\blahblah\blah.exe With the FileOpenDialog.

in the list box, it says C:\blahblah\blah.exe

I click rename, and rename it to weeeee

I want the list box to open C:\blahblah\blah.exe, but the list box say weeeee.

---

I have no idea how I would do an array for this.

Can I have an example

Link to comment
Share on other sites

this should work

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 340, 210, 193, 115)
$List1 = GUICtrlCreateList("", 11, 11, 134, 188)
$Button1 = GUICtrlCreateButton("Add File", 160, 13, 154, 23, 0)
$Button2 = GUICtrlCreateButton("Run File", 161, 44, 155, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $avFiles[100] ;max 100 files
For $i = 0 to 99 ;Just to prevent errors!
    $avFiles[$i] = "|"
Next

Global $curPointer = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sFile = FileOpenDialog("", "", "Executables(*.exe)")
            $title = InputBox("", "Enter a name for the program")
            $avFiles[$curPointer] = $sFile & "|" & $title
            $curPointer += 1
            GUICtrlSetData($List1, $title)
        Case $Button2
            $CurSelection = GUICtrlRead($List1)
            For $i = 0 to 99
                $str = StringSplit($avFiles[$i], "|")
                if ($str[2] == $CurSelection) Then Run($str[1])
            Next
    EndSwitch
WEnd

But.. its probably not the most efficient way of doing that. This example only allows 100 entries.. but of course, you'll have to edit it to fit your need :lmao:

Hopefully this helps you

Edited by CHRIS95219
Link to comment
Share on other sites

I have this exactly:

Global $avFiles[100] ;max 100 files
For $i = 0 to 99 ;Just to prevent errors!
    $avFiles[$i] = "|"
Next

Global $curPointer = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sFile = FileOpenDialog("", "", "Executables(*.exe)")
            $title = InputBox("", "Enter a name for the program")
            $avFiles[$curPointer] = $sFile & "|" & $title
            $curPointer += 1
            GUICtrlSetData($Launchpad1, $title)
    EndSwitch
WEnd

But the file open dialog doesnt open up.

The only thing I might have done was forget to rename $button1 To $Addprogram but I switched em both out twice just to see. That wasn't the problem, so Im stumped.

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GUIList.au3>
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
$Drive = DriveSpaceFree ( "" & DriveGetDrive ( "Removable" ) )
$Form1 = GUICreate("USBer", 199, 249, 439, 296)
$RemoveProg = GUICtrlCreateButton("Remove prog", 120, 56, 73, 25)
guictrlsetonevent ($RemoveProg, "RemoveProg")
$Launchpad1 = GUICtrlCreateList ("Programs", 0, 32, 113, 201)
GUICtrlSetOnEvent ( $Launchpad1, "LaunchIt")
$ExploreDrive = GUICtrlCreateButton("ExploreDrive", 120, 104, 73, 25)
guictrlsetonevent ($ExploreDrive, "ExploreDrive")
$Button1 = GUICtrlCreateButton("Add program", 120, 8, 73, 25)
$Save = GUICtrlCreateButton("Save", 120, 208, 73, 25)
guictrlsetonevent ($Save, "Save")
$SpaceOnDrive = GUICtrlCreateButton("Space Free", 0, 0, 81, 25)
guictrlsetonevent ($SpaceOnDrive, "SpaceOnDrive")
$Rename = GUICtrlCreateButton("Rename", 120, 152, 73, 25)
guictrlsetonevent ($Rename, "Rename")
GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func SpaceOnDrive()
    MsgBox(4096, "Space free", $Drive & " MB" )
EndFunc

Func RemoveProg()
    _GUICtrlListDeleteItem($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1))
EndFunc

Func ExploreDrive()
    $var4 = DriveGetDrive("ALL")
    Local $message
    For $i = 1 to $var4[0]
        $message &= "("&$i&")" & $var4[$i] & " - " & DriveGetLabel($var4[$i]) & ":" & DriveGetType($var4[$i]) & @CRLF
    Next
    $INputDrive = $var4[0]+1
    while ($INputDrive > $var4[0] or $INputDrive == 0)
        $INputDrive = INputBox("Drive Selector", "Enter the number of the drive you wish to explore " & @CRLF & $message)
    WEnd
    Run(@WindowsDir & "\explorer.exe " & $var4[$INPutDrive])
 EndFunc
 
 
Global $avFiles[100] ;max 100 files
For $i = 0 to 99 ;Just to prevent errors!
    $avFiles[$i] = "|"
Next

Global $curPointer = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sFile = FileOpenDialog("", "", "Executables(*.exe)")
            $title = InputBox("", "Enter a name for the program")
            $avFiles[$curPointer] = $sFile & "|" & $title
            $curPointer += 1
            GUICtrlSetData($Launchpad1, $title)
    EndSwitch
WEnd
 
 
Func LaunchIt()
    $Open = _GUICtrlListGetText($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1))
    Run($Open)
EndFunc

Func Save()
    ;working on it later
    EndFunc
   
Func Rename()
        $InputBox = InputBox ("Rename To...", "What would you like to rename " & _GUICtrlListGetText($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1)) & " to?")
        _GUICtrlListReplaceString($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1), $InputBox)
endFunc
       
func Exit1()
   Exit
endfunc

It's messy because I've had help from multiple people with multiple strategies on doing different things.

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GUIList.au3>
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
$Drive = DriveSpaceFree ( "" & DriveGetDrive ( "Removable" ) )
$Form1 = GUICreate("USBer", 199, 249, 439, 296)
$RemoveProg = GUICtrlCreateButton("Remove prog", 120, 56, 73, 25)
guictrlsetonevent ($RemoveProg, "RemoveProg")
$Launchpad1 = GUICtrlCreateList ("Programs", 0, 32, 113, 201)
GUICtrlSetOnEvent ( $Launchpad1, "LaunchIt")
$ExploreDrive = GUICtrlCreateButton("ExploreDrive", 120, 104, 73, 25)
guictrlsetonevent ($ExploreDrive, "ExploreDrive")
$Button1 = GUICtrlCreateButton("Add program", 120, 8, 73, 25)
GUICtrlSetOnEvent(-1, "AddPRogram")
$Save = GUICtrlCreateButton("Save", 120, 208, 73, 25)
guictrlsetonevent ($Save, "Save")
$SpaceOnDrive = GUICtrlCreateButton("Space Free", 0, 0, 81, 25)
guictrlsetonevent ($SpaceOnDrive, "SpaceOnDrive")
$Rename = GUICtrlCreateButton("Rename", 120, 152, 73, 25)
guictrlsetonevent ($Rename, "Rename")
GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
GUISetState(@SW_SHOW)
Global $avFiles[100] ;max 100 files
For $i = 0 to 99 ;Just to prevent errors!
    $avFiles[$i] = "|"
Next

Global $curPointer = 0
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func SpaceOnDrive()
    MsgBox(4096, "Space free", $Drive & " MB" )
EndFunc

Func RemoveProg()
    _GUICtrlListDeleteItem($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1))
EndFunc

Func ExploreDrive()
    $var4 = DriveGetDrive("ALL")
    Local $message
    For $i = 1 to $var4[0]
        $message &= "("&$i&")" & $var4[$i] & " - " & DriveGetLabel($var4[$i]) & ":" & DriveGetType($var4[$i]) & @CRLF
    Next
    $INputDrive = $var4[0]+1
    while ($INputDrive > $var4[0] or $INputDrive == 0)
        $INputDrive = INputBox("Drive Selector", "Enter the number of the drive you wish to explore " & @CRLF & $message)
    WEnd
    Run(@WindowsDir & "\explorer.exe " & $var4[$INPutDrive])
 EndFunc
 

Func AddProgram()
            $sFile = FileOpenDialog("", "", "Executables(*.exe)")
            $title = InputBox("", "Enter a name for the program")
            $avFiles[$curPointer] = $sFile & "|" & $title
            $curPointer += 1
            GUICtrlSetData($Launchpad1, $title)
 EndFunc
 
Func LaunchIt()
    $Open = _GUICtrlListGetText($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1))
    Run($Open)
EndFunc

Func Save()
    ;working on it later
    EndFunc
   
Func Rename()
        $InputBox = InputBox ("Rename To...", "What would you like to rename " & _GUICtrlListGetText($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1)) & " to?")
        _GUICtrlListReplaceString($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1), $InputBox)
endFunc
       
func Exit1()
   Exit
endfunc

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GUIList.au3>
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
$Drive = DriveSpaceFree ( "" & DriveGetDrive ( "Removable" ) )
$Form1 = GUICreate("USBer", 199, 249, 439, 296)
$RemoveProg = GUICtrlCreateButton("Remove prog", 120, 56, 73, 25)
guictrlsetonevent ($RemoveProg, "RemoveProg")
$Launchpad1 = GUICtrlCreateList ("Programs", 0, 32, 113, 201)
GUICtrlSetOnEvent ( $Launchpad1, "LaunchIt")
$ExploreDrive = GUICtrlCreateButton("ExploreDrive", 120, 104, 73, 25)
guictrlsetonevent ($ExploreDrive, "ExploreDrive")
$Button1 = GUICtrlCreateButton("Add program", 120, 8, 73, 25)
GUICtrlSetOnEvent(-1, "AddPRogram")
$Save = GUICtrlCreateButton("Save", 120, 208, 73, 25)
guictrlsetonevent ($Save, "Save")
$SpaceOnDrive = GUICtrlCreateButton("Space Free", 0, 0, 81, 25)
guictrlsetonevent ($SpaceOnDrive, "SpaceOnDrive")
$Rename = GUICtrlCreateButton("Rename", 120, 152, 73, 25)
guictrlsetonevent ($Rename, "Rename")
GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
GUISetState(@SW_SHOW)
Global $avFiles[100] ;max 100 files
For $i = 0 to 99 ;Just to prevent errors!
    $avFiles[$i] = "|"
Next

Global $curPointer = 0
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func SpaceOnDrive()
    MsgBox(4096, "Space free", $Drive & " MB" )
EndFunc

Func RemoveProg()
    _GUICtrlListDeleteItem($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1))
EndFunc

Func ExploreDrive()
    $var4 = DriveGetDrive("ALL")
    Local $message
    For $i = 1 to $var4[0]
        $message &= "("&$i&")" & $var4[$i] & " - " & DriveGetLabel($var4[$i]) & ":" & DriveGetType($var4[$i]) & @CRLF
    Next
    $INputDrive = $var4[0]+1
    while ($INputDrive > $var4[0] or $INputDrive == 0)
        $INputDrive = INputBox("Drive Selector", "Enter the number of the drive you wish to explore " & @CRLF & $message)
    WEnd
    Run(@WindowsDir & "\explorer.exe " & $var4[$INPutDrive])
 EndFunc
 

Func AddProgram()
            $sFile = FileOpenDialog("", "", "Executables(*.exe)")
            $title = InputBox("", "Enter a name for the program")
            $avFiles[$curPointer] = $sFile & "|" & $title
            $curPointer += 1
            GUICtrlSetData($Launchpad1, $title)
 EndFunc
 
Func LaunchIt()
    $current = GUICtrlRead($Launchpad1)
    For $i = 0 to 99
        $str = StringSplit($avFiles[$i], "|")
        if ($str[2] == $current) Then Run($str[1])
    Next
EndFunc

Func Save()
    ;working on it later
    EndFunc
   
Func Rename()
        $InputBox = InputBox ("Rename To...", "What would you like to rename " & _GUICtrlListGetText($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1)) & " to?")
        _GUICtrlListReplaceString($Launchpad1, _GUICtrlListGetCaretIndex($Launchpad1), $InputBox)
endFunc
       
func Exit1()
   Exit
endfunc

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...