Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

add 3 elements

Posted on 2006-04-20
10
Medium Priority
?
216 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:RyanBank
  • 5
  • 3
  • 2
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16496859

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 Comment

by:RyanBank
ID: 16497086
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16497113

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16497120

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 Comment

by:RyanBank
ID: 16497142
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16497177
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16497221
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16497227
don't accept my comment as answer since angleIII almost got it
0
 

Author Comment

by:RyanBank
ID: 16497256
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16497291
yes, that's correct. I forgot that (it's difficult to test without vb installed)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question