Sign in to follow this  
Followers 0
Pook

Loop/Array from a TXT file

3 posts in this topic

Okay... I've been reading/testiong some post but I'm just not that good yet.

I trying to convert some of my Vbs scripts to Autoit & I can't find a solid loop command(set-up)

For example this is what I like to use in VBS...

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = wscript.createObject("wscript.shell")
Set oTextStream = oFSO.OpenTextFile("wks.txt")
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
oTextStream.Close
For Each strComputer In RemotePC
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'>>>> code here <<<<<
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Next

This would pull the computer name from the TXT file and run the code on each of them. I can't figure out how to accomplish this in Autoit.

Any ideas Please...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Okay... I've been reading/testiong some post but I'm just not that good yet.

I trying to convert some of my Vbs scripts to Autoit & I can't find a solid loop command(set-up)

For example this is what I like to use in VBS...

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = wscript.createObject("wscript.shell")
Set oTextStream = oFSO.OpenTextFile("wks.txt")
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
oTextStream.Close
For Each strComputer In RemotePC
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'>>>> code here <<<<<
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Next

This would pull the computer name from the TXT file and run the code on each of them. I can't figure out how to accomplish this in Autoit.

Any ideas Please...

Use _FileReadToArray():
#include <File.au3>

Global $sFile = "wks.txt", $avFile
_FileReadToArray($sFile, $avFile)
For $n = 1 To $avFile[0]
     _YourFunctionHere($avFile[$n])
Next

Func _YourFunctionHere($sInput)
     ConsoleWrite("Debug: $sInput = " & $sInput & @LF)
EndFunc

It's in the help file.

muttley

Edit: Or...

Global $sFile = "wks.txt", $sLine

While 1
    $sLine = FileReadLine($sFile)
    If @error Then ExitLoop
    _YourFunctionHere($sLine)
Next

Func _YourFunctionHere($sInput)
     ConsoleWrite("Debug: $sInput = " & $sInput & @LF)
EndFunc

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks for your Help!!!

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