mr_synapse

Noob Alert - Unable to Parse

8 posts in this topic

I am trying to edit a script that I found, and I am not having any luck getting it to compile/run. Here is the script:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
$file_src = FileOpenDialog ( “Choose a CSV file with host objects”, @ScriptDir, “Comma delimeted files (*.csv)” )
$source = FileOpen($file_src)
$dest = FileOpen(@ScriptDir & “\cli-commands.txt”, $FO_OVERWRITE )

; file format <service name>,<service protocol>,<service port(s)>
While 1

$line = FileReadLine($source)
If @error Then ExitLoop

$split_line = StringSplit($line, “,”)

$hName = $split_line[1]
$hAddr = $split_line[2]
$hDesc = $split_line[3]

FileWriteLine($dest, ‘set service ‘ & ‘”‘ & $hName & ‘” protocol “‘ & $hAddr & ‘” port ‘ & $hDesc)

WEnd

FileClose($file_src)
FileClose($dest)

 

I get an error at line 3 (FileOpenDialog line). I have tried what little I can find online, but I don't know where to proceed from here.

The script should take values from a .csv file and creat text lines with those values in a particular format. The script looks okay to me... help! Thank you!!!

 

Share this post


Link to post
Share on other sites



You have used the wrong characters for your string quotations, both the double and single quotes.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
$file_src = FileOpenDialog("Choose a CSV file with host objects", @ScriptDir, "Comma delimeted files (*.csv)" )
$source = FileOpen($file_src)
$dest = FileOpen(@ScriptDir &"\cli-commands.txt", $FO_OVERWRITE )

; file format <service name>,<service protocol>,<service port(s)>
While 1

$line = FileReadLine($source)
If @error Then ExitLoop

$split_line = StringSplit($line,",")

$hName = $split_line[1]
$hAddr = $split_line[2]
$hDesc = $split_line[3]

FileWriteLine($dest, 'set service ' & '"' & $hName & '" protocol"' & $hAddr & '" port ' & $hDesc)

WEnd

FileClose($file_src)
FileClose($dest)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Jos answare is the correct one, mine was wrong, my eyes just fail me.

Kind Regards
Alien.

Edited by alien4u
Wrong Answare...

Share this post


Link to post
Share on other sites

@Alien4u: the original line is correct, yours must throw error. Read in helpfile about missing 2. param $delimiter. The fields are comma separated so it's correct.

Share this post


Link to post
Share on other sites
1 hour ago, AutoBert said:

@Alien4u: the original line is correct, yours must throw error. Read in helpfile about missing 2. param $delimiter. The fields are comma separated so it's correct.

You are right read my previous post, you probably was writing this when I was editing my post.

Share this post


Link to post
Share on other sites

@Jos - I must apologize, but I don't know exactly what you mean. Is there somewhere where I can go to read about how to do this correctly? Thank you very much, I appreciate your time/help. 

Share this post


Link to post
Share on other sites

Just use my posted code which is corrected.

One example: 

Your code: FileOpenDialog ( Choose 
My code:    FileOpenDialog( "Choose
 

Jos

 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This often happens if code is copied and pasted from Word or a similar program. It automatically changes double and single quotes to those damned opening and closing quotes that are not the same character at all. Whoever that that was a good idea was.. well... wrong.

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