| View previous topic :: View next topic |
| Author |
Message |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Thu Jul 23, 2009 8:55 pm Post subject: Concatenate carriage returns and quotes |
|
|
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); |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Thu Jul 23, 2009 9:02 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
|
| Back to top |
|
 |
BF2 Player
Joined: 27 Mar 2009 Posts: 71
|
Posted: Thu Jul 23, 2009 9:28 pm Post subject: |
|
|
Try quotes around the text...
| Code: |
Jscript = ("
<html>
<body text="#00FF00" bgcolor="#000000">
<script type="text/javascript">
function ClipBoard()
{
var a =
") |
|
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Thu Jul 23, 2009 9:31 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Thu Jul 23, 2009 9:38 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
Posted: Thu Jul 23, 2009 10:07 pm Post subject: |
|
|
| 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
with the extra line breaks? maybe?
[/code] |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7295 Location: Australia
|
Posted: Fri Jul 24, 2009 1:05 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Fri Jul 24, 2009 9:10 pm Post subject: |
|
|
| 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! |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Fri Jul 24, 2009 9:56 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Mystiq
Joined: 08 Jan 2007 Posts: 83
|
Posted: Mon Jul 27, 2009 9:03 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 265 Location: Germany
|
Posted: Tue Jul 28, 2009 4:51 am Post subject: |
|
|
I think so:
| Code: |
Jscript .= " + \n + " A_LoopField " + \n + document.links.txtbox" A_Index ".value"
|
Hubert |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Tue Jul 28, 2009 3:02 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
charliemopps
Joined: 09 Feb 2006 Posts: 117
|
Posted: Tue Jul 28, 2009 3:17 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|