Jump to content

need help in array


kemo1987
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

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

#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
Link to comment
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

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

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