473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Public Function Compile Error

I appreciated the help I received through this newsgroup some time ago to
build a module to change a students score into a curriculum level eg score
of 24 gives a grade of "6a". However, I am now struggling to build a module
that does the opposite! That is to take a grade and allocate it a score. I
looked at the first module (listed below) and changed it around to give what
I thought was a logical solution. But it don't work! Error says something
about a missing object. I don't know enough to fix it, could anyone please
point me in the right direction? It would also be useful to know if I can
use the same module for a range of conversions in the same query or does
each conversion need it's own query?

Original Module was...

Public Function GetGrade(AvgScore As Double) As String

AvgScore = Nz(AvgScore, 0)

Select Case AvgScore

Case Is >= 36

GetGrade = "8a"

Case Is >= 34

GetGrade = "8b"

Case Is >= 32

GetGrade = "8c"

Case Is >= 30

GetGrade = "7a"

Case Is >= 28

GetGrade = "7b"

Case Is >= 26

GetGrade = "7c"

Case Is >= 24

GetGrade = "6a"

Case Is >= 22

GetGrade = "6b"

Case Is >= 20

GetGrade = "6c"

Case Is >= 18

GetGrade = "5a"

Case Is >= 16

GetGrade = "5b"

Case Is >= 14

GetGrade = "5c"

Case Is >= 12

GetGrade = "4a"

Case Is >= 10

GetGrade = "4b"

Case Is >= 8

GetGrade = "4c"

Case Is >= 6

GetGrade = "3a"

Case Is >= 4

GetGrade = "3b"

Case Is >= 2

GetGrade = "3c"

Case Is 0

GetGrade = "W"

Case Else

GetGrade = "U"

End Select

End Function

My attempt at reversing it was...

Public Function GetScore(NCLGym As Text) As String
NCLGym = Nz(NCLGym, 0)
Select Case NCLGym
Case Is = "8a"
GetScore = 36
Case Is = "8b"
GetScore = 34
Case Is = "8c"
GetScore = 32
Case Is = "7a"
GetScore = 30
Case Is = "7b"
GetScore = 28
Case Is = "7c"
GetScore = 26
Case Is = "6a"
GetScore = 24
Case Is = "6b"
GetScore = 22
Case Is = "6c"
GetScore = 20
Case Is = "5a"
GetScore = 18
Case Is = "5b"
GetScore = 16
Case Is = "5c"
GetScore = 14
Case Is = "4a"
GetScore = 12
Case Is = "4b"
GetScore = 10
Case Is = "4c"
GetScore = 8
Case Is = "3a"
GetScore = 6
Case Is = "3b"
GetScore = 4
Case Is = "3c"
GetScore = 2
Case Is = "W"
GetScore = 0
Case Else
GetScore = "U"
End Select
End Function

Thanks in anticipation from a Virtual (Basic) Virgin!.


Jul 17 '06 #1
2 1327
My attempt at reversing it was...
>
Public Function GetScore(NCLGym As Text) As String
NCLGym = Nz(NCLGym, 0)
Select Case NCLGym
Case Is = "8a"
GetScore = 36
Case Is = "8b"
GetScore = 34
Case Is = "8c"
GetScore = 32
Case Is = "7a"
GetScore = 30
Case Is = "7b"
GetScore = 28
Case Is = "7c"
GetScore = 26
Case Is = "6a"
GetScore = 24
Case Is = "6b"
GetScore = 22
Case Is = "6c"
GetScore = 20
Case Is = "5a"
GetScore = 18
Case Is = "5b"
GetScore = 16
Case Is = "5c"
GetScore = 14
Case Is = "4a"
GetScore = 12
Case Is = "4b"
GetScore = 10
Case Is = "4c"
GetScore = 8
Case Is = "3a"
GetScore = 6
Case Is = "3b"
GetScore = 4
Case Is = "3c"
GetScore = 2
Case Is = "W"
GetScore = 0
Case Else
GetScore = "U"
End Select
End Function
I wouldn't do this with VB at all. I'd use SQL. As long as you have a
fixed number of possible values, just put all the (textscore, numeric
score) combinations in a table, and then just use a simple SQL
statement.

Something along the lines of:

Option Compare Database

Public Function ConvertScore(ByVal strScore As String) As Integer
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT NumericScore FROM tblScores WHERE TextScore = '" &
strScore & "';"

Set rs = DBEngine(0)(0).OpenRecordset(strSQL, dbOpenSnapshot)

If rs.RecordCount = 0 Then
ConvertScore = 0
Else
ConvertScore = rs.Fields(0)
End If

rs.Close
Set rs = Nothing

End Function

Jul 18 '06 #2
Thank you for your response.
It worked OK once I changed (NCLGym As Text) to (NCLGym As String).

Regards
Penfold
<pi********@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
My attempt at reversing it was...

Public Function GetScore(NCLGym As Text) As String
NCLGym = Nz(NCLGym, 0)
Select Case NCLGym
Case Is = "8a"
GetScore = 36
Case Is = "8b"
GetScore = 34
Case Is = "8c"
GetScore = 32
Case Is = "7a"
GetScore = 30
Case Is = "7b"
GetScore = 28
Case Is = "7c"
GetScore = 26
Case Is = "6a"
GetScore = 24
Case Is = "6b"
GetScore = 22
Case Is = "6c"
GetScore = 20
Case Is = "5a"
GetScore = 18
Case Is = "5b"
GetScore = 16
Case Is = "5c"
GetScore = 14
Case Is = "4a"
GetScore = 12
Case Is = "4b"
GetScore = 10
Case Is = "4c"
GetScore = 8
Case Is = "3a"
GetScore = 6
Case Is = "3b"
GetScore = 4
Case Is = "3c"
GetScore = 2
Case Is = "W"
GetScore = 0
Case Else
GetScore = "U"
End Select
End Function

I wouldn't do this with VB at all. I'd use SQL. As long as you have a
fixed number of possible values, just put all the (textscore, numeric
score) combinations in a table, and then just use a simple SQL
statement.

Something along the lines of:

Option Compare Database

Public Function ConvertScore(ByVal strScore As String) As Integer
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT NumericScore FROM tblScores WHERE TextScore = '" &
strScore & "';"

Set rs = DBEngine(0)(0).OpenRecordset(strSQL, dbOpenSnapshot)

If rs.RecordCount = 0 Then
ConvertScore = 0
Else
ConvertScore = rs.Fields(0)
End If

rs.Close
Set rs = Nothing

End Function

Jul 18 '06 #3

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

Similar topics

6
1880
by: muser | last post by:
In the following function there is an access violation error, some memory can't be read. A week ago this code did compile. Can anyone possibly tell me why my compiler is unable to read part of...
8
8737
by: Aman | last post by:
does it matter if a typedef is declared under public or private ? does any one (public or private ) constitute better design ? -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
19
2310
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
11
2405
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
2
3619
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
4
2403
by: Peter Speybrouck | last post by:
I have a little problem with a webservice. I reproduced the problem in the following simplified example. I just create a new C# ASP.NET webservice and a c# console application. I added a new...
12
2651
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
7
1262
by: Penfold | last post by:
Hi, I benefited from this newsgroups help to compile a public function to convert numeric scores to alphanumeric grades. Now I need to reverse the process to allocate a numeric score to each...
1
2922
by: Angus | last post by:
Why moving a function from protected to public area in class causes error C2556 - overloaded function differs only by return type I have a protected function called GetState like this: enum...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.