Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Function in class module cannot be assigned an array?

Hi there,

I wonder if anybody can explain to me why I am getting the #VALUE!
error here.

I have a function GetSimMinValue which accesses another function
MinValue built into a class module, the first function is:

Function GetSimMinValue(Identifier As Integer, Step As Integer) As
Double
GetSimMinValue = Simulations(Identifier).MinValue(Step)
End Function

This function accesses the following function in the class module:


Public Function MinValue(Step As Integer)

Dim i As Long
Dim Mins() As Double
ReDim Mins(1 To 1, 1 To 2)

' code here to set the values of Min()

MinValue = Mins
End Function


Having stepped through the function everything works fine until the
final line: MinValue=Mins which seems to be causing the error.

Does anybody have any ideas why?

Thanks in advance
Lloyd

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Function in class module cannot be assigned an array?

Lloyd,
Firstly, I wouldn't use "Step" as the name of an argument; it's used by VB
in a For/Next loop.
e.g. For i=1 To 10 Step 2

Also, you should mark the return type of you functions.
So a simlified version:

<Worksheet
Private Sub CommandButton1_Click()
MsgBox GetSimMinValue(10)(1, 1)
End Sub
</Worksheet

<Module
Function GetSimMinValue(WhichStep As Integer) As Double()
Dim Sims As Class1
Set Sims = New Class1
GetSimMinValue = Sims.MinValue(WhichStep)
End Function
</Module

<Class1
Public Function MinValue(WhichStep As Integer) As Double()
ReDim Mins(1 To 1, 1 To 2) As Double
MinValue = Mins
End Function
</Class1

NickHK

"pinkfloydfan" wrote in message
ups.com...
Hi there,

I wonder if anybody can explain to me why I am getting the #VALUE!
error here.

I have a function GetSimMinValue which accesses another function
MinValue built into a class module, the first function is:

Function GetSimMinValue(Identifier As Integer, Step As Integer) As
Double
GetSimMinValue = Simulations(Identifier).MinValue(Step)
End Function

This function accesses the following function in the class module:


Public Function MinValue(Step As Integer)

Dim i As Long
Dim Mins() As Double
ReDim Mins(1 To 1, 1 To 2)

' code here to set the values of Min()

MinValue = Mins
End Function


Having stepped through the function everything works fine until the
final line: MinValue=Mins which seems to be causing the error.

Does anybody have any ideas why?

Thanks in advance
Lloyd



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Function in class module cannot be assigned an array?

You would need to create an instance of that class, and reference the
function through that instance

Set myClass = clsClassName
myVar = myClass.MinValue(Step)

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"pinkfloydfan" wrote in message
ups.com...
Hi there,

I wonder if anybody can explain to me why I am getting the #VALUE!
error here.

I have a function GetSimMinValue which accesses another function
MinValue built into a class module, the first function is:

Function GetSimMinValue(Identifier As Integer, Step As Integer) As
Double
GetSimMinValue = Simulations(Identifier).MinValue(Step)
End Function

This function accesses the following function in the class module:


Public Function MinValue(Step As Integer)

Dim i As Long
Dim Mins() As Double
ReDim Mins(1 To 1, 1 To 2)

' code here to set the values of Min()

MinValue = Mins
End Function


Having stepped through the function everything works fine until the
final line: MinValue=Mins which seems to be causing the error.

Does anybody have any ideas why?

Thanks in advance
Lloyd



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Function in class module cannot be assigned an array?

Thankyou Nick

I will use that presentation style in future. I should also have said
that "Simulations" was a global array of the specific Class.

However, your code has highlighted my error: it seems that each
function should have been defined with "As Double()" in order to
accept an array rather than both or one "As Double". I guess that not
adding this qualifier to both functions would also be ok.

Cheers
Lloyd


On 28 Feb, 11:25, "NickHK" wrote:
Lloyd,
Firstly, I wouldn't use "Step" as the name of an argument; it's used by VB
in a For/Next loop.
e.g. For i=1 To 10 Step 2

Also, you should mark the return type of you functions.
So a simlified version:

<Worksheet
Private Sub CommandButton1_Click()
MsgBox GetSimMinValue(10)(1, 1)
End Sub
</Worksheet

<Module
Function GetSimMinValue(WhichStep As Integer) As Double()
Dim Sims As Class1
Set Sims = New Class1
GetSimMinValue = Sims.MinValue(WhichStep)
End Function
</Module

<Class1
Public Function MinValue(WhichStep As Integer) As Double()
ReDim Mins(1 To 1, 1 To 2) As Double
MinValue = Mins
End Function
</Class1

NickHK

"pinkfloydfan" wrote in message

ups.com...



Hi there,


I wonder if anybody can explain to me why I am getting the #VALUE!
error here.


I have a function GetSimMinValue which accesses another function
MinValue built into a class module, the first function is:


Function GetSimMinValue(Identifier As Integer, Step As Integer) As
Double
GetSimMinValue = Simulations(Identifier).MinValue(Step)
End Function


This function accesses the following function in the class module:


Public Function MinValue(Step As Integer)


Dim i As Long
Dim Mins() As Double
ReDim Mins(1 To 1, 1 To 2)


' code here to set the values of Min()


MinValue = Mins
End Function


Having stepped through the function everything works fine until the
final line: MinValue=Mins which seems to be causing the error.


Does anybody have any ideas why?


Thanks in advance
Lloyd- Hide quoted text -


- Show quoted text -



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
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
class module? sybmathics Excel Programming 17 February 25th 06 02:29 PM
Class module in VBA romkeys Excel Programming 1 August 19th 04 06:20 PM
Calling a module function from a class method ranafout[_2_] Excel Programming 1 November 12th 03 11:08 AM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 08:20 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"