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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch when calling a VB function from ASP

Status
Not open for further replies.

SuaveRick

Programmer
Apr 12, 2004
142
CA
Hi there,

I just want to write to a log file, nothing fancy. I have a vb function setup in the <script> that will do this. From the asp I call logIt("message goes here") and I get a type mismatch when it tries to call the logIt function.

The function just has function logIt(strMessage) and doesn't work, just says 'Type Mismatch: logIt'

Anyone run into this before?

Thanks!
 
Show the code you have calling the function, as well as the function itself. Is this ASP, or client-side scripting?

Lee
 
This is in the script:

function logIt(strMessage)

dim fso, textFile

set fso = CreateObject("Scripting.FileSystemObject")
set textFile = fso.CreateTextFile("text.txt",true)
textFile.WriteLine(strMessage)
textFile.Close

end function

This is the ASP:
<%
dim strMsg
strMsg = "this is a test message for the log file"
call logIt(strMsg)
%>

Thanks for any help.
 
try using sub instead of function.

...
sub logIt(strMessage)
...
end sub
...
call logIt(strMsg)
...
 
Hm. Are you declaring logIt as a variable?

dim logIt

Just asking.
 
I am trying to say DON'T declare logIt as a variable.
 
You can't call a client side function/sub from server side scripting. Unless you have the function logIt inside ASP tags, you're writing it out for client side processing, which means it doesn't exist until after the server is done processing the ASP script and has delivered it to the client. If you DO have it in ASP tags, then you should have shown that. I don't think you do, though, because you didn't use Server.CreateObject.

Lee
 
@trollacious

I think you hit the nail on the head.

SuaveRick's Code:
Code:
set fso = CreateObject("Scripting.FileSystemObject")

Should Be:
Code:
set fso = Server.CreateObject("Scripting.FileSystemObject")
 
If he didn't put it inside ASP tags, though, it doesn't matter WHAT he uses because it's a client-side function.

Lee
 
oh I know, but I really think SuaveRick left the tags out in the post, not his code. It would be blantantly obvious to SuaveRick if he didn't enclose the code with <%%>; it would just paint the code as HTML to the response buffer otherwise.
 
I had the function in the client side, you are right. I'll have to try it in the ASP then. It does make sense though, the asp wouldn't see the function at all the way I have it now. Good catch!!

I can still do all the same stuff in the asp as I can in the vbscript right? Like write to a file?

That I can figure out.

Thanks all!!!
 
ASP is not a language, it is a kind of functionality package. You can use VBScript, JScript, PerlScript, or PythonScript (and probably others I don't know about) to write code that will work in ASP. If it's not JScript or VBScript (which are built into IIS), you have to add in your scripting engine, but that's the only difference.

Yes, you can write to files with ASP, but only on the server. ASP stands for Active Server Pages, and nothing you write with ASP will be executed on the client's computer.

VBScript on the client side will only work with Internet Explorer, and if your web page is going on the Internet, you'll alienate a growing percentage of viewers if you use that language for scripting.

Lee
 
I (somehow) totally missed the fact that you were executing a VB Script(*.vbs) not ASP VBScript(*.asp). Sorry!

That's what lack of sleep does I suppose. [sleeping2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top