Jump to content

Recommended Posts

Posted

I swear I've searched...But nothing I saw, worked...

 

;Assign the file path to a variable
Local $sFilePath = @ScriptDir & "\FILIAIS.txt"

;Open the file temp.txt in append mode. If the folder C:\AutomationDevelopers does not exist, it will be created.
Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND + $FO_CREATEPATH)

;Display a message box in case of any errors.
If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "Um erro ocorreu ao abrir o arquivo "FILIAIS".")
EndIf

;Set the file position to beginning for reading the data from the beginning of the file.
FileSetPos($hFileOpen, 0, $FILE_BEGIN)

Local $sFileRead = FileReadLine ($hFileOpen,1)

;FileReadLine,FILIAL,filiais.txt,1
;ESCOLHER FILIAL
$FIL = StringSplit($sFileRead,",")
$OPT = Ubound($FIL) -1
;$FILS =

MsgBox($MB_SYSTEMMODAL, "", $sFileRead,10)

Global $lArray[$OPT] = [$sFileRead]
;Global $lArray[6] = ["VERMELHO - ESTAÇÃO 1", "AMARELO - ESTAÇÃO 2","ROSA - ESTAÇÃO 3","VERDE - ESTAÇÃO 4","AZUL - ESTAÇÃO 5","ESTRELA - ESTAÇÃO 6"]
; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($lArray) - 1
    $sList &= "|" & $lArray[$i]
Next
; Create a GUI
$hGUI = GUICreate("QUAL FILIAL ?", 350, 50)
; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            $sLocation = GUICtrlRead($hCombo)
            ExitLoop
    EndSwitch
WEnd

I'm trying to create a array from a txt file! The users will add new info so anyone can use without compiling a new exe...I put some numbers sepated by comma and made a string split, trying to generate separated option to the dropdown menu...But when I try: 

Global $lArray[$OPT] = [$sFileRead] I don't get the numbers separatedly...but still with the commas, I tried Quotes inside the file, around the variable...

Can someone help me plz? Thanks!

PS: please ignore all the trash and comments...I'm trying a lot of things...
 

Posted

A couple of ways to approach this differently that might be easier or work better for you.

FileReadToArray() and StringRegExpReplace() or StringReplace()

And also ArrayToString() is handy for setting GUI controls.

Posted
  On 1/30/2020 at 7:57 PM, ViciousXUSMC said:

A couple of ways to approach this differently that might be easier or work better for you.

FileReadToArray() and StringRegExpReplace() or StringReplace()

And also ArrayToString() is handy for setting GUI controls.

Expand  

Thanks for your hint! I found the problem! 
 

;========================================================================================================================
;Direcionar ao arquivo de texto com informações

;Assign the file path to a variable
Local $sFilePath = @ScriptDir & "\FILIAIS.txt"

;Open the file temp.txt in append mode. If the folder C:\AutomationDevelopers does not exist, it will be created.
Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND + $FO_CREATEPATH)

;Display a message box in case of any errors.
If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "Um erro ocorreu ao abrir o arquivo "FILIAIS".")
EndIf

;Set the file position to beginning for reading the data from the beginning of the file.
FileSetPos($hFileOpen, 0, $FILE_BEGIN)

;ler linha 1 do arquivo de texto
Local $sFileRead = FileReadLine ($hFileOpen,1)

;========================================================================================================================

;ESCOLHER FILIAL
;quebrar linha 1 do arquivo de texto em cada virgula
$FIL = StringSplit($sFileRead,",")

;criar objeto lista em branco
$sList = ""

;loop de 1 até último item, criando opções da lista
For $i = 1 To UBound($FIL) - 1
    $sList &= "|" & $FIL[$i]
 Next

; Create a GUI
$hGUI = GUICreate("QUAL FILIAL ?", 350, 50)
; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            $sLocation = GUICtrlRead($hCombo)
            ExitLoop
    EndSwitch
 WEnd

The txt file look like this:

366,133,233,365

And the menu is ok now!

image.png.639b4dff70985a981f9fd04ade6c4ec7.png

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