English 中文(简体)
如何在功能要求中处理空洞参数?
原标题:how to treat empty parameters in function calls?
  • 时间:2011-09-08 21:31:26
  •  标签:
  • vbscript

当您称之为“x = 我func(a,b,d)

I m having issues with my function, say,

function myfunc(p1, p2, p3, p4)  
  if p3 <> "" then whatever  
end function

给我一个已翻新的<代码>类型不匹配

P.S. I m试图用文字功能取代一个COM物体,这些空参数的电话是用这些空洞的公用物体发出的,这些物体与这些物体有问题,但伪装与这些物体一样。 我可以改变这些呼吁,但我只需要处理空洞参数的一些功能,而只是不知道如何(导致的不是无uck的核,也无uck,而<条码>则无任何给我<条码>。

最佳回答

The data type of missed parameters is ERROR.
I wrote an example, try the following:

Function IsMissing(p)
    IsMissing = (VarType(p) = vbError)
End Function

Function Myfunc(p1, p2, p3, p4)
    If IsMissing(p1) Then Response.Write "p1 is missing "
    If IsMissing(p2) Then Response.Write "p2 is missing "
    If IsMissing(p3) Then Response.Write "p3 is missing "
    If IsMissing(p4) Then Response.Write "p4 is missing "
End Function

str = myfunc(, , , 1)
 str = myfunc(1, 2, , )  causes error

http://www.ohchr.org。 最后一个职能参数/子由于辛加税错误不能落空。

问题回答

本着教育男子养鱼的精神:

<代码>TypeName功能将向您披露其类型。

MsgBox TypeName(p3)   Returns string: "Error"

而不是if p3 <>> ,你可以测试一些诸如以下的略论:

    If TypeName(p3) = "Error" Then MsgBox "Whatever!"

或最好

    If VarType(p) = vbError Then MsgBox "Whatever!"
      vbError is a built-in constant whose value is 10.

但是,实际上,为了最佳做法,你的方案设计应避免断断断断断断断断断断断断断断断断断断断断断断断断续续的论据。 VB形形形形形形形色色,无法处理“选择”论点。

缩略语不支持任择参数。 可以通过通过阵列或无效的价值观来加以模拟,因为你不能改变呼吁,这不利于你的处境。 下一个解决办法可能是考虑改变平台(我可以建议Net)或像以下那样的“Error Next”舱。

 Assuming a String Parameter
Dim strOptionalParameter As String
strOptionalParameter = p3

 We set the value of the optional parameter to a variable
 in case it blows up and moves on to this next statement.
If strOptionalParameter <> "" Then
 Rest of Code Here
End If




相关问题
What approach should I use to test a VBScript?

I ve been asked to help out with a project which has made extensive use of VBScript to process a whole bunch of text files and generate certain outputs - sanitized files, SQL entries etc.. The script ...

Unable to call c# code from vbscript - ActiveX error

I am trying to call a method I have written in C# from VBScript. I have followed just about all of the instructions I can find on the web and am still having problems. Specifically I am getting Error:...

How to set delay in vbscript

How to set delay in vbscript? WScript.Sleep(100) does not work on Windows XP, Vista.

Using Classes in a Dictionary in Classic ASP

I usually do C# but have inherited a classic ASP project. I have defined a class: Class clsPayment Public Name End Class Set objPayment = New clsPayment objPayment.Name = "...

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

Problem casting field when querying spreadsheet

I am trying to query an .xls spreadsheet with VBScript, but I have run into an issue when trying to cast a field. I connect to the spreadsheet like this. Set objConnection = CreateObject("ADODB....

热门标签