Jump to content

Noob Alert - Unable to Parse


Recommended Posts

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

 

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

Link to comment
Share on other sites

  • Developers

Just use my posted code which is corrected.

One example: 

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

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

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