|
 |
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

December 15th, 2004, 05:24 PM
|
Registered User
|
|
Join Date: Dec 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
Code:
<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
else
MsgBox "Aborted.", 48, "Add to Queue"
End If
-->
</SCRIPT>
|

December 16th, 2004, 07:50 AM
|
Registered User
|
|
Join Date: Dec 2004
Location: , , .
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.
|

December 16th, 2004, 08:45 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
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.
mmcdonal
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |