Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy VFP Array to Excel
Message
From
09/12/2005 13:21:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01076673
Message ID:
01076686
Views:
35
>WindowsXP, VFP7/VFP9, Excel2002.
>
>Could anybody shed some light on this behavior of one-dimensional array (see example below)? It seems that arrays are created identical (1 and 2), but they behave differently. For array2 only the first member is copied. The result is like this:
>
>Array1 Array2 Array3
>
>Value 1 Value 1 Value 1
>Value 2 Value 1 Value 2
>Value 3 Value 1 Value 3
>Value 4 Value 1 Value 4
>Value 5 Value 1 Value 5
>Value 6 Value 1 Value 6
>Value 7 Value 1 Value 7
>Value 8 Value 1 Value 8
>Value 9 Value 1 Value 9
>Value 10 Value 1 Value 10
>....
>
>
>
>
>
>CLOSE TABLES all
>DIMENSION tmp_array2[200]    && problem with this
>DIMENSION tmp_array3[200,2]
>
>DIMENSION tmp_array1[200]
>
>Local m.oXl_App
>  Create Cursor test (test_date C (25))
>  For m.nIndex=1 To 200
>	   Insert Into test Values ("Value "+TRANSFORM(m.nIndex))
>	   tmp_array2[m.nIndex] = "Value "+TRANSFORM(m.nIndex)
>   	   tmp_array3[m.nIndex,1] = "Value "+TRANSFORM(m.nIndex)
>  Endfor
>
>  Select test_date From test  Into Array tmp_array1
>	
>  m.oXl_App=Createobject("EXCEL.Application")
>  With m.oXl_App
>   	.Workbooks.Add()
>	.worksheets(1).Range(.cells(1,1),.cells(Alen(tmp_array1,1),1)).Value=aPasser('tmp_array1')
>    .worksheets(1).Range(.cells(,2),.cells(Alen(tmp_array2,1),2)).Value=aPasser('tmp_array2')
>	.worksheets(1).Range(.cells(,3),.cells(Alen(tmp_array3,1),3)).Value=aPasser('tmp_array3')
>   	.Application.Visible =.T.
>  Endwith
>
>....
>
> *------------------
>  Procedure  aPasser
> *------------------
>  Lparameters m_array
>  Return @&m_array
>
Yuri,
I think it's the way VFP works. Result would be the same if you appended tmp_array2 to a cursor (single row). So in effect excel sees it:
.Range(...).Cells.Value = 'ConstantValue'

Whenever I work with append from or excel copy I redimension the array like this:

Dimension tmp_array2[Alen(tmp_array2,1),Max(1,Alen(tmp_array2,2))]

PS: To be more clear to Excel it's on a single row (single row, 200 columns):
.Cells(1,1),.cells(1,Alen(tmp_array2,1)).Value = ...

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform