Consulting

Results 1 to 4 of 4

Thread: Updating Range with Visual FoxPro Array

  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

    Dime 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




  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I just tried this code in VBA and it worked.
    [vba]
    Option Base 1
    Sub Test
    Dim DataArray(100, 3)
    For r = 1 To 100
    DataArray(r, 1) = "ORD " & r
    DataArray(r, 2) = Rnd() * 1000
    DataArray(r, 3) = DataArray(r, 2) * 0.7
    Next
    Set oSheet = Worksheets(1)

    oSheet.Range("A2").Resize(100, 3).Value = DataArray
    End Sub
    [/vba]

  3. #3
    Thank you for your reponse. The code that I have shown is written in Visual FoxPro and not in VBA. I am creating references to EXCEL via Automation and this my problem with the Array.

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I know your code is in FoxPro, but I can't see any code that is specific to FoxPro other than the Str and RAnd functions.

    Have you checked that your array is being populated as expected?

Posting Permissions

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