Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default function with matrix

Dears;

I have a Nightmare with a macro!! I don' know where is the mistake...the
program is a little bit big, so I'll try to do a resume of the code.

First of all i've created a newtype of variable called NewType (I'm not so
much original...):

Here you are the type:

Type NewType
Peca As String
ri As Integer
pi As Integer
qi As Integer
End Type

Inside a macro I call a function like this:

seq = pas_2(C, T_Treballs())
Where C is an integer and T_Treballs() is NewType

The function is declared:
Public Function pas_2(carrega As Integer, vector() As NewType) As NewType

There is a moment inside the function where there is this code:
y = 1
ReDim Preserve pas_2(y)

and a message like this appear:

"Compilation mistake
The program was waiting for a matrix" (or something like this, I work with a
spanish version and I've translated the message)

Why pas_2(y) is not a matrix inside the function??

Thanks a lot!
--
atrep
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default function with matrix

I didn't test this, but my guess would be that your function is not declared
to return an array of NewType, so you can't use the ReDim function on it.
Add an empty set of parentheses to the end of your function declaration and
see if that clears things up...

Public Function pas_2(carrega As Integer, vector() As NewType) As NewType()

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Dears;

I have a Nightmare with a macro!! I don' know where is the mistake...the
program is a little bit big, so I'll try to do a resume of the code.

First of all i've created a newtype of variable called NewType (I'm not so
much original...):

Here you are the type:

Type NewType
Peca As String
ri As Integer
pi As Integer
qi As Integer
End Type

Inside a macro I call a function like this:

seq = pas_2(C, T_Treballs())
Where C is an integer and T_Treballs() is NewType

The function is declared:
Public Function pas_2(carrega As Integer, vector() As NewType) As NewType

There is a moment inside the function where there is this code:
y = 1
ReDim Preserve pas_2(y)

and a message like this appear:

"Compilation mistake
The program was waiting for a matrix" (or something like this, I work with
a
spanish version and I've translated the message)

Why pas_2(y) is not a matrix inside the function??

Thanks a lot!
--
atrep


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default function with matrix

Thanks Rick for your promp response!

The problem has been solved, now it seems to ReDim the matrix. However a new
problem apears. The following step inside the function is:

pas_2(y).Peca = vector(x).Peca

and this message appears:

"the argument is not optional". It seems that i'm recalling the function
inside the function...

Sure these mistakes are stupid mistakes, but this is the first time working
with functions amd matrix at the same time...

Before I forgot to say that If there is something which I haven't clarified
enough please, ask. I'm not englishspeaker and sure I do lots of mistakes
that can cause missunterstandings.

Thanks a lot once more!
--
atrep


"Rick Rothstein" wrote:

I didn't test this, but my guess would be that your function is not declared
to return an array of NewType, so you can't use the ReDim function on it.
Add an empty set of parentheses to the end of your function declaration and
see if that clears things up...

Public Function pas_2(carrega As Integer, vector() As NewType) As NewType()

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Dears;

I have a Nightmare with a macro!! I don' know where is the mistake...the
program is a little bit big, so I'll try to do a resume of the code.

First of all i've created a newtype of variable called NewType (I'm not so
much original...):

Here you are the type:

Type NewType
Peca As String
ri As Integer
pi As Integer
qi As Integer
End Type

Inside a macro I call a function like this:

seq = pas_2(C, T_Treballs())
Where C is an integer and T_Treballs() is NewType

The function is declared:
Public Function pas_2(carrega As Integer, vector() As NewType) As NewType

There is a moment inside the function where there is this code:
y = 1
ReDim Preserve pas_2(y)

and a message like this appear:

"Compilation mistake
The program was waiting for a matrix" (or something like this, I work with
a
spanish version and I've translated the message)

Why pas_2(y) is not a matrix inside the function??

Thanks a lot!
--
atrep



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default function with matrix

Usually, when dealing with a function that returns an array, it is better to
Dim a "working" array inside your function, do all your work with it and
then, at the end, assign your working array to the function name (I think
that will also work with an array of Types).

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Thanks Rick for your promp response!

The problem has been solved, now it seems to ReDim the matrix. However a
new
problem apears. The following step inside the function is:

pas_2(y).Peca = vector(x).Peca

and this message appears:

"the argument is not optional". It seems that i'm recalling the function
inside the function...

Sure these mistakes are stupid mistakes, but this is the first time
working
with functions amd matrix at the same time...

Before I forgot to say that If there is something which I haven't
clarified
enough please, ask. I'm not englishspeaker and sure I do lots of mistakes
that can cause missunterstandings.

Thanks a lot once more!
--
atrep


"Rick Rothstein" wrote:

I didn't test this, but my guess would be that your function is not
declared
to return an array of NewType, so you can't use the ReDim function on it.
Add an empty set of parentheses to the end of your function declaration
and
see if that clears things up...

Public Function pas_2(carrega As Integer, vector() As NewType) As
NewType()

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Dears;

I have a Nightmare with a macro!! I don' know where is the
mistake...the
program is a little bit big, so I'll try to do a resume of the code.

First of all i've created a newtype of variable called NewType (I'm not
so
much original...):

Here you are the type:

Type NewType
Peca As String
ri As Integer
pi As Integer
qi As Integer
End Type

Inside a macro I call a function like this:

seq = pas_2(C, T_Treballs())
Where C is an integer and T_Treballs() is NewType

The function is declared:
Public Function pas_2(carrega As Integer, vector() As NewType) As
NewType

There is a moment inside the function where there is this code:
y = 1
ReDim Preserve pas_2(y)

and a message like this appear:

"Compilation mistake
The program was waiting for a matrix" (or something like this, I work
with
a
spanish version and I've translated the message)

Why pas_2(y) is not a matrix inside the function??

Thanks a lot!
--
atrep




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default function with matrix

OK Rick! I've dona it and worked perfectly!
Thanks a lot for your promp response!
KR!
--
atrep


"Rick Rothstein" wrote:

Usually, when dealing with a function that returns an array, it is better to
Dim a "working" array inside your function, do all your work with it and
then, at the end, assign your working array to the function name (I think
that will also work with an array of Types).

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Thanks Rick for your promp response!

The problem has been solved, now it seems to ReDim the matrix. However a
new
problem apears. The following step inside the function is:

pas_2(y).Peca = vector(x).Peca

and this message appears:

"the argument is not optional". It seems that i'm recalling the function
inside the function...

Sure these mistakes are stupid mistakes, but this is the first time
working
with functions amd matrix at the same time...

Before I forgot to say that If there is something which I haven't
clarified
enough please, ask. I'm not englishspeaker and sure I do lots of mistakes
that can cause missunterstandings.

Thanks a lot once more!
--
atrep


"Rick Rothstein" wrote:

I didn't test this, but my guess would be that your function is not
declared
to return an array of NewType, so you can't use the ReDim function on it.
Add an empty set of parentheses to the end of your function declaration
and
see if that clears things up...

Public Function pas_2(carrega As Integer, vector() As NewType) As
NewType()

--
Rick (MVP - Excel)


"xavi garriga" wrote in message
...
Dears;

I have a Nightmare with a macro!! I don' know where is the
mistake...the
program is a little bit big, so I'll try to do a resume of the code.

First of all i've created a newtype of variable called NewType (I'm not
so
much original...):

Here you are the type:

Type NewType
Peca As String
ri As Integer
pi As Integer
qi As Integer
End Type

Inside a macro I call a function like this:

seq = pas_2(C, T_Treballs())
Where C is an integer and T_Treballs() is NewType

The function is declared:
Public Function pas_2(carrega As Integer, vector() As NewType) As
NewType

There is a moment inside the function where there is this code:
y = 1
ReDim Preserve pas_2(y)

and a message like this appear:

"Compilation mistake
The program was waiting for a matrix" (or something like this, I work
with
a
spanish version and I've translated the message)

Why pas_2(y) is not a matrix inside the function??

Thanks a lot!
--
atrep




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Matrix via function Dan Excel Programming 2 January 26th 09 10:14 PM
Funtion as Matrix function? Dietmar M. Kehrmann Excel Programming 0 April 18th 08 09:06 PM
Can I write a function like matrix function? Evaluate function parameter as VBA code[_2_] Excel Programming 2 July 23rd 07 02:16 PM
UDF function on Matrix Arrun Excel Programming 1 December 26th 06 10:51 AM
VBA function return matrix? Steve O'Hagan Excel Programming 3 January 29th 04 08:27 PM


All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"