0

I have a loop, and I want to put the result into array. Here is my loop.

    For i = 1 To bill
        a = rs("CT08_Tarikh") 'from db
        cutiumum = Array(a)   'and this is how I declare array
        rs.MoveNext
    Next
    rs.Close
    Set rs = Nothing
End If

and after that, i will pass the variable to another function:

tarikh = NetWorkdays(dateFrom, dateTo, cutiumum)

Public Function NetWorkdays(dtStartDate, dtEndDate, arrHolidays)

but, when I try to do some loop for arrHolidays inside the function NetWorkdays, it only return 1 data (not all from the cutiumum).

What do you think is my mistake?

Update

I'm already using

dim arrRecordset

arrRecordset = rs.GetRows()

but I got an error inside the function

Public Function NetWorkdays(dtStartDate, dtEndDate, arrHolidays)
    Dim lngDays
    Dim lngSaturdays
    Dim lngSundays
    Dim lngHolidays
    Dim lngAdjustment
    Dim dtTest
    Dim i, x

    lngDays = DateDiff("d", dtStartDate, dtEndDate)
    lngSundays = DateDiff("ww", dtStartDate, dtEndDate, vbSunday)
    lngSaturdays = DateDiff("w", IIf(Weekday(dtStartDate, vbSunday) = vbSaturday, dtStartDate, dtStartDate - Weekday(dtStartDate, vbSunday)), dtEndDate)

    For x = LBound(arrHolidays) To UBound(arrHolidays)
        For i = 0 To lngDays
            dtTest = DateAdd("d", i, dtStartDate)

'error in line here: Subscript out of range: 'arrHolidays'
            If arrHolidays(x) = dtTest And Weekday(dtTest) <> 1 And Weekday(dtTest) <> 7 Then
                lngHolidays = lngHolidays + 1
            End If
        Next
    Next

    If Weekday(dtStartDate, vbSunday) = vbSunday Or Weekday(dtStartDate, vbSunday) = vbSaturday Then
        lngAdjustment = 0
    Else
        lngAdjustment = 1
    End If

    NetWorkdays = lngDays - lngSundays - lngSaturdays - lngHolidays + lngAdjustment
End Function

1 Answer 1

2

Try this:

dim arrRecordset
arrRecordset = rs.GetRows()

The getRows() method will transform a recordset into a two dimensional array in one go:

https://www.w3schools.com/asp/met_rs_getrows.asp

Sign up to request clarification or add additional context in comments.

5 Comments

it looks good , but I got an error . I already update my question and if you could take a look, i appreciate.
Is this the same array you create with getRows()? In that case it might be because the array is two-dimensional. You need to provide UBound and LBound with a dimension: w3schools.com/asp/func_lbound.asp
These problems are easy to find if you use a debugger. Do you have (free) Visual Studio installed? You can use it to debug ASP. Add the word "stop" somewhere in your ASP code, and VS will break there. msdn.microsoft.com/en-us/library/ms525253(v=vs.90).aspx
Ok. I will. Thank you.
Here is a more detailed explanation on how to debug asp with VS. weblogs.asp.net/dixin/debugging-classic-asp-with-visual-studio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.