Jump to content
Sign in to follow this  
AGJester

read txt & input into script

Recommended Posts

AGJester

I am new to scripting and have worked with Crimson editor using it for the mouse click function mainly. What I am trying to accomplish now is to have it read a text file from my system and input it into my script. I will explain with my code below. I use a program (freeware) called VisionApp to Terminal into multi systems at the same time.

The test.txt has 10 server names in it (Variables) and I need them to be read and inputed into the section at the bottom call "Name". I looked at this top section of the script to read the txt file but am not sure how to get it to output it into the Variable "Name". if anyone has some pointers or sites I can look at for this I would really appreciate it.

;

; This Scipt adds Servers into VisionApp Remote Desktop.

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

; Open add servers to highlighted Folder

WinWaitActive("visionapp Remote Desktop")

AutoItSetOption("MouseCoordMode", 0)

Mouseclick ("left", 19, 60)

send("name{tab}name{tab}{tab}{tab}{space}")

Share this post


Link to post
Share on other sites
flyingboz

WinWaitActive("visionapp Remote Desktop")

AutoItSetOption("MouseCoordMode", 0)

Mouseclick ("left", 19, 60)

send("name{tab}name{tab}{tab}{tab}{space}")]/quote]

turn the above into a function: , i.e."

func _VisionAppRDP($host)
;activate window
;click
  send ($host)
endfunc'

the top part, instead of the msgbox, call the func:

_VisionAppRDP($line)

edit: BTW, nice first effort. You managed to get somewhere close, once you get the concepts of looping and passing variables down, you'll be answering questions here....

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites
AGJester

flyingboz,

Thanks for the fast reply.. but I am not sure I understand... The code is below.. what I am trying to do is get the section that says *variable* to be the actual text from the txt file. I was learning VB from a friend of mine and this is a little dirrerent. Could you help me a little more?

;
; This Scipt adds Servers into VisionApp Remote Desktop.

$file = FileOpen("test.txt", 0)


; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
;   MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

; Open add servers to highlighted Folder
WinWaitActive("visionapp Remote Desktop")
AutoItSetOption("MouseCoordMode", 0) 
Mouseclick ("left", 19, 60)
send("*Variable*{tab}*Variable*{tab}{tab}{tab}{space}{enter}")



func _VisionAppRDP($host)
;activate window
;click
  send ($host)
endfunc

_VisionAppRDP($line)

Thanks,

Jester

Edited by AGJester

Share this post


Link to post
Share on other sites
AGJester

So I think I figured some of it out.. just working on how to read the next line in the txt file...

;
; This Scipt adds Servers into VisionApp Remote Desktop.

$file = FileOpen("test.txt", 0)
$name = Filereadline($file)


; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)

Wend

FileClose($file)


func _VisionAppRDP($host)
;activate window

WinWaitActive("visionapp Remote Desktop")
AutoItSetOption("MouseCoordMode", 0) 
;click
Mouseclick ("left", 19, 60)
  send ($name)
  send ("{tab}")
  send ($name)
  send ("{tab}{tab}{tab}{space}")
endfunc

_VisionAppRDP($line)

Share this post


Link to post
Share on other sites
AGJester

I was trying to follow someone elses while = 1 code and well.... I had to hard reboot because the mouse kept clicking all over the desktop trying to send emails and log in to servers... it was getting quite comical.... but alas.. had to get rid of that section of code... Right now I only have 3 servers in my txt file (so as not to bring down the network) and the script only pulls the 1st one... I need the script to run the "Func_" section until the txt file is empty... any help would be appreciated.

Share this post


Link to post
Share on other sites
Jester_ag

Finally managed to get it all coded correctly...

CODE
;

; This Script adds Servers into VisionApp Remote Desktop.

MsgBox(0, "Instructions", "Make sure you SINGLE Click on the location where you want to create a new folder & Add your list of servers.")

$Folder = InputBox("Server Information", "Enter the Folder Name.", "")

$txt = inputbox("Source File", "what is the name of your text file including .txt?", "")

;activate window

WinWaitActive("visionapp Remote Desktop")

; Sends Right Click on folder

send ("+{F10}")

; Highlights New Connection

send ("{down}{down}{Enter}")

send ($Folder)

send ("{Enter}")

;Asks the user to enter a ServerName.

$file = FileOpen($txt, 0)

$counter = 1

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$server = FileReadLine($file)

If @error = -1 Then ExitLoop

;MsgBox(0, "Line read:", $server)

;activate window

WinWaitActive("visionapp Remote Desktop")

; Sends Right Click on folder

send ("+{F10}")

; Highlights New Connection

send ("{down}")

send ("{Enter}")

; Enters the name of the server 2x

send ($server)

send ("{tab}")

send ($server)

; Selects Console & Full Screen

send ("{tab}{tab}{tab}{space}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{up}{Enter}")

;endfunc

$i = 0

while $i < $counter

send ("{up}")

;MsgBox(0, "Value of $i is:", $i)

$i = $i + 1

Wend

$counter = $counter + 1

Wend

FileClose($file)

Share this post


Link to post
Share on other sites
Distrophy

Looks good, you might want to look at FileOpenDialog() to add some flexibility in selecting your file.

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  

×