Faran

Read Array from file and laterz seprate them

18 posts in this topic

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Faran,

Fine. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

thanks m23 but its not filling the listbox at all

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

M23

its same file but see i have screen shoot there is nothing inside listbox

see.jpg

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

M23

still same issue

used this

user1|password1
user2|password2
user3|password3
user4|password4
user5|password5

in file and putted ur new given codes but nothing comes in listbox

and when press button its show

see2.jpg

Share this post


Link to post
Share on other sites

Faran,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

yes its in same Folder where the script is

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

hello m23

I used "For $i = 0 To Ubound($aLines)  -1" instead of "For $i = 0 To @extended - 1" and its worked now

thanks you so much for ur time

faran

Share this post


Link to post
Share on other sites

Faran,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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