AutoHotkey Community

It is currently May 26th, 2012, 8:18 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: July 23rd, 2009, 9:55 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
I'm writing a script to dynamically build Javascript.

How do I concatenate carriage returns and Quote marks together?

I know how to do it in other languages... just not AHK

So I'd like

Var = {
"var a = "Question 1"
window.clipboardData.setData("Text",a);


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 10:02 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
or like this
Code:
Jscript = (
               <html>
               <body text="#00FF00" bgcolor="#000000">
               <script type="text/javascript">
               function ClipBoard()
               {
               var a =
            )


But it errors out on "Function ClipBoard()"

How do I get it to just accept this as text? Ignore all the quotes and stuff?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 10:17 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
I'm nub here so forgive me

but maybe....

http://www.autohotkey.com/docs/commands/_EscapeChar.htm

:?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 10:28 pm 
Offline

Joined: March 27th, 2009, 10:48 pm
Posts: 71
Try quotes around the text...

Code:
Jscript = ("
               <html>
               <body text="#00FF00" bgcolor="#000000">
               <script type="text/javascript">
               function ClipBoard()
               {
               var a =
            ")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 10:31 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
randallf wrote:
I'm nub here so forgive me

but maybe....

http://www.autohotkey.com/docs/commands/_EscapeChar.htm

:?:


Yes, that helps.

BF2 Player wrote:
Try quotes around the text...

Code:
Jscript = ("
               <html>
               <body text="#00FF00" bgcolor="#000000">
               <script type="text/javascript">
               function ClipBoard()
               {
               var a =
            ")


That to... figured that out. But it doesn't like my carriage returns or my quotes inside of quotes. I need doubles. I think I'm starting to get somewhere.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 10:38 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
Ok, I got this far:

Code:
Jscript :=    ("<html> `r
               <body text=""#00FF00""bgcolor=""#000000""> `r
               <script type=""text/javascript"">`r
               function ClipBoard()=`r
               {`r
               var a = ")


Now its getting hung up on the ()

any ideas?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2009, 11:07 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
charliemopps wrote:
Ok, I got this far:

Code:
Jscript :=    ("<html> `r
               <body text=""#00FF00""bgcolor=""#000000""> `r
               <script type=""text/javascript"">`r
               function ClipBoard()=`r
               {`r
               var a = ")


Now its getting hung up on the ()

any ideas?


I have learned that AHK is very specific about things like quotes, such as
( variable ) can be recognized differently than (variable)

Maybe try the above, with
Code:
("
etc
")


with the extra line breaks? maybe?
[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2009, 2:05 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
To open a continuation section, ( must begin on a new line and can only be followed by options for the continuation section. Rather than appending `r to each line, you can override the default "join" string:
Code:
Jscript =
( Join`r`n
<html>
<body text="#00FF00" bgcolor="#000000">
<script type="text/javascript">
function ClipBoard()
{
var a =
)
Note that quotation marks are treated literally with '='; it is only ':=' that requires quotes around strings (and requires each literal quote to be written as "").

To close a continuation section, ) must be at the beginning of a line, but anything following it is appended to the end of the continuation section as is.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2009, 10:10 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
Lexikos wrote:
To open a continuation section, ( must begin on a new line and can only be followed by options for the continuation section. Rather than appending `r to each line, you can override the default "join" string:
Code:
Jscript =
( Join`r`n
<html>
<body text="#00FF00" bgcolor="#000000">
<script type="text/javascript">
function ClipBoard()
{
var a =
)
Note that quotation marks are treated literally with '='; it is only ':=' that requires quotes around strings (and requires each literal quote to be written as "").

To close a continuation section, ) must be at the beginning of a line, but anything following it is appended to the end of the continuation section as is.


This code comes from Australia, and Australia is entirely peopled with criminals, and criminals are used to having people not trust them, as you are not trusted by me, so I can clearly not choose the code in front of you...


Just kidding. That's awesome. Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2009, 10:56 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
Stuck again...

So, after I got the code from above in... I now want to loop through a text file and build Javascript/HTML based on what the lines say.
Code:
Jscript =
( Join`r`n
      <html>
      <body text="#00FF00" bgcolor="#000000">
      <script type="text/javascript">
      function ClipBoard()
      {
      var a =
)
               
FileRead, Contents, %SelectedFile%
if not ErrorLevel  ; Successfully loaded.
Loop, parse, Contents, `n, `r
{
   Jscript =   %Jscript%  + "\n" + "%A_LoopField%" + "\n" + document.links.txtbox%A_Index%.value

}


But the Java script needs the \n for carriage returns... but AHK doesn't like that.

How can i get it to work around that?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2009, 10:03 pm 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
Maybe...
Code:
Jscript := Jscript . "`n" . A_LoopField . "`ndocument.links.txtbox" . A_Index . ".value"
; `n is newline, see help file "escape sequence".


You mentioned carriage return, thats "`r", if its what you want?

P.S. i'm a n00b. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2009, 5:51 am 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 355
Location: Germany
I think so:
Code:
Jscript .=  "  + \n + " A_LoopField " + \n + document.links.txtbox" A_Index ".value"


Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2009, 4:02 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
no, that errors out.

I don't want carriage returns there. What I want there is the Javascript code for carriage returns which is \n

So what I want it to litterally output is:

<html>
<body text="#00FF00" bgcolor="#000000">
<script type="text/javascript">
function ClipBoard()
{
var a = TEXTFROMFILEREADLINE1 + \n + document.links.txtboxINDEXNUMBER1.value +\n + TEXTFROMFILEREADLINE2 + \n + document.links.txtboxINDEXNUMBER2.value

and so on... this is building the code for the javascript based on a list that will be in the text file.

Basically this will built an HTML document that will be a questionair.

The questionnaire will be built based on what's in a text file. So my users can type up what they want on the questionnaire, save it as a text file, run this script and pow!

Here's an example of how I want the output to turn out:

Code:
<html>
<body text="#00FF00" bgcolor="#000000">
<script type="text/javascript">
function ClipBoard()
{
var a = "Check 1st thing?" + "\n" + document.links.txtbox1.value + "\n"  + "\n" + "more stuff?" + "\n" + "\n" + document.links.txtbox2.value + "\n" + "Configured other thing?" +  "\n" + document.links.txtbox3.value + "\n" + "\n"  + "Verified some stuff?" +  "\n" + document.links.txtbox4.value ;
window.clipboardData.setData("Text",a);
}


and then one I get that part down I'll build the HTML that follows it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2009, 4:17 pm 
Offline

Joined: February 9th, 2006, 8:01 pm
Posts: 117
ok, wow... I put an extra space in there and now it works. How weird.

I'll post the code when I get done with it.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, SifJar, SKAN, StepO and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group