Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 20th, 2004, 01:57 PM
Randy U Randy U is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Randy U User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Porblem with a module..any help is appreciated.

I have a module that I have made a custom function in. It calculates the Standard Deviation for row level values.
I use 6 variables in the Sub Procedure on the form.
If I use 1, 2, 3 or 4 variables it returns a value that looks like a "Scientific" data type "ie: 5E-07"
If I use 5 or 6 variables it works perfectly except for one thing----if all the variables are the same which should give me an answer of 0.00000 I get an error in a line of the code in the macro. This part is giving me problems:

If n > 0 Then 'only applies if points available
RStDevP = Sqr((n * dblSumOfSq - dblSum * dblSum) / n / n)
Else
RStDevP = Null
End If

Can anyone look at it and help me with what is wrong?
Thanks in advance!

Function RStDevP(ParamArray FieldValues()) As Variant
Dim dblSum As Double, dblSumOfSq As Double
Dim n As Long
Dim varArg As Variant
For Each varArg In FieldValues
If IsNumeric(varArg) Then
dblSum = dblSum + varArg
dblSumOfSq = dblSumOfSq + varArg * varArg
n = n + 1
End If
Next
If n > 0 Then 'only applies if points available
RStDevP = Sqr((n * dblSumOfSq - dblSum * dblSum) / n / n)
Else
RStDevP = Null
End If

End Function



The Data type is Double
It's specifically this part that is giving the following error:

"Invalid Procedure Call or Argument"

RStDevP = Sqr((n * dblSumOfSq - dblSum * dblSum) / n / n)

One more thing....
If all 6 values are the same and they are =< 2 as a whole number or decimal like 0.5 then I get the error.
If the values are all 4 as a whole number then I get the error.
If the values are all the same except for the above numbers then i get that funky scientific date type value.

Again it works fine if the numbers are different.

Reply With Quote
  #2  
Old November 20th, 2004, 06:21 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 4
Hi Randy,

Might want to check the formula. In the function Sqr() your totals are ending up in a negative number and then trying to square that number, which will result in an error.

Try this and see if it will work

RStDevP = Sqr((dblSum * dblSum - n * dblSumOfSq) / n / n)

lwells

Reply With Quote
  #3  
Old November 21st, 2004, 08:10 AM
Randy U Randy U is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 Randy U User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I did not actually use that smip you sent me because when you said negative number I thought that I could jsut add a "Abs" to always get a positive answer.
It worked.

I still am dealing with the return of weird answers. ir "1E-08". How do I get a number to show up.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Porblem with a module..any help is appreciated.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway