Re: simple function question
- From: Ron Rosenfeld <ronrosenfeld@xxxxxxxxxx>
- Date: Fri, 10 Jun 2005 22:30:05 -0400
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
.
- References:
- simple function question
- From: Don Shepherd
- simple function question
- Prev by Date: Re: simple function question
- Next by Date: Re: Help in copying range
- Previous by thread: Re: simple function question
- Next by thread: Re: simple function question
- Index(es):
Relevant Pages
|