Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log function

Status
Not open for further replies.

irishjoe

Programmer
Aug 5, 2002
76
AU
Hi,

I have the following code for working out a log function. When I put it in my database I get this error.

"The expression On Load you entered as the event property setting produced the following error: Expected variable or procedure, not module."

The code is;
Static Function Log10(X)
Log10 = Log(X) / Log(10#)
End Function
(Straight from the access help.)

The wierd thing it works in one database and not another. I have checked the references and they are the same.

Thanks for any help anyone can give me...
 
I think this may depend on where exactly you put the function in your database. I tried setting up this Public Function in a module:

Code:
Public Function Log10(X As Double)
   Log10 = Log(X) / Log(10#)
End Function

I then tested it by creating a button on a test form, with this test code in its On_Click event:

Code:
Private Sub btnTest_Click()
    MsgBox Log10(Me.RecordID)
End Sub

The form has an AutoNumber field called RecordID, but you could obviously test with any numeric field.

This worked every time for me - the correct Log(10) value was displayed as a message.

I hope that these notes will help you in your own database.


Bob Stubbs
 
Bob,

Thanks for your reply.
I think there may be something wrong with my database because I tried that and it comes up with the following error at the Log10 = Log(x)/Log(10#) line.

Compile Error:
Expected variable or procedure, not module.

Its wierd, it works fine on one database and then I copy and paste the form into another database, it doesn't work.
 
I guess your module is named Log10.
If this is the case, simply rename it with something different that any public method/property/function/procedure name.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I changed it to

Public Function Log10JOE(X As Double)
Log10JOE = Log(X) / Log(10#)
End Function

and put it in a module.

But it is coming up with the same error at the Log(X) part.
 
How is named the Module ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Its called ExtraModules but i have never had to specify where the function is if it in a module.

Its on its own with "Option Compare Database" at the top.

The references are as follows.
-Visual Basic for Applications
-Microsoft Access 9.0 Object Library
-Microsoft ActiveX Data Objects 2.1 library
-Microsoft Windows Common Controls 6.0 (SP6)
-OLE Automation
-ctv OLE Control module
-Microsoft DAO 3.6 Object Library
-Microsoft Calendar Control 9.0

The code to call it is as follows. (Excuse the length, its just copied and pasted from my database...)
TempF1 = 10 ^ ((2400 / (Temperature + 273)) - (0.6 * Log10JOE(FCO2)) - 6.7)

FCO2 is declared as,
Dim FCO2 As Double
 
Ok, something is definately wrong...
I created a new database with just the bits that use the log function bit and it works perfectly!
I did exactly the same thing but in the database that I want it to go into, it doesnt work.

Whats this all about? Bug? Corrupt Database?
 
AAAAGGGGGHHHHH!!!!
I tried creating a new database then importing all the tables, queries, forms, reports and modules. Now when I run my main menu, which hasn't been touched, it is coming up with the original error message!

Could this be a virus or something?
(I should have never stopped using Java!)
 
Expected variable or procedure, not module
Check all the module names vs public method/property/function/procedure names.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I will have a look at it again tomorrow. I've gone a bit brain dead.
I'll create a new database and slowly add the data and see when it starts to die.

Thanks for your help. Greatly appreciated...
 
just as a "sanity" check, try using this adaptation of your function:

Code:
Public Function basLog_N(X As Double, N As Double)
   basLog_N = Log(X) / Log(N)
End Function

with the following example syntax.

Code:
? basLog_N(10, 10)
 1

Although the mod does offer some additional flexability, it is (praticaly) useless to most and requires the additional parameter, so not very suitable for general use. It might work it there is a naming conflict embedded in other objects.





MichaelRed


 
After spending a fair few hours ripping my database apart, I found the problem.
There was a function that on certain conditions adds a record into a table. Like if someone deletes a record, their name, time and record deleted is added to the table.

Can anyone guess what this table was called???
LOG!!!
It was something like Log(name, date, time, area, item)
Thats why it was crashing on the log bit.

Thanks to all for their help, without which I would still be kicking the computer and telling it to just work...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top