Jump to content

Read Array from file and laterz seprate them


Faran
 Share

Recommended Posts

Hello,

i m totaly newbie to Autoit i need some help with this

i have a array in text file users.txt something like this

profile[1]=user1|password1
profile[2]=user2|password2
profile[3]=user3|password3
profile[4]=user4|password4
profile[5]=user5|password5

i want to import this array to multi select listbox
 and laterz seprate them and login to a site by them

thanks

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Function FileReadToArray would be a good start.

To split strings try function StringSplit.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Faran,

Why do you want to log into "a site" using many different username/password combinations and why are you storing these combinations in a simple text file? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

good question

i have many email account thats why i want to save them all to a text file

and wiv autoit i want to login to selected Email account which will be display in Listbox i guess but i m not so familar to autoit

Link to comment
Share on other sites

  • Moderators

Faran,

Fine. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

so far i have i have got my text file 2d array in Listbox

but 2nd issue how will i get text from colum1 and colum2 of selected items

#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$button = GUICtrlCreateButton("Selected item", 10, 325)
$List1 =  GUICtrlCreateListView("List|List1", 2, 40, 394, 268, BitOR($LBS_MULTIPLESEL,$LBS_MULTICOLUMN,$LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$file = "users.txt"
FileOpen($file, 0)
For $i = 1 to _FileCountLines($file)
      $line = FileReadLine($file, $i)
GUICtrlCreateListViewItem($line,$List1)

Next
FileClose($file)
 _GUICtrlListView_SetItemSelected($List1, 1)
    _GUICtrlListView_SetItemSelected($List1, 2)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         case $button
       MsgBox (0,"Selected","Item are" & _GUICtrlListView_GetSelectedIndices($List1,1))
    EndSwitch
WEnd

thanks in advance

Link to comment
Share on other sites

  • Moderators

Faran,

This should give you an idea of how you might proceed: :)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

$file = "users.txt"

$Form1 = GUICreate("Form1", 615, 438, 192, 124)

$button = GUICtrlCreateButton("Selected item", 10, 325)
$List1 =  GUICtrlCreateListView("List|List1", 2, 40, 394, 268)

GUISetState(@SW_SHOW)

; Read the file into an array
$aLines = FileReadToArray($file)
; Loop through the array
For $i = 0 To @extended - 1
    ; Extract the data
    $sUser = StringRegExpReplace($aLines[$i], "^.*=(.*)\|.*$", "$1")
    $sPass = StringRegExpReplace($aLines[$i], "^.*\|(.*)$" , "$1")
    ; And fill the ListView
    GUICtrlCreateListViewItem($sUser & "|" & $sPass, $List1)
Next

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            ; Get the selected item
            $sSelection = Number(_GUICtrlListView_GetSelectedIndices($List1, False))
            ; Extract the data from the original array
            $sUser = StringRegExpReplace($aLines[$sSelection], "^.*=(.*)\|.*$", "$1")
            $sPass = StringRegExpReplace($aLines[$sSelection], "^.*\|(.*)$" , "$1")
            ; And here it is
            MsgBox($MB_SYSTEMMODAL, "Selection", "UserName:" & @TAB & $sUser & @CRLF & "Password: " & @TAB & $sPass)
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faran,

I used the same file format as you showed in the OP:

profile[1]=user1|password1
profile[2]=user2|password2
profile[3]=user3|password3
profile[4]=user4|password4
profile[5]=user5|password5
Is that not how the file reads? If not then what does it look like? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faran,

A thought - re-reading the OP makes me think the actual file content looks like this:

user1|password1
user2|password2
user3|password3
user4|password4
user5|password5
If this is the case then this code should work: :)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

$file = "users.txt"

$Form1 = GUICreate("Form1", 615, 438, 192, 124)

$button = GUICtrlCreateButton("Selected item", 10, 325)
$List1 =  GUICtrlCreateListView("Username|Password", 2, 40, 394, 268)

GUISetState(@SW_SHOW)

$aLines = FileReadToArray($file)
For $i = 0 To @extended - 1
    ; Add the already formatted data
    GUICtrlCreateListViewItem($aLines[$i], $List1)
Next


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            $iSelection = Number(_GUICtrlListView_GetSelectedIndices($List1, False))
            ; Split the array line on the "|"
            $aSplit = StringSplit($aLines[$iSelection], "|")
            MsgBox($MB_SYSTEMMODAL, "Selection", "UserName:" & @TAB & $aSplit[1] & @CRLF & "Password: " & @TAB & $asplit[2])
    EndSwitch
WEnd
If that still does not work, please post a copy of the file with which you want to work. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faran,

Is the file in the same folder as the script? If not, use the full path when you declare the $file variable. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faran,

Then I am at a complete loss - the code works for me or I would not have posted it. :(>

Let us see if we can pin down which part of the script is failing. Try running this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

; Prefill the array
Global $aLines[5] = ["user1|password1", "user2|password2", "user3|password3", "user4|password4", "user5|password5"]

$Form1 = GUICreate("Form1", 615, 438, 192, 124)

$button = GUICtrlCreateButton("Selected item", 10, 325)
$List1 =  GUICtrlCreateListView("Username|Password", 2, 40, 394, 268)

GUISetState(@SW_SHOW)

For $i = 0 To 4
    ; Add the already formatted data
    GUICtrlCreateListViewItem($aLines[$i], $List1)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            $iSelection = Number(_GUICtrlListView_GetSelectedIndices($List1, False))
            ; Split the array line on the "|"
            $aSplit = StringSplit($aLines[$iSelection], "|")
            MsgBox($MB_SYSTEMMODAL, "Selection", "UserName:" & @TAB & $aSplit[1] & @CRLF & "Password: " & @TAB & $asplit[2])
    EndSwitch
WEnd
Does it work now? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faran,

My fault for using the latest beta where @extended holds the number of lines read. Glad you got it working. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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