Asp+com have to pay attention to the problem _ application skills

Source: Internet
Author: User
As you all know, ASP is an untyped scripting language, and Vb,vc,delphi and other languages developed DLL components are strongly typed, so there is a problem. I still use my problems to speak, I use VB to write a class test, there is a method Funa, method Funa return value is an array, sample code:
Class Test:

Public Function Getstr ()
Getstr = Split ("A,b,c,d", ",")
End Function

ASP code:

Dim o
Set o=server.createobject ("Bqrm.test")
Dim arr
Arr=o.getstr ()
Response.Write (TypeName (arr)) ' Output string ()
Response.Write (IsArray (arr)) ' Outputs True
Response.Write (arr (0)) ' Output type mismatch, IsArray return it is an array, but you can not take it as an array to operate, depressed AH


But by changing the code of a Getstr method, it can be used, for example:
Public Function Getstr ()
Getstr = Array ("A", "B", "C", "D")
End Function
It's not going to go wrong, but sometimes you can't list all the elements, you have to write a function and convert it into an array of no type,

Function Getvbsarray (ByVal arr)
If IsArray (arr) Then
Dim arrtmp ()
ReDim arrtmp (UBound (arr))
Dim Ibound
Ibound = 0
Dim tmp
For each TMP in ARR
Arrtmp (ibound) = tmp
Ibound = Ibound + 1
Next
Getvbsarray = arrtmp
Erase arrtmp
Else
Getvbsarray = arr
End If
End Function
Put it in a module, and then switch back to the array method before returning it, such as:

Public Function Getstr ()
Getstr = Getvbsarray (Split ("A,b,c,d", ","))
End Function
In this way, there will be no problem.



BTW: This one question makes me depressed for a day and a half ah, is the second I have been working a year to meet the problem that I can not do, although the solution does not feel anything, but did not solve the past really think that this is a difficult problem, in fact, by their own ignorance blindfolded. I only have a bit of VBS, do not understand VC, DELPHI, I will not say those, save the Recruit B4 .... ^_^

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.