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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance on script 1

Status
Not open for further replies.

drtonline

Vendor
Aug 9, 2006
5
US
I have tried to tweak a script that was posted here to take data from an xcel spreadsheet and transmit to my phone system. The script get's the info from row 1 and column 1 and transmits it. However, it does not go past the 1st record. If I put 5 records in, it transmits the data from R-1 C-1 5 times. I am trying to enter
add-persi:stn,22459,,,,,,,,,,123456;^M

123456 is what is in the spread sheet and can be up to 100 variable numbers.

Here is the script -

;**************************************
; DDE code derived from samples at
; ;**************************************

;**************************************
; Declare DDE variables.
;**************************************

long LinkVar, SystemVar ;Variables containing DDE Id's.
string szText ;Text read from DDE link to Excel.
integer iRow, iCol1 ;Row and column variables
string sRowCol ;Holds request for row and column

;**************************************
; Main procedure below
;**************************************

proc main

string s1st, s2nd

s1st = "add-persi:stn,22459,,,,,,,,,,"
s2nd = ";^M"




;**************************************
; Code here for DDE input
;**************************************

iCol1 = 1 ;Column one
iRow = 1 ;Start reading with row 1

if ddeinit SystemVar "excel" "system"
;ddeexecute SystemVar "[FULL(TRUE)]" ;Maximize the spreadsheet.
if ddeinit LinkVar "excel" "sheet1" ;Set up link to spreadsheet.
while 1 ;Loop forever.
strfmt sRowCol "R%dC%d" iRow iCol1 ;Format request for data from current row, column 1
dderequest LinkVar sRowCol szText ;Read data from spreadsheet, current row, column 1
strreplace szText "`n" ""
strreplace szText "`r" ""
if strcmp szText "end" ;If cell contains the string exit
exitwhile ;Exit the while loop.
else
strcat s1st szText
strcat s1st s2nd
transmit s1st
pause 5


endif
iRow++ ;Increment row value
endwhile
ddeterminate LinkVar ;Break DDE link to spreadsheet.
ddeterminate SystemVar ;Break DDE link to Excel.
else
errormsg "Couldn't establish DDE link to spreadsheet!"
endif
else
errormsg "Couldn't establish DDE link to Excel!"
endif


;**************************************
; End DDE code
;**************************************


endproc
 
My guess is, you never reformat s1st back to

Code:
s1st = "add-persi:stn,22459,,,,,,,,,,"


Maybe
Code:
               strcat s1st szText
               strcat s1st s2nd
               transmit s1st
               s1st = "add-persi:stn,22459,,,,,,,,,,"
               pause 5

I'm using a modified version of this code for a project of my own, it works pretty good. Kudo's to Knob for such a great resource.
 
It transmits the - add-persi:stn,22459,,,,,,,,,,123456;^M
each time. So, if I put 123456, 123457, 123458, end in the spreadsheet in column 1, the script transmits - add-persi:stn,22459,,,,,,,,,,123456;^M 3 times and ends. It doesn't step down the numbers.
 
It looks like kodr is right. When I ran your script against a spreadsheet with 1 in the first row, 2 in the second row, and so forth, I would see the value read from the spreadsheet being appended to the previous string. You'll need to make the changes he suggested in his post to eliminate that problem.

 
Did you try my suggestion?

The way your code looks, your szText variable is going to append it's self every time it's ran (including ^m.)

You need to 'reset' the variable. Otherwise it will transmit the original string everytime (remember the ^m?)

After a few pass through your loop, your szText variable is going to be quite large.

 
Thanks kodr. I misunderstood your first message. That cange did the trick. I have been using Procomm for years, but, scripting is new for me. So, thanks knob and kodr!

"After a few pass through your loop, your szText variable is going to be quite large."

I am not sure what this means, but, it doesn't sound efficient. If there is a better way or if this will cause issues let me know.

Thanks again for getting me this far!

DT
 
What I meant was that, without clearing and 'resetting' s1st (sorry, I orignally said szText) back to it's original value, what was happening was, every time it looped, the new data in szText got appended into s1st, and as a result, s1st contained more and more data.

By setting s1st back to your original value, you prevent this from happening.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top