|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
For Next
I have a bit of code below that is calling another bit of code that is capturing a value and doing some calculations and setting it to a global variable. I then display that calculated value in a message box (see below "Result"). This is in a FOR loop so it repeats 10 times. That works great.
What I want to do next and the reason for this email is to: 1. Each time in run through the loop I want to add the values together. 2. Once I have them I want to divide by 10 to get a mean value. 3. I am looking to get this to run automatically, grabbing 10 values and adding them together. Does anyone have any hints or examples of how I can add these values together and return one value. Right now I have to hit the message box 10 times. I want this to run automatically and return one number.... THANKS IN ADVANCE CODE: Private Sub Command970_Click() Dim intLoopIndex Dim Result For intLoopIndex = 1 To 10 'Total = Ycoord2 + 1 'MsgBox Total Call Command8_Click Result = YCoord3 + 1 MsgBox Result Next intLoopIndex End Sub |
|
#2
|
|||
|
|||
|
FOR THOSE INTERESTED IN THE ANSWER TO MY QUESTION I FIGURED IT OUT.....
I figured it out. Part of my problem was that some variables were strings, integer, double. I converted them all to Double to retain sig figures. 1. As it goes through the FOR LOOP it adds the values. 2. It then multiplies by .1 (or dividing by 10) For some reason Access wont divide. 3. Finally I place it in a field in my Form CODE: Private Sub Command970_Click() Dim intLoopIndex Dim Result As Double For intLoopIndex = 1 To 10 Call Command8_Click Dim Num Num = CDbl(YCoord3) Result = Result + Num ' This will count from 1 to 10 inside the MsgBox Next intLoopIndex Result = Result * 0.1 Dim Result2 Result2 = CStr(Result) Forms!frmAddSign!Y.SetFocus If Result2 = "" Then Y.Text = "000.00" Else Y.Text = Result2 End If End Sub |
|
#3
|
|||
|
|||
|
Thanks for posting your solution.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > For Next |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|