Title: Message
Yes! You're absolutely right. Thanks for helping! Here's the code that works...
 
Dim chan_num, i As Integer
Dim cell As String
 
OnError GoTo no_connection
   chan_num = DDEInitiate("EXCEL", "Report 1")
OnError GoTo 0
 
'  cell = DDERequest$( chan_num, "R7C2" )
'  print cell
 
 for i = 1 to 100
  row_col = "R"+(6+i)+"C5"
  cell = DDERequest$( chan_num, row_col)
  print row_col+":"+cell
 next
 
DDETerminateAll
 
End Program
 
no_connection :
Note "ERROR! Excel not open!"
End Program


Lähettäjä: Warren Vick, Europa Technologies Ltd. [mailto:[EMAIL PROTECTED]
Lähetetty: 18. toukokuuta 2006 11:13
Vastaanottaja: Huotari Markku; [email protected]
Aihe: RE: [MI-L] Reading values from Excel with MapBasic

Hello Markku,
 
You don't need to use "run command" in this case and I suspect your code will work fine without it. I've seen a lot of cases where MapBasic programmers (even some MapInfo'ers from MapWorld) use "run command" when they don't need to. As far as I know, the only time you need to use it is in situation where the command itself has non-variable elements that need to be evaluated at run-time. e.g. selecting/updating a table with fields that will not be known until the program executes. Any part of command that can accept an _expression_, such as parameters to the DdeRequest$() function, can be done with variables.
 
Regards,
Warren Vick
Europa Technologies Ltd.
http://www.europa-tech.com

Tel: +44 20 8398 3955 x201
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: 18 May 2006 08:12
To: [email protected]
Subject: [MI-L] Reading values from Excel with MapBasic

Hi,

I'm trying to scan through an open Excel-document with MapBasic and collect a range of values from a specific column to be used in MapBasic, but the only way I seem to get it work is cell by cell by assigning each DDERequest$ with single row & column numbers (see the commented lines below).

What I do need is to get the DDERequest$ working in a loop where I scan through several rows of the same column. I'm jammed with this code that keeps on complaining about the run command "..." - it doesn't seem to assign any value to the cell variable. The print-commands output of the string "cell = ..." Looks OK to me...

I've started to wonder whether there are limitations in using variable names combined with the "run command"?

- - -

Dim chan_num, i, nro As Integer
Dim cell As String

OnError GoTo no_connection
   chan_num = DDEInitiate("EXCEL", "Report 1")
OnError GoTo 0

'  cell = DDERequest$( chan_num, "R7C2" )
'  print cell

 for i = 1 to 100
   print "cell = DDERequest$( "+chan_num+", ""R"+(6+i)+"C5"" )"
   run command "cell = DDERequest$( "+chan_num+", ""R"+(6+i)+"C5"" )"
   print cell

 next

DDETerminateAll

End Program

no_connection :
Note "ERROR! Excel not open!"
End Program

- - -

One possibility of course would be to import the excel-document to MapInfo, but since I've learned that it's possible to read the excel-document directly I thought I'd give this a try. Any ideas anybody?

I'm using MapInfo 7.5 and MapBasic 5.5 - and yes I know - I should upgrade - working on that too :)

                     _\////
                      (o  o)
- - - - - - - - -ooOO -(__) -OOoo - - - - - - - - - - -
     YTV - Pääkaupunkiseudun yhteistyövaltuuskunta
                  http://www.ytv.fi
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
   Markku Huotari              YTV, liikenneosasto
   [EMAIL PROTECTED]       Tietotekniset palvelut
   www.geocities.com/houtari   Opastinsilta 6 A
   puh. (09) 156 1219          00520 HELSINKI
- - - - - - - - - - - - - - - - - - - - - - - - - - - -

_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to