Jump to content

Recommended Posts

Posted (edited)

Hello, I hope you can help me with this problem.

in which it repeats the same name when saving it in the test.txt.

 

#include <GuiConstantsEx.au3> 
#include <GuiListView.au3> 


$hGUI = GUICreate("Prueba", 800, 600) 

$hListView = GUICtrlCreateListView("#|Nombre del programa|", 10, 10, 680, 100) 

_GuiCtrlListView_SetColumnWidth($hListView,0,35) 
_GuiCtrlListView_SetColumnWidth($hListView,1,300) 


$OkButton = GUICtrlCreateButton("Aceptar", 50, 170, 75, 23) 

$AddButton = GUICtrlCreateButton("Agregar nueva ruta", 130, 170, 75, 23) 

$RemButton = GUICtrlCreateButton("Eliminar", 210, 170, 75, 23) 


GUISetState(@SW_SHOW, $hGUI) 

_FillList(@ScriptDir & "\test.txt") 

Mientras 1 
    $msg = GUIGetMsg(1) 
    Cambiar $msg[0] 
        Caso $GUI_EVENT_CLOSE 

                Salir 

        Caso $OkButton 
            $sData = "" 

            Para $i = 0 Hasta _GUICtrlListView_GetItemCount($hListView) - 1 
                $sData &= _GUICtrlListView_GetItemText($hListView, $i, 1) & @CRLF 

            Siguiente 

            $hFile = FileOpen(@ScriptDir & "\test.txt", 2) 
            FileWrite($hFile, $sData) 
            FileClose($hFile) 
            Salir 


        Caso $AddButton 
             $sFile = FileOpenDialog(@SCRIPTNAME,@WORKINGDIR,"(*.exe)") 

            Si $sFile = "" Entonces ContinueCase 
            $sFile = StringRegExpReplace($sFile, "^.*\\", "") 

            GUICtrlCreateListViewItem(_GUICtrlListView_GetItemCount($hListView) + 1 & "|" & $sFile , $hListView) 


        Caso $RemButton 
            _GUICtrlListView_DeleteItemsSelected($hListView) 

    FinCambiar 
WEnd 

Func _FillList($sFile) 
    Local $iRead = FileRead($sFile) 
    Local $aString = StringSplit(StringStripCR($iRead), @LF) 

    Para $i = 1 Hasta $aString[0] 
        Si $aString[$i] = "" Entonces ContinuarBucle 
        GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aString[$i], "^.*\\", "") , $hListView) 

    Siguiente 
FinFunc

 

Edited by angel83
  • Developers
Posted (edited)

That script is full of syntax errors!  did you use some sort of translator from English to Spanish before posting?
Please try to use au3check and make a valid script first. 🙂 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

If it was apparently translated into Spanish with the browser, I'm sorry. 
thank you jos
 who is in english

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>


$hGUI = GUICreate("Test", 800, 600)

$hListView = GUICtrlCreateListView("#|Program name|", 10, 10, 680, 100)

_GuiCtrlListView_SetColumnWidth($hListView,0,35)
_GuiCtrlListView_SetColumnWidth($hListView,1,300)


$OkButton = GUICtrlCreateButton("Ok", 50, 170, 75, 23)

$AddButton = GUICtrlCreateButton("Add new path", 130, 170, 75, 23)

$RemButton = GUICtrlCreateButton("Remove", 210, 170, 75, 23)


GUISetState(@SW_SHOW, $hGUI)

_FillList(@ScriptDir & "\test.ini")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE

                Exit

        Case $OkButton
            $sData = ""

            For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
                $sData &= _GUICtrlListView_GetItemText($hListView, $i, 1)  & @CRLF

            Next

            $hFile = FileOpen(@ScriptDir & "\test.ini", 2)
            FileWrite($hFile, $sData)
            FileClose($hFile)
            Exit


        Case $AddButton
             $sFile = FileOpenDialog(@SCRIPTNAME,@WORKINGDIR,"(*.exe)")

            If $sFile = "" Then ContinueCase
            $sFile = StringRegExpReplace($sFile, "^.*\\", "")

            GUICtrlCreateListViewItem(_GUICtrlListView_GetItemCount($hListView) + 1 & "|" & $sFile , $hListView)


        Case $RemButton
            _GUICtrlListView_DeleteItemsSelected($hListView)

    EndSwitch
WEnd

Func _FillList($sFile)
    Local $iRead = FileRead($sFile)
    Local $aString = StringSplit(StringStripCR($iRead), @LF)

    For $i = 1 To $aString[0]
        If $aString[$i] = "" Then ContinueLoop
        GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aString[$i], "^.*\\", "")  , $hListView)

    Next
EndFunc

 

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