Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fput statment output

Status
Not open for further replies.

Slider55

Technical User
Oct 18, 2006
61
US
I'm using the program dde excel to text to help me output data but when I run the program it outputs to a single column. I'm reading 7 columns per row and Using the fputs command, the program outputs all 7 columns in a single row to one column in a text file instead of 7 columns seperated by commas. What commands do I need to be using to do what I am explaining. Below is the part of the script I'm trying to modify. I'm sure this is something so simple, at least I hope it is. Thanks for the help...

;************************************************************************
;* *
;* Procedure RunDDE *
;* *
;* This Procedure Executes the Procomm DDE Commands to Transfer the *
;* Data From the Excel File to an Text File. *
;* *
;************************************************************************

Proc RunDDE
long LinkVar, SystemVar ;* Variables containing DDE Id's.

fopen 1 "C:\Excel_Test_Text.txt" Create ;* RAW MODE

if ddeinit SystemVar "excel" "system"
ddeexecute SystemVar "[APP.MINIMIZE()]" ;* Minimize Excel
if ddeinit LinkVar "excel" "DNB Master List" ;* Link to Sheet 1

While Ro < 550 ;* Last Row in Excel

strfmt sOne "%s%d%s%d" sStrR Ro sStrC C1
strfmt sTwo "%s%d%s%d" sStrR Ro sStrC C2
strfmt sThr "%s%d%s%d" sStrR Ro sStrC C3
strfmt sFou "%s%d%s%d" sStrR Ro sStrC C4
strfmt sFiv "%s%d%s%d" sStrR Ro sStrC C5
strfmt sSix "%s%d%s%d" sStrR Ro sStrC C6
strfmt sSev "%s%d%s%d" sStrR Ro sStrC C7
;*** GET THE DATA FROM THE ROWS AND COLUMNS IN EXCEL ****

Dderequest LinkVar sOne sTok1
;fputs 1 sTok1

Dderequest Linkvar sTwo sTok2
fputs 1 sTok2
Dderequest Linkvar sThr sTok3
fputs 1 sTok3
Dderequest Linkvar sFou sTok4
fputs 1 sTok4
Dderequest Linkvar sFiv sTok5
fputs 1 sTok5
Dderequest Linkvar sSix sTok6
fputs 1 sTok6
Dderequest Linkvar sSev sTok7
fputs 1 sTok7

pause 1 ;* Slows Transfer Rate Down to Excel for Demo ONLY !

Ro++ ;* Increment Row Number
Endwhile
fclose 1
 
I found this in reading the aspect site...."When retrieving a string from an Excel spreadsheet via DDE, be aware that the string will have a carriage return and linefeed at the end of it. You can use the commands strreplace szText "`n" "" and strreplace szText "`r" "" to strip these extra characters out."

Is this what is causing the output to the single row? Thanks!
 
Well I see now that I just needed to read and search a few more times. I got the output I was looking for. This is really cool when it works. Here it is with the output. Hope it helps someone out there like me that doesn't know much about this stuff.

Proc RunDDE
long LinkVar, SystemVar ;* Variables containing DDE Id's.

fopen 1 "C:\Excel_Test_Text.txt" Create ;* RAW MODE

if ddeinit SystemVar "excel" "system"
ddeexecute SystemVar "[APP.MINIMIZE()]" ;* Minimize Excel
if ddeinit LinkVar "excel" "DNB Master List" ;* Link to Sheet 1

While Ro < 356 ;* Last Row in Excel

strfmt sOne "%s%d%s%d" sStrR Ro sStrC C1
strfmt sTwo "%s%d%s%d" sStrR Ro sStrC C2
strfmt sThr "%s%d%s%d" sStrR Ro sStrC C3
strfmt sFou "%s%d%s%d" sStrR Ro sStrC C4
strfmt sFiv "%s%d%s%d" sStrR Ro sStrC C5
strfmt sSix "%s%d%s%d" sStrR Ro sStrC C6
strfmt sSev "%s%d%s%d" sStrR Ro sStrC C7
;*** GET THE DATA FROM THE ROWS AND COLUMNS IN EXCEL ****

Dderequest LinkVar sOne sTok1
strreplace sTok1 "`n" ","
strreplace sTok1 "`r" ""
fputs 1 sTok1
Dderequest Linkvar sTwo sTok2
strreplace sTok2 "`n" ","
strreplace sTok2 "`r" ""
fputs 1 sTok2
Dderequest Linkvar sThr sTok3
strreplace sTok3 "`n" ","
strreplace sTok3 "`r" ""
fputs 1 sTok3
Dderequest Linkvar sFou sTok4
strreplace sTok4 "`n" ","
strreplace sTok4 "`r" ""
fputs 1 sTok4
Dderequest Linkvar sFiv sTok5
strreplace sTok5 "`n" ","
strreplace sTok5 "`r" ""
fputs 1 sTok5
Dderequest Linkvar sSix sTok6
strreplace sTok6 "`n" ","
strreplace sTok6 "`r" ""
fputs 1 sTok6
Dderequest Linkvar sSev sTok7
;strreplace sTok7 "`n" ","
;strreplace sTok7 "`r" ""
fputs 1 sTok7

;pause 1 ;* Slows Transfer Rate Down to Excel for Demo ONLY !

Ro++ ;* Increment Row Number
Endwhile
fclose 1





output

TN,TYPE,DN,CHG TO DN,DES,NAME,MARP
012 0 05 00,500,3400,2400,3400,A2 Carriage Place,MARP
012 0 06 00,500,3401,2401,3401,A3 Carriage Place,MARP
012 0 07 00,500,3402,2402,3402,A4 Carriage Place,MARP
012 0 08 00,500,3403,2403,3403,A5 Carriage Place,MARP
012 0 09 00,500,3404,2404,3404,A6 Carriage Place,MARP
012 0 10 00,500,3405,2405,3405,A7 Carriage Place,MARP
020 1 06 01,500,3410,2406,3410,D1B Town House,MARP
020 1 07 01,500,3411,2407,3411,D1A Town House,MARP
020 1 08 01,500,3412,2408,3412,D2B Town House,MARP
020 1 09 01,500,3413,2409,3413,D2A Town House,MARP
020 1 10 01,500,3414,2410,3414,D3B Town House,MARP
020 1 11 01,500,3415,2411,3415,D3A Town House,MARP
020 1 12 01,500,3416,2412,3416,D4B Town House,MARP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top