Consulting

Results 1 to 4 of 4

Thread: Updating Range with Visual FoxPro Array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Updating Range with Visual FoxPro Array

    I would like to add values to Excel using Visual FoxPro. The code is detailed below.

    The problem that I have is that the whole range of cells are filled with the contents of the first element only, in the example below all cells contain "ORD 1"

    Any help with this would be most appreciated.

    Wayne

    ' Start a new workbook in Excel
    oExcel = CreateObject("Excel.Application")
    oBook = oExcel.Workbooks.Add
    oExcel.Visible=.t.
    ' Create an array with 3 columns and 100 rows
    Dim DataArray(100,3) 
    For r = 1 To 100
        DataArray(r, 1) = "ORD" + STR(r,6,0)
        DataArray(r, 2) = RAnd() * 1000
        DataArray(r, 3) = DataArray(r, 2) * 0.7
    Next
    oSheet = oBook.Worksheets(1)
    ' Transfer the array to the worksheet starting at cell A2
    oSheet.Range("A2").Resize(100, 3).Value = DataArray
    ' Save the Workbook and Quit Excel
    oBook.SaveAs("C:Book1.xls")
    oExcel.Quit
     
    


    Last edited by Aussiebear; 01-23-2025 at 01:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •