[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB COM in asp file

Posted on 2000-04-17
4
Medium Priority
?
201 Views
Last Modified: 2013-11-25
I created VB COM I want to use in my web based application.



the COM poject is ActiceX dll and it is called COM_ASST.
the only class in the COM is Called
C_ASST

and the class contains one function

here is my COM class definition
------------------------------------
Public Function GetNextRecordNumber(ObjCon As ADODB.Connection, companyName As String) As Long
Dim rs As Recordset
Dim cmd As Command
Dim param As Parameter
Set cmd = New Command

With cmd
.ActiveConnection = con
.CommandText = "spGetNextRecordNumber"
.CommandType = adCmdStoredProc
End With


Set param = cmd.CreateParameter("companyName", adVarChar, adParamInput, 40, companyName)
cmd.Parameters.Append param
Set rs = cmd.Execute
GetNextRecordNumber = rs!NextRecord
rs.Close
Set rs = Nothing
End Function

------------- end -------------------

I have written a small VB test program and it works fine.

When I use it in an asp file
-------------------------------------
<%@ Language=VBScript %>

<%
dim obj
  num = 0

  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open "testDB", "sa", ""
  set obj = server.CreateObject("COM_Asst.C_Asst")  
   num = obj.GetNextRecordNumber objConn, "Customers"
 
  Response.write num
%>

---------------------------------
I get the following error

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'GetNextRecordNumber'
/p.asp, line 11
0
Comment
Question by:yassin092898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
stefanx earned 400 total points
ID: 2724633
Maybe try and declare your passing parameters as variants. Or perhaps like this :

Public Function GetNextRecordNumber(ObjCon As Object, ByVal companyName As Variant) As Long

Sure, you may not get the early binding advantage on your ADO Object, but it will also allow your COM component to be insensitive to changes in the ADO version (which are released at frighteningly short intervals).

There is a slight performance penalty since late binding is always slower than early binding.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2724690
whatever you are passing to the COM you have to pass it byREF. so in your function make sure your parameters are set to be BYREF.
Public Function GetNextRecordNumber(byref ObjCon As ADODB.Connection, byRef companyName As String) As Long
0
 
LVL 8

Expert Comment

by:stefanx
ID: 2724768
Marine - that's not correct. You only need to pass things ByRef if you want to be able to read the passed values back from the COM component. This applies to simple types such as String, Integer etc. Objects are always passed ByRef because you are actually passing a pointer (if you try and compile a VB component with an Object passed ByVal, it generates an error). In VB, if you don't specify a passing type (like yasin has done), it is considered to be ByRef anyway, so changing it to ByRef will have no effect. Yasin's problem has more to do with the fact that VBScript does not support typed variables, only variants.

Incidentally, strings are also pointers so it is normally faster to pass strings ByRef than ByVal. This is however not necessarily true for COM components because cross-component marshalling typically takes longer than just a single marshalling call to make a copy of the string when the COM Component's method is called. The same applies to thread marshalling calls, so if you are writing an apartment threaded component for use within a muti-threaded Visual Basic Application and you don't need to read back strings, rather pass them ByVal - it is faster. If you do need to read the parameter back from the method, then make a copy of the string into a local variable and operate on the local variable. Before you exit the method, assign the local variable to the passed one.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2724782
Sorry , sorry i meant to say byVal.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question