Results 1 to 6 of 6

Thread: VB Experts..need help..!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Charlotte
    Posts
    127

    Unhappy VB Experts..need help..!!!!

    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()"

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    umm..duh
    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"
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Charlotte
    Posts
    127
    Should I just remove the quotes from revlon? and that should do it?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Charlotte
    Posts
    127
    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

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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

    Code:
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width