Jump to content

FileWrite


Recommended Posts

I can't get this to work. I want to use the FileWrite command to send text to an opened file. The text sent to the file conains " characters. I want to send this exact sting "Automated Logon Tool". I know that a " is a literal string tag and sends the quoted text based on the help file. Being simple minded I though "No problem, double quote the string. It does not sent the text I want. I have looked and looked and can not find an answer. Below is the line of code I am describing. Any suggestions?

FileWrite($file, ""Automated Logon Tool"")

I am new to programming and figure it is very simple to overcome. Am I right?

Me

Link to comment
Share on other sites

I obviously need to provide some detail here!!!!

The script I am writing logges me in a phone system.

It needs to connect to the phone system via a ras connection via a windows dialup.

I query a access database and present a list os customer. I select the customer I want to call.

I then use rasdial to connect to the specified ras number found in the access query. This query also provided me my ras login and password.

I create a connect.scp on the fly based on the selected customer, it was also specified in the ras connectoid, save it to the drive, and then use it for the rasdial connection.

After the ras connection if completed I get the ras server ip address and then telnet to it.

Simple :)

Me

Link to comment
Share on other sites

Are you still having issues with FileWrite, or is there something else that you needed?

What Senton-Bomb wrote would work with writing in the double quotes. You cannot have two sets of quotes next to each other, otherwise it will think that is the end of the string.

If you want to write quotes into the string, use what Senton-Bomb had done and use the single quote ( ' ) to encapsulate the string within the command. Otherwise you can use the ASCII number of the quote with Chr(39) & <string> & Chr(39). (I think that is the number for a single quote, you can find it in the help file reference)

Edited by TheCuz

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Link to comment
Share on other sites

Allright, Now you know I am an idiot!! I was amazed by the fast response to my original post. Thanks again!

The problem is I am to stupid to understand how it solves my problem. I read, reread, reread, (repeat until stupor set in).

I am sure to most of you the soultion is obvious. I do not understand how the strings are sent with the wrapper mentioned.

Forrest Gump

Link to comment
Share on other sites

Here is what I tried:

If FileExists($script) Then

MsgBox(0, "Info", "Script exists.")

Else

MsgBox(0,"Info", "Script does not exist. I'll create it for you.")

EndIf

; File open section

; -------------------------------------------------

$file = FileOpen($script, 10)

FileWrite($file, "proc main" & @CRLF)

FileWrite($file, " '"transmit ^M"'" & @CRLF) <-- This is where my error was.

FileWrite($file, "endproc" & @CRLF)

FileClose($file)

; EndIf

I tried the following:

FileWrite($file, " '"transmit ^M"'" & @CRLF)

FileWrite($file, " '"transmit ^M"' " & @CRLF)

An finally after your suggestion, many thanks again, it works with:

FileWrite($file, '" "transmit ^M" & @CRLF')

This might be obviuos to you guys but it sure wasn't to me!!!

As always once you figure it out it is easy.

Thanks for your help.

Me

Link to comment
Share on other sites

Here is what I tried:

If FileExists($script) Then

MsgBox(0, "Info", "Script exists.")

Else

MsgBox(0,"Info", "Script does not exist. I'll create it for you.")

EndIf

; File open section

; -------------------------------------------------

$file = FileOpen($script, 10)

FileWrite($file, "proc main" & @CRLF)

FileWrite($file, " '"transmit ^M"'" & @CRLF) <-- This is where my error was.

FileWrite($file, "endproc" & @CRLF)

FileClose($file)

; EndIf

I tried the following:

FileWrite($file, " '"transmit ^M"'" & @CRLF)

FileWrite($file, " '"transmit ^M"' " & @CRLF)

An finally after your suggestion, many thanks again, it works with:

FileWrite($file, '" "transmit ^M" & @CRLF')

This might be obviuos to you guys but it sure wasn't to me!!!

As always once you figure it out it is easy.

Thanks for your help.

Me

WARNING: The code above will open the file for overwrite whether it exists already or not! The message boxes imply you didn't mean to do that.

:)

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

My verbage is poor. I'll correct it. If the file exists I do want to delete it. The file is a RAS DUN script I create that is unique to each site dialed. The script contains the password and login information for the RAS connection. For security purposes I will delete the file AFTER I have successfully connected and logged into the system.

If I do see an exisitng file with the same name I'll delete it. Later on I'll make a copy, put in my information, connect and then put back the original version. This of course assumes the user had created a script with the exact name as mine ( I hope not!!).

Thanks again for all of your help. You guys and gals are awesome!!

Me

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