Hi,

Please kindly assist how can we do the following:

arr_req=1,2,3,4,5,6,7,8,9,10
add 3 elements from the current element and move to the next element and loop.

1+2+3=6 -element 1
2+3+4=9 -element 2
...
for the element that will be less than the slots, continue with the first element.
9+10+1=element 9
10+1+2=element 10

output:
arr_reqconverted=6,9,12,15,18,21,24,27,20,13

dim intSumofSlots as integer
arr_req=1,2,3,4,5,6,7,8,9,10
Dim Arr_ReqConverted() As String

For i = 0 To UBound(arr_req)
intSumOfSlots = 0
For x = 0 To intSlot - 1

If i + x < 11 Then
intSumOfSlots = intSumOfSlots + i+x
else
intSumOfSlots = intSumOfSlots + CInt(arr_req(i + x - 10))
endif
next
Arr_ReqConverted(i) = intSumOfSlots
next
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Billing EngineerCommented:

dim intSumofSlots as integer
Dim Arr_ReqConverted() As String

For i = 0 To UBound(arr_req)
arr_req(i) = i
next

for i = UBound(arr_req)
intSumOfSlots = 0
for x = i to i + 2
if x < ubound(arr_req) then
intSumOfSlots = intSumOfSlots + arr_req(x)
next x
arr_req(i)= intSumOfSlots
next i

0
Author Commented:
not sure What I have type in wrongly but

Output came out:3,6,9,12,15,18,21,15,8,0

output should be:
arr_reqconverted=6,9,12,15,18,21,24,27,20,13

Private Sub Command1_Click()
Dim intSumofslots As Integer
ReDim Preserve arr_req(9)
For i = 0 To UBound(arr_req)
arr_req(i) = i
Next
For i = 0 To UBound(arr_req)
intSumofslots = 0
For x = i To i + 2
If x < UBound(arr_req) Then intSumofslots = intSumofslots + arr_req(x)
Next x
arr_reqConverted(i) = intSumofslots
Next i
Debug.Print Join(arr_reqConverted, ",")

End Sub

0
Billing EngineerCommented:

Private Sub Command1_Click()
Dim intSumofslots As Integer
ReDim Preserve arr_req(9)
For i = 0 To UBound(arr_req)
arr_req(i) = i+1
Next
For i = 0 To UBound(arr_req)
intSumofslots = 0
For x = i To i + 2
If x < UBound(arr_req) Then intSumofslots = intSumofslots + arr_req(x)
Next x
arr_reqConverted(i) = intSumofslots
Next i
Debug.Print Join(arr_reqConverted, ",")

End Sub
0
Billing EngineerCommented:

Private Sub Command1_Click()
Dim intSumofslots As Integer
ReDim Preserve arr_req(9)
For i = 0 To UBound(arr_req)
arr_req(i) = i + 1  <<<< correction here
Next
For i = 0 To UBound(arr_req)
intSumofslots = 0
For x = i To i + 2
If x <= UBound(arr_req) Then intSumofslots = intSumofslots + arr_req(x)     <<<< correction here
Next x
arr_reqConverted(i) = intSumofslots
Next i
Debug.Print Join(arr_reqConverted, ",")

End Sub
0
Author Commented:
Finish changing, sad to say not a complete match:

Output came out:6,9,12,15,18,21,24,17,9,0

output should be:
arr_reqconverted=6,9,12,15,18,21,24,27,20,13
0
Billing EngineerCommented:
Private Sub Command1_Click()
Dim intSumofslots As Integer
ReDim Preserve arr_req(9)
For i = 0 To UBound(arr_req)
arr_req(i) = i + 1
Next
For i = 0 To UBound(arr_req)
intSumofslots = 0
For x = i To i + 2
If x <= UBound(arr_req) Then
intSumofslots = intSumofslots + arr_req(x)
else
intSumofslots = intSumofslots + arr_req(x - ubound(arr_req) + lbound(arr_req))
end if
Next x
arr_reqConverted(i) = intSumofslots
Next i
Debug.Print Join(arr_reqConverted, ",")

End Sub
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
chagne this

For x = i To i + 2
If x <= UBound(arr_req) Then intSumofslots = intSumofslots + arr_req(x)     <<<< correction here
Next x

to

For x = i To i + 2
If x <= UBound(arr_req) Then
intSumofSlots = intSumofSlots + arr_req(x)     '<<<< correction here
Else
intSumofSlots = intSumofSlots + arr_req(x - 10)
End If
Next x
0
Commented:
don't accept my comment as answer since angleIII almost got it
0
Author Commented:
I added a "-1" in the code below, please kindly let me know if this is correct?

Dim intSumofslots As Integer
ReDim Preserve arr_req(9)
ReDim Preserve Arr_ReqConverted(9)

For i = 0 To UBound(arr_req)
arr_req(i) = i + 1
Next
For i = 0 To UBound(arr_req)
intSumofslots = 0
For x = i To i + 3
If x <= UBound(arr_req) Then
intSumofslots = intSumofslots + arr_req(x)
Else
intSumofslots = intSumofslots + arr_req(x - UBound(arr_req) + LBound(arr_req) - 1)   <-----here
End If
Next x
Arr_ReqConverted(i) = intSumofslots
Next i
Debug.Print Join(Arr_ReqConverted, ",")
0
Billing EngineerCommented:
yes, that's correct. I forgot that (it's difficult to test without vb installed)
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.