Question

I've written a function that returns the minimum values of the 8 numerical values inputted through SSRS.

Problem is there is not always 8 values and when there isn't I receive an error in SSRS. i think this is because I'm feeding the function null values

I don't ever work with VB, is there anyone who can show me a work around?

The code used is below enter code here

Function minimumReading(reading0 as String
                        ,reading1 as String 
                        ,reading2 as String
                         ...    7 as String)

Dim     a(7) as String
        a(0) = reading0
        a(1) = reading1
        ...
        a(7) = reading7
Dim max as string
    Dim min as string

max = a(3)
min = a(3)

Dim i as integer

for i = Lbound(a) to Ubound(a)
    if a(i) < min Then min = a(i)
next i

minimumReading =  min

End Function` 

Thanks in advance

Was it helpful?

Solution

Do you need to pass the 8 values as individual arguments? It would be better form (also easier to maintain long run) to create a function that finds the minimum of an array (which might already exist)

If you must have it the way you have setup you can use this

Dim a() As String
ReDim a(0 To 0)
Dim i As Long
If reading0 <> vbNullString Then
    a(UBound(a)) = reading0
End If
If reading1 <> vbNullString Then
    ReDim Preserve a(LBound(a) To (UBound(a) + 1))
    a(UBound(a)) = reading1
End If
If reading2 <> vbNullString Then
    ReDim Preserve a(LBound(a) To (UBound(a) + 1))
    a(UBound(a)) = reading2
End If
...

Again my suggestion is to restructure your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top