Carriage Returns sent after variables (version 9.2.01)

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
[email protected]
Newbie
Posts: 2
Joined: Thu Sep 30, 2010 12:18 am

Carriage Returns sent after variables (version 9.2.01)

Post by [email protected] » Thu Sep 30, 2010 12:35 am

We're having trouble with carriage returns occurring after we post any kind of variable.

We are pulling variables out of an excel sheet and when we try and paste them (in a message modal, or to create a directory using the variables we've collected) it always adds a carriage return after each variable sent (see an example of our data below)

Here is the code where we paste the data:

Code: Select all

SRT>FolderCreator

SetFocus>Microsoft Excel - *

DDEREQUEST>Excel,%granfilepath%:data2,R1C3,piececount,10

wait>1

MessageModal> Press Okay to Continue on to Make %piececount% Folders


If>%piececount%>0
	
	let>x=0
	repeat>x
	let>x=x+1

	DDEREQUEST>Excel,%granfilepath%:Data2,R%x%C1,donkey,10
	SetFocus>jobtest*

	CreateDir>t:\%year%\GRANITE Jobs - %year%\%gran_jobnum% - %gran_jobname%\%gran_jobnum% - %donkey%
	MessageModal>Directory t:\%year%\GRANITE Jobs - %year%\%gran_jobnum% - %gran_jobname%\%gran_jobnum% - %donkey% Made!

	until>x,%piececount%

else
	messagemodal>All Done
	goto>end
endif

end>FolderCreator


Here is what happens:

Code: Select all

t:\2010

\GRANITE Jobs - 2010

\9999G

 - test_test

\9999G

 -  Kitchen 1 of 3

Code: Select all



adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu Sep 30, 2010 12:45 am

Something like this will strip the CRLF characters

Code: Select all

StringReplace>source,%CRLF%,,strNewString

[email protected]
Newbie
Posts: 2
Joined: Thu Sep 30, 2010 12:18 am

Post by [email protected] » Thu Sep 30, 2010 3:23 am

Hey Adroege, thanks for getting back to me. Ur solution will work for sending a string, but our problem with carriage returns that follow sent variables runs deeper.

In one part of our macro we are sending variables to our autocad program (DraftSight, which is free) and when we pull a variable from our excel sheet and then send it to the cad program, it ends up also sending a carriage return immediately afterwards, which messes up the syntax of the DraftSight command (i.e. when we need to send an X coordinate, followed by a comma, followed by a Y coordinate and then press ENTER).

So when the X coordinate is sent, a carriage return is immediately sent, ending the command prematurely in autocad and then sending a comma and a 2nd variable which the cad program doesn't know what to do with because its out of context.

Is it a global setting somewhere in MacroScheduler that a carriage return is sent after each variable we send, paste, DDEPoke, etc?


Thanks for your help!

-Paul

Code: Select all

StringReplace>source,%CRLF%,,strNewString
[/quote]

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 30, 2010 4:42 am

Is it a global setting somewhere in MacroScheduler that a carriage return is sent after each variable we send, paste, DDEPoke, etc?
adroege is exactly correct. Every value you acquire from Excel using DDE will come with the carriage return and line feed characters (CRLF). That's because of the way Microsoft designed excel. Every Excel cell contains a carriage return/line feed. Since you don't want those characters included with the value of your variables, use the StringReplace> function to strip them out.

Since you don't show the code where you acquired the values for the variables "granfilepath", "year", "gran_jobnum", "gran_jobname" and "donkey", I assumed you also got those by DDE and so I included lines to strip %CRLF% from all of those variables in the rewrite of your sample code below.


Code: Select all

SRT>FolderCreator

SetFocus>Microsoft Excel - *

StringReplace>%granfilepath%,%CRLF%,,granfilepath
DDEREQUEST>Excel,%granfilepath%:data2,R1C3,piececount,10
StringReplace>%piececount%,%CRLF%,,piececount
wait>1

MessageModal> Press Okay to Continue on to Make %piececount% Folders


If>%piececount%>0
    StringReplace>%year%,%CRLF%,,year
    StringReplace>%gran_jobnum%,%CRLF%,,gran_jobnum
    StringReplace>%gran_jobname%,%CRLF%,,gran_jobname
    
    let>x=0
    repeat>x
    let>x=x+1

    DDEREQUEST>Excel,%granfilepath%:Data2,R%x%C1,donkey,10
    StringReplace>%donkey%,%CRLF%,,donkey
    SetFocus>jobtest*

    CreateDir>t:\%year%\GRANITE Jobs - %year%\%gran_jobnum% - %gran_jobname%\%gran_jobnum% - %donkey%
    MessageModal>Directory t:\%year%\GRANITE Jobs - %year%\%gran_jobnum% - %gran_jobname%\%gran_jobnum% - %donkey% Made!

    until>x,%piececount%

else
    messagemodal>All Done
    goto>end
endif

end>FolderCreator
Last edited by JRL on Thu Sep 30, 2010 4:50 am, edited 1 time in total.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Sep 30, 2010 4:44 am

[email protected] wrote:Is it a global setting somewhere in MacroScheduler that a carriage return is sent after each variable we send, paste, DDEPoke, etc?
I'd say no. Can you possibly post the code you're using to send the values?
[email protected] wrote:In one part of our macro we are sending variables to our autocad program (DraftSight, which is free) and when we pull a variable from our excel sheet and then send it to the cad program, it ends up also sending a carriage return immediately afterwards, which messes up the syntax of the DraftSight command (i.e. when we need to send an X coordinate, followed by a comma, followed by a Y coordinate and then press ENTER).
however you said...
[email protected] wrote:Ur solution will work for sending a string
so... why not first build a string containing your X coordinate, followed by a comma, followed by a Y coordinate and then just send the string?

i.e.

Let>myString=10,25
Send>myString

or if you need the Enter to be sent along as well...

Let>myString=10,25%CR%
Send>myString
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Sep 30, 2010 7:39 am

JRL is correct. When you use DDE to get data from Excel you always end up with CRLF at the end of the data. No idea why. Blame Microsoft :-)

So as a number of people have suggested use StringReplace after your DDERequest lines to remove the CRLFs.

DDE is deprecated anyway, though amazingly Excel still supports it. Might not for much longer. I would advise using DBQuery or VBScript or the new XL functions instead.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts