Re: simple function question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Fri, 10 Jun 2005 21:55:17 -0400, "Don Shepherd" <nospam@xxxxxxxxxx> wrote:

>OK, I can't get this function to return anything other than #VALUE! What am
>I doing wrong? The function is in a module, and the input parameter is a
>reference to a cell containing an integer.
>
>Function my_digit_patt(a) As Integer
>Dim ct(9) As Integer
>For i = 1 To Len(a)
>ct(Val(Mid(a, i, 1))) = ct(Val(Mid(a, i, 1))) + 1
>Next
>b = 0
>For i = 0 To 10
>b = b + ct(i) * 10 ^ (10 - i)
>Next
>my_digit_patt = b
>End Function
>

Well, I see a few problems off the top of my head.

1. On line 7: For i = 0 To 10
You are using i as the subscript for ct. But the upper bound of ct is
only 9. So when i=10, the subscript will be out of range.

2. You have specified that your function should return an integer. But the
allowable range for integers in VBA is -32,768 to 32,767. Depending on the
range of values being passed to the function, the result may be out of range of
your data type.


--ron
.



Relevant Pages

  • simple function question
    ... The function is in a module, and the input parameter is a ... reference to a cell containing an integer. ... Dim ctAs Integer ... Prev by Date: ...
    (microsoft.public.excel.programming)
  • Exception as Parameter
    ... Is that possible to use exception as an input parameter in IDL ... Prev by Date: ...
    (comp.object.corba)
  • nvarchar(max) sql data type equivalen in c#
    ... i am writing a UDF which takes nvarcharas input parameter. ... tell me what is the equivalent of this data type in C#. ... Thx ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to call an oracle function
    ... > but still getting the same exception ... Are there *more* parameters in the stored function than the input parameter ... // Bjorn A ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • INTEGER-OF-DATE
    ... The help for this function states that for the date input parameter, ... back a particular result that indicates an invalid input parm? ... Prev by Date: ...
    (comp.lang.cobol)