AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Concatenate carriage returns and quotes

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Thu Jul 23, 2009 8:55 pm    Post subject: Concatenate carriage returns and quotes Reply with quote

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
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Thu Jul 23, 2009 9:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Thu Jul 23, 2009 9:17 pm    Post subject: Reply with quote

I'm nub here so forgive me

but maybe....

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

Question
Back to top
View user's profile Send private message
BF2 Player



Joined: 27 Mar 2009
Posts: 71

PostPosted: Thu Jul 23, 2009 9:28 pm    Post subject: Reply with quote

Try quotes around the text...

Code:

Jscript = ("
               <html>
               <body text="#00FF00" bgcolor="#000000">
               <script type="text/javascript">
               function ClipBoard()
               {
               var a =
            ")
Back to top
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Thu Jul 23, 2009 9:31 pm    Post subject: Reply with quote

randallf wrote:
I'm nub here so forgive me

but maybe....

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

Question


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
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Thu Jul 23, 2009 9:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Thu Jul 23, 2009 10:07 pm    Post subject: Reply with quote

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]
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Fri Jul 24, 2009 1:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Fri Jul 24, 2009 9:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Fri Jul 24, 2009 9:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mystiq



Joined: 08 Jan 2007
Posts: 83

PostPosted: Mon Jul 27, 2009 9:03 pm    Post subject: Reply with quote

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. Smile
Back to top
View user's profile Send private message
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Tue Jul 28, 2009 4:51 am    Post subject: Reply with quote

I think so:
Code:

Jscript .=  "  + \n + " A_LoopField " + \n + document.links.txtbox" A_Index ".value"


Hubert
Back to top
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Tue Jul 28, 2009 3:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
charliemopps



Joined: 09 Feb 2006
Posts: 117

PostPosted: Tue Jul 28, 2009 3:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group