Sign in to follow this  
Followers 0
kemo1987

need help in array

9 posts in this topic

Hello again and sorry for annoying

well i tried to make that with 3 different arrays but it sent all ip then all user then all pass.

so i made one array and use StringSplit with "," to split every line to 3 elements

$ip=$data[0] give number of elements for each line i mean > 1 for first line and 3 for other lines

$user=$data[1] this give me 4 then ip

$pass=$data[2] give error

what i want is :

for every line in the file

send $ip > tab > $user > tab > $pass >tab > enter

and i want it look like this

122.33.23.241 friz k01

122.73.213.22 ffri 102

122.33.23.243 frss 103

122.73.213.24 jiis tt04

=========================

siplist.txt contain more than 100 lines like this:

122.33.23.241,friz,k01

122.73.213.22,ffri,102

122.33.23.243,frss,103

122.73.213.24,jiis,tt04

=======================

; Get the files into arrays
#include<Array.au3>
#include <File.au3>
Global $aFile_sip[3]
_FileReadToArray("siplist.txt", $aFile_sip)
;_ArrayDisplay($aFile_sip, "ip Array")
For $line In $aFile_sip
$data=StringSplit($line, ",")
$ip=$data[0] ; first elemnt in array
$user=$data[1] ;second
$pass=$data[2] ;third > i got  error here illegal charcter
WinWaitActive("[CLASS:Notepad]") ; JUST FOR TRY BUT IT WILL SEND TO ANOTHER APP
Send($ip)
send("{TAB}")
Send($user)
send("{TAB}")
Send($pass)
send("{TAB}")
send("{ENTER}")
Next

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Change the For loop in your script because you start with the first element in the array and this element keeps the number of elements (in your example 4).

; Get the files into arrays
#include<Array.au3>
#include <File.au3>
Global $aFile_sip[3]
_FileReadToArray("siplist.txt", $aFile_sip)
;_ArrayDisplay($aFile_sip, "ip Array")
For $iIndex = 1 To $aFile_sip[0]
    $data = StringSplit($aFile_sip[$iIndex], ",", 2)  ; <== modified so the array doesn't contain the counter in $data[0]
    $ip = $data[0] ; first elemnt in array
    $user = $data[1] ;second
    $pass = $data[2] ;third > i got  error here illegal charcter
    WinActivate("[CLASS:Notepad]") ; JUST FOR TRY BUT IT WILL SEND TO ANOTHER APP
    Send($ip)
    Send("{TAB}")
    Send($user)
    Send("{TAB}")
    Send($pass)
    Send("{TAB}")
    Send("{ENTER}")
Next

Edit:

modified so the array doesn't contain the counter in $data[0]

Edited by water
1 person likes this

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

#3 ·  Posted (edited)

#include
#include 

Global $aFile_sip[3]
_FileReadToArray("siplist.txt", $aFile_sip)
;_ArrayDisplay($aFile_sip, "ip Array")

For $line In $aFile_sip
    $data = StringSplit($line, ",")
    ConsoleWrite(_ArrayToString($data) & @CRLF)
Next

ConsoleWrite('***' & @CRLF)

For $i = 1 To $aFile_sip[0]
    $line = $aFile_sip[$i]
    $data = StringSplit($line, ",")
    ConsoleWrite(_ArrayToString($data) & @CRLF)
Next

EDIT: result

1|4

3|122.33.23.241|friz|k01

3|122.73.213.22|ffri|102

3|122.33.23.243|frss|103

3|122.73.213.24|jiis|tt04

***

3|122.33.23.241|friz|k01

3|122.73.213.22|ffri|102

3|122.33.23.243|frss|103

3|122.73.213.24|jiis|tt04

Edited by Zedna

Share this post


Link to post
Share on other sites

Thank you All

i tried first solution and work so good

Share this post


Link to post
Share on other sites

kemo1987, water, and Zedna

Please look at value in $data[0] that is returned from $data=StringSplit($line, ","), or, $data = StringSplit($aFile_sip[$iIndex], ",").

Evidently the number of strings returned "work so good".

" $ip = $data[0] ", I don't think so.

Malkey

Share this post


Link to post
Share on other sites

Malkey,

you are right, that's a bug. I changed my code so that StringSplit doesn't return the counter in $data[0].

$data = StringSplit($aFile_sip[$iIndex], ",")
to
$data = StringSplit($aFile_sip[$iIndex], ",", 2)

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

#9 ·  Posted (edited)

i see what u talking about so i used

$data[1] ip

$data[2]user

$data[3]pass

it work good but i think to edit it to

$data = StringSplit($aFile_sip[$iIndex], ",", 2)

thank you for help

Edited by kemo1987

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
Sign in to follow this  
Followers 0