473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Average of strings

I have several queries, which generate about 10 fields each a text
field of length 2 (which contain effort and attainment grades), eg A2,
B4, A3, A3. I am trying to calculate an 11th fields, which is an
average of the other fields (in this case A3). Does anyone have any
ideas?

Tony Lennard
Nov 13 '05 #1
3 1775
Can you assign a numeric value to each text value, do the average, and then
lookup what text value is closest to the numeric average?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Tony Lennard" <to**@lennarda.freeserve.co.uk> wrote in message
news:9c**************************@posting.google.c om...
I have several queries, which generate about 10 fields each a text
field of length 2 (which contain effort and attainment grades), eg A2,
B4, A3, A3. I am trying to calculate an 11th fields, which is an
average of the other fields (in this case A3). Does anyone have any
ideas?

Tony Lennard

Nov 13 '05 #2
Tony Lennard wrote:
I have several queries, which generate about 10 fields each a text
field of length 2 (which contain effort and attainment grades), eg A2,
B4, A3, A3. I am trying to calculate an 11th fields, which is an
average of the other fields (in this case A3). Does anyone have any
ideas?

Tony Lennard


I might create another query. Drop in the query you created and drag
all fields or the * to it.

Create another column. Enter something like
AvgOfThe10 : GetAvg([Col1], [Col2]...[Col10])

This will call the function, contained in a module, called GetAvg.

Now, I suppose an A is greater than a B and so on. In the function, you
could get the left value. Let's assign A=5, B = 4...F = 1.

Now add the left value times 10 plus the right value
A3 = 5 * 10 + 3
53
B4 = 4 * 10 + 4
44

So now you add up all of the numbers and divide by 10 to get the average.

Let's say you had all 9 A1's and 1 A2. The number you would get would
be 583. Ex (59*9) + (52*1)

The average would be 58.

Now you calc for the letter. Int(58/10) = 5. So you determine that is
an A.

You can subract 58-(5*10) to get 8. Thus the average is A8.

Public Function GetAvg(v1, v2, v3....v10) As String
Dim intNumber As Integer
Dim intAvg As Integer
Dim intRemain As Integer
Dim intLetter As Integer
'get the total
intNumber = intNumber + (ParseValue(v1)*10) + Cint(Right(V1,1))
intNumber = intNumber + (ParseValue(v2)*10) + Cint(Right(V2,1))
intNumber = intNumber + (ParseValue(v3)*10) + Cint(Right(V3,1))
intNumber = intNumber + (ParseValue(v4)*10) + Cint(Right(V4,1))
...
'583 using the example above
intNumber = intNumber+(ParseValue(v10)*10) + Cint(Right(V10,1))

'get the average...58
intAvg = Int(intNumber / 10)

'we have 10 items we are avging and we multiplied by 10
'the letter so...83
intRemain = intNumber Mod 100

'get the letter...A
GetAvg = ParseAlpha(intAvg)

'note...Cint does rounding.
'Cint(80..85/10) = 8
'Cint(86..89/10) = 9
GetAvg = GetAvg & CInt(intRemain/10)

'this will return A8 to the column in the query

End Function
Public Function ParseValue(var)
Select case Left(var,1)
Case "A"
ParseValue = 5
Case "B"
ParseValue = 4
Case "C"
ParseValue = 3
Case "D"
ParseValue = 2
case else
ParseValue = 1
end select
End Function
Public Function ParseAlpha(var)
'we divide by 10 because A = 5*10 = 50
Select case Int(var/10)
Case 5
ParseAlpha = "A"
Case 4
ParseAlpha = "B"
Case 3
ParseAlpha = "C"
Case 2
ParseAlpha = "D"
case else
ParseAlpha = "E"
end select
End Function
Nov 13 '05 #3
"Tony Lennard" <to**@lennarda.freeserve.co.uk> wrote in message
news:9c**************************@posting.google.c om...
I have several queries, which generate about 10 fields each a text
field of length 2 (which contain effort and attainment grades), eg A2,
B4, A3, A3. I am trying to calculate an 11th fields, which is an
average of the other fields (in this case A3). Does anyone have any
ideas?


If your design is normalized you should have the attainable grades in a
separate table. Just add another column to the table to hold the numeric
score vales.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sara | last post by:
I am trying to find the average number of products of the set that is on rows...dynamically. For example, if I had states on rows and was looking at the average number of products, I would see...
6
by: J | last post by:
Kind of new at programming/vb.net. I'm doing this junky die roller program. Heres's what is supposed to happen: Roll 2 6-sided dies. Add rolls together put total in rolls(d6total). Display...
4
by: Gary | last post by:
Hi, I have a temperature conversion program down pat, but I was told to add an average, meaning, i need to get the average temperature for as many times as it was entered. i do not know where to...
3
by: C++Geek | last post by:
I need to get this program to average the salaries. What am I doing wrong? //Program to read in employee data and calculate the average salaries of the emplyees.
2
by: jarosciak | last post by:
Hi everyone, I need a little bit of help with this problem. I've got a time durations feed, which comes in this format (minutes:seconds): Example, there is only 5 values:
8
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way?...
3
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows...
3
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average....
5
by: p3rk3le | last post by:
So, I'm about to do a sequential search on a table (n contents) of random numbers. I have to print the average between the number of comparisons and the contents of the table (n) and the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.