Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 15th, 2004, 05:24 PM
Registered User
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling external classes and/or subs/funcs

I'm having a lot of trouble getting my VBS to do what I want it to. I can't seem to figure out how to a) register a class that resides in a file, b) call a sub that resides in a file, or c) not go nuts.

Yes, it's driving me nuts. addToQueue is defined in pcontrol.vbs as a Sub. Originally it was in a class in that file, but I couldn't figure out how to instantiate a class from a file, so I just put the subs in the file.

Below is a snippet of code (names changed to protect the innocent, and my job...). When it actually calls addToQueue, it gives me a Type Mismatch error that refers to the first character of the function name.

<SCRIPT language=VBScript src="pcontrol.vbs"></SCRIPT>
<SCRIPT language=vbscript event=onclick for=btnAddToQueue>
Dim myFields
Dim tmpMSG
Dim myMSG
Dim myP
Dim myR
Dim myA
Dim msgRET

Set myFields = MSODSC.CurrentSection.DataPage.Recordset.Fields

myP = myFields.Item("PN").value
myR = myFields.Item("RN").value
myA = myFields.Item("AN").value

myMSG = "PID: " & Left(myP, 4) & "  RID: " & myR & "  AID: " & myA
msgRET = MsgBox(myMSG, 65, "Adding to queue")
if msgRET = 1 Then
addToQueue Left(myP, 4), myR, myA
MsgBox "Aborted.", 48, "Add to Queue"
End If
Reply With Quote
  #2 (permalink)  
Old December 16th, 2004, 07:50 AM
Registered User
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

type mismatch means you're trying to pass a string as an int (for example) or its sending a 'nil' result that the sub can't handle .
Check the values, either when passed to the sub, or before they are passed.

Reply With Quote
  #3 (permalink)  
Old December 16th, 2004, 08:45 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

VBScript is typeless, so type mismatch is always an issue.

If you need to define the variable before you pass it, or after, then format the variable like this:

stMyVariable = "My text or number value here"
WScript.Echo CStr(stMyVariable)

CStr converts the variable contents to a string. If the value is null, however, then you will get an error. Perhaps this:

If stMyVariable <> "" Then
   WScript.Echo CStr(stMyVariable)
Else stMyVariable = "Null"
   WScript.Echo CStr(stMyVariable)
End If

Likewise CInt converts to Integer, and CDate converts a valid date/time to Date, CBool converts to Boolean, CByte converts to Byte, CCur = Currency, CDbl = Double, CLng = Long, CSng = Single, Hex returns Hex value, Oct returns Octal value, and Chr converts ANSI to a character.

So with all these available types that VBScript has to guess at, it is sometimes best to force the type yourself to make sure there are no problems with type mismatch. I use these a lot in my code.

Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling external scripts from XSLT dextermagnific XSLT 2 June 25th, 2007 03:55 AM
Calling to an external .jar file tony_s XSLT 3 December 16th, 2006 05:20 PM
calling an external application forlorn Classic ASP Professional 0 August 19th, 2005 03:26 AM
calling an external application forlorn Classic ASP Basics 0 August 19th, 2005 03:22 AM
Calling subs & Functions Zooker Beginning VB 6 4 August 20th, 2003 07:09 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.