Editing CSV file

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
allthenames
Newbie
Posts: 18
Joined: Wed Aug 18, 2010 5:51 pm

Editing CSV file

Post by allthenames » Fri May 04, 2012 8:26 pm

Trying to multiply "cost" by 1.5 and input the result in the next row as "price"
Price always shows up as simply "price" rather than the numerical value

Let>k=1
Label>start
setfocus>Excel*
dderequest>Excel,C:\Program Files\screen-scraper basic edition\ItemsforVendio.txt,R%k%C9,cost,10
StringReplace>cell,SPACE,,cell
Let>a = 1.5
Let> price = %cost% * %a%
MessageModal>cost
MessageModal>%price%
Let>LineToWrite=,,,,,,,,,price
WriteLn>newtest.csv,result,LineToWrite
If>k>5,finish
Let>k=k+1
Goto>start
Label>finish
-Ben

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri May 04, 2012 9:41 pm

Assuming that what you posted is the actual code, you need to remove all those spaces in

Code: Select all

Let>a = 1.5 
Let> price = %cost% * %a% 

allthenames
Newbie
Posts: 18
Joined: Wed Aug 18, 2010 5:51 pm

Thanks

Post by allthenames » Sat May 05, 2012 1:09 am

Thanks it looks a little better except now i'm getting:
5*1.5 as "price"

Code: Select all

Let>k=1
Label>start
setfocus>Excel*
dderequest>Excel,C:\Program Files\screen-scraper basic edition\ItemsforVendio.txt,R%k%C9,cost,10
StringReplace>cell,SPACE,,cell
Let>a=1.5
Let>price=%cost%*%a%
MessageModal>cost
MessageModal>price
Let>LineToWrite=,,,,,,,,,price
WriteLn>newtest.csv,result,LineToWrite
If>k>10,finish
Let>k=k+1
Goto>start
Label>finish
-Ben

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat May 05, 2012 1:21 am

I'm not familiar with the dde stuff. I would guess there's a space or something in the cost. What does the the MessageModal>cost show?

allthenames
Newbie
Posts: 18
Joined: Wed Aug 18, 2010 5:51 pm

Post by allthenames » Sat May 05, 2012 3:31 am

it shows 5. No additional spaces. So thats working correctly I believe
-Ben

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat May 05, 2012 3:50 am

Does this this code work? If so, and yours doesn't, then it would seem there is "something" wrong with cost as passed by dde.

Code: Select all

Let>cost=5
Let>a=1.5
Let>price=%cost%*%a%
MessageModal>cost
MessageModal>price

allthenames
Newbie
Posts: 18
Joined: Wed Aug 18, 2010 5:51 pm

Post by allthenames » Sat May 05, 2012 4:17 am

yep! it worked. I'll have to look into that dde code. Anyone else have any idea what i'm doing wrong here?
-Ben

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

Post by JRL » Sat May 05, 2012 5:36 am

As I recall there is either a CRLF or a TAB that comes in with a DDErequest. Try doing a stringreplace to null on the "cost" variable for CRLF if that doesn't work try TAB.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat May 05, 2012 4:17 pm

Thanks JRL, I was thinking it might be a TAB

Code: Select all

To test replace MessageModal>cost with MDL>#%cost%# you should get

#5#

if there's a TAB or CRLF you may get

#5     # or 

#5
#

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

Post by Marcus Tettmar » Tue May 08, 2012 12:08 pm

Just use Trim to get rid of tabs/spaces/line feeds.

Trim>cost,cost
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Tue May 08, 2012 1:59 pm

Marcus wrote:Just use Trim.....
Doh... Apparently some people read Help.

Help for trim says it removes spaces and control characters. I wrote the following to determine exactly what "control characters" means. What I found was that Trim> removes every ASCII character from decimal 0 (hex 00) to decimal 32 (hex 20). Or the first 33 ASCII characters. It leaves the rest alone.

Thanks Marcus.

Code: Select all

VBSTART
VBEND

Let>kk=-1
Repeat>kk
  Add>kk,1
  Let>vStr=string
  VBEval>chr("%kk%"),vChar
  Let>vStr=%vStr%%vChar%
  Trim>vStr,vStr
  Length>vStr,vLen
  WriteLn>%temp_dir%Trim_Results.txt,wres,ASCII character %kk% - %vLen% - %vStr%
Until>kk=255

mdl>complete

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