+ Reply to Thread
Results 1 to 3 of 3

VB dll, Excell and matlab

  1. #1
    Mangesh Yadav
    Guest

    VB dll, Excell and matlab

    Hi,

    Need some help regarding the following. I am making a VB DLL to convert some
    of my excel macro code. The following is working fine where I set "myRng" as
    an excel range, and then create a VB variable "myR" with a for statement and
    then send it to matlab using the PutFullMatrix. Something like this

    Sub MySub(myApp As Object)
    Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")
    myRows = myApp.Worksheets("Sheet1").Range("A1:A10").rows.Count
    For i = 0 To myRows - 1
    myR(i, 0) = myRng(i + 1)
    Next i
    Set Matlab = CreateObject("matlab.application")
    Call Matlab.PutFullMatrix ("myR", "base", myR, myRImag)

    Now my question is: Why do I have to use a for statement. That would make me
    use as many for loops as there are input ranges. Can't I do something like:

    Sub MySub(myApp As Object)
    Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")

    Set Matlab = CreateObject("matlab.application")
    Call Matlab.PutFullMatrix ("myR", "base", myRng, myRImag)

    where I send the variable "myRng" directly to matlab instead of explicitly
    using a for loop to create a VB varaible.



    --
    - Mangesh
    ------------------------------------------
    Office 2003 & Windows XP



  2. #2
    keepITcool
    Guest

    Re: VB dll, Excell and matlab


    Not familiar with matlab..

    But I suspect you need to pass a Variant Array
    not a range..

    dim Matlab as object
    dim xlsVal as variant
    dim matVal as variant

    Set Matlab = CreateObject("Matlab.Application")
    xlsVal = Thisworkbook.worksheets("sheet1").Range("a1:a10").Value

    'xlsVAL is now a 1 based 2 dimensional array.
    'IF matlab can handle 1 based arrays you're ok..

    call matlab.PutFullMatrix( "myR","base",xlsVal,matVal)


    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    Mangesh Yadav wrote :

    > Hi,
    >
    > Need some help regarding the following. I am making a VB DLL to
    > convert some of my excel macro code. The following is working fine
    > where I set "myRng" as an excel range, and then create a VB variable
    > "myR" with a for statement and then send it to matlab using the
    > PutFullMatrix. Something like this
    >
    > Sub MySub(myApp As Object)
    > Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")
    > myRows = myApp.Worksheets("Sheet1").Range("A1:A10").rows.Count
    > For i = 0 To myRows - 1
    > myR(i, 0) = myRng(i + 1)
    > Next i
    > Set Matlab = CreateObject("matlab.application")
    > Call Matlab.PutFullMatrix ("myR", "base", myR, myRImag)
    >
    > Now my question is: Why do I have to use a for statement. That would
    > make me use as many for loops as there are input ranges. Can't I do
    > something like:
    >
    > Sub MySub(myApp As Object)
    > Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")
    >
    > Set Matlab = CreateObject("matlab.application")
    > Call Matlab.PutFullMatrix ("myR", "base", myRng, myRImag)
    >
    > where I send the variable "myRng" directly to matlab instead of
    > explicitly using a for loop to create a VB varaible.


  3. #3
    Mangesh Yadav
    Guest

    Re: VB dll, Excell and matlab

    Thanks keepITcool.
    will give it a shot and come back.

    Mangesh



    "keepITcool" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Not familiar with matlab..
    >
    > But I suspect you need to pass a Variant Array
    > not a range..
    >
    > dim Matlab as object
    > dim xlsVal as variant
    > dim matVal as variant
    >
    > Set Matlab = CreateObject("Matlab.Application")
    > xlsVal = Thisworkbook.worksheets("sheet1").Range("a1:a10").Value
    >
    > 'xlsVAL is now a 1 based 2 dimensional array.
    > 'IF matlab can handle 1 based arrays you're ok..
    >
    > call matlab.PutFullMatrix( "myR","base",xlsVal,matVal)
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > Mangesh Yadav wrote :
    >
    > > Hi,
    > >
    > > Need some help regarding the following. I am making a VB DLL to
    > > convert some of my excel macro code. The following is working fine
    > > where I set "myRng" as an excel range, and then create a VB variable
    > > "myR" with a for statement and then send it to matlab using the
    > > PutFullMatrix. Something like this
    > >
    > > Sub MySub(myApp As Object)
    > > Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")
    > > myRows = myApp.Worksheets("Sheet1").Range("A1:A10").rows.Count
    > > For i = 0 To myRows - 1
    > > myR(i, 0) = myRng(i + 1)
    > > Next i
    > > Set Matlab = CreateObject("matlab.application")
    > > Call Matlab.PutFullMatrix ("myR", "base", myR, myRImag)
    > >
    > > Now my question is: Why do I have to use a for statement. That would
    > > make me use as many for loops as there are input ranges. Can't I do
    > > something like:
    > >
    > > Sub MySub(myApp As Object)
    > > Set myRng = myApp.Worksheets("Sheet1").Range("A1:A10")
    > >
    > > Set Matlab = CreateObject("matlab.application")
    > > Call Matlab.PutFullMatrix ("myR", "base", myRng, myRImag)
    > >
    > > where I send the variable "myRng" directly to matlab instead of
    > > explicitly using a for loop to create a VB varaible.




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1