PDA

Click to See Complete Forum and Search --> : VB Experts..need help..!!!!


pcabrol
May 7th, 2001, 02:14 PM
I'm compiling this code as a dll to run in MTS..I've created a simple ASP page to run a simple update or save method..not sure if my code is correct but I receive a type mistmatch error.

here's how it looks in ASP

<%@ Language=VBScript %>

<%
Set obj=Server.CreateObject("CorpHighYield.company")
obj.UpdateCompany "Revlon", "REVLN", "11"
%>


Error message I receive:





Public Function UpdateCompany(CompanyName As Long, BondTicker As Long, IndustryID As Integer, Optional CompanyID As Integer)
Dim rsCompany As ADODB.Connection, sSQL As String, objDB As Object, stat As Long

On Error GoTo ErrorHandler

'** Create instance of the database engine object
Set objDB = GetObjectContext.CreateInstance("MTSBaDbEngine.Engine")

If Not IsMissing(CompanyID) Then
'** Build query to update Company Name
sSQL = "update HighYieldCompany set CompanyName= " & CompanyName
sSQL = sSQL & "where companyID=" & CompanyID

ElseIf Not IsMissing(CompanyID) Then
'** Build query to update BondTicker
sSQL = "update HighYieldCompany set BondTicker= " & BondTicker
sSQL = sSQL & "where companyID=" & CompanyID

Else
If Not IsMissing(CompanyID) Then
sSQL = "insert into HighYieldCompany(CompanyName, BondTicker, FK_IndustryID) values(" & _
CompanyName & ", '" & BondTicker & "','" & IndustryID & "')"

If Not stat = 0 Then
'** Build query to insert new record
sSQL = "insert into HighYieldCompany(CompanyName, BondTicker, FK_IndustryID) values(" & _
CompanyName & ", '" & BondTicker & "','" & IndustryID & "')"
End If
stat = objDB.Execquery(sSQL)
End If

End If

'** Execute query
Call objDB.Execquery(sSQL)

'** Create recordset and pass back to client
Set UpdateCompany = rsCompany
Set objDB = Nothing
GetObjectContext.SetComplete

Exit Function
ErrorHandler:

GetObjectContext.SetAbort
Err.Raise Number:=Err.Number, Description:=Err.Description, _
Source:=LIBRARY_NAME & "::" & CLASS_NAME & ".UpdateCompany()"

Cander
May 7th, 2001, 02:19 PM
umm..duh :p
Just kidding, you may have overlooked it. Happens to me alot

but you are passing strings into Long's

Look at your function declaration and how you are calling it

CompanyName As Long but you used that parameter as a string "Revelon"

pcabrol
May 7th, 2001, 02:24 PM
Should I just remove the quotes from revlon? and that should do it?

Cander
May 7th, 2001, 02:28 PM
change the DEclaration in the function to Strings instead. And remove the qoutes around the 11.

Public Function UpdateCompany(CompanyName As String, BondTicker As String, IndustryID As Integer, Optional CompanyID As Integer)


Set obj=Server.CreateObject("CorpHighYield.company")
obj.UpdateCompany "Revlon", "REVLN", 11

That should do it for ya.

pcabrol
May 7th, 2001, 02:38 PM
Almost there ;) ..got a little further than before...got an
error..but a different one..How is does my if ..then else statement looks?

error '8004e002'
/test/hy.asp, line 5

Cander
May 7th, 2001, 02:46 PM
problem is, that error could be anywhere in that function. Do this , declare a public variable called mstrErrMsg and on called mstrErrLabel.

Now in your function every couple of lines do this

mstrErrLabel = "section 1"

just change the number

then use the follwoing error hander



ErrHandler:
mstrErrMsg = mstrErrLabel & "ErrNo: " & str(Err.Number) & "Source: " & Err.Source _
& " Description: " & Err.Description

Err.Raise vbObjectError + 9, , mstrErrMsg


now when it errors , you will see the error message and the string saying section 1 or whatever number you used. Now you can find out more easily which line the problem is on. Try that out. Oh and dont forget to put your on error at the beggining of the function

On Error Goto ErrHandler