Passing arrays from a COM object to ASP

Results 1 to 4 of 4

Thread: Passing arrays from a COM object to ASP

  1. #1
    James Van Booven Guest

    Default Passing arrays from a COM object to ASP

    I am trying to create a COM object in Visual Basic 6 that will parse a string that contains account information about multiple accounts and return several arrays: AccountNumber(), AccountSuffix(), AccountDescription(), and AccountBalance()<BR><BR>Getting the string from another application and parsing it is not an issue. The question is once I&#039;ve got the string parsed into these four single-dimension arrays, how do I pass them back to ASP?<BR><BR>Here&#039;s the code I have right now. The RemoteHost and RemotePort are passed to the COM object, which will pull the account information string from an app running on that Host/Port. That&#039;s irrelevant to the current question, but I have left those references for completeness.<BR><BR>--- Test ASP Code ---<BR><BR> RemoteHost = ""<BR> RemotePort = "1001"<BR> Set objClass = Server.CreateObject("TestProject.AccountData")<BR> objTest = objClass.GetAccountSummary("1000000000012345", RemoteHost, RemotePort)<BR> <BR> Response.Write objClass.AccountNumber(0) &#039;This fails. How do I call the arrays?<BR><BR>--- End Test ASP Code ---<BR><BR><BR>--- Visual Basic COM object ---<BR><BR>Option Explicit<BR><BR>Private m_iRecordLen As Integer &#039;Total length of each record<BR>Private m_iNumOfRecords As Integer &#039;Total number of records<BR><BR>Private m_iAcctNumStart As Integer &#039;Account Number starting position<BR>Private m_iAcctNumLen As Integer &#039;Account Number field length<BR>Private m_iAcctSfxStart As Integer &#039;Account Suffix starting position<BR>Private m_iAcctSfxLen As Integer &#039;Account Suffix field length<BR>Private m_iAcctDescStart As Integer &#039;Account Description starting position<BR>Private m_iAcctDescLen As Integer &#039;Account Description starting position<BR>Private m_iAcctBalStart As Integer &#039;Account Balance starting position<BR>Private m_iAcctBalLen As Integer &#039;Account Balance starting position<BR>Private m_iAcctEOPFlagStart As Integer &#039;End-Of-Packet Flag starting position<BR>Private m_iAcctEOPFlagLen As Integer &#039;End-Of-Packet Flag starting position<BR><BR>Private m_sAcctNum() As String &#039;Account Number Array<BR>Private m_sAcctSfx() As String &#039;Account Suffix Array<BR>Private m_sAcctDesc() As String &#039;Account Description Array<BR>Private m_sAcctBal() As String &#039;Account Balance Array<BR>Private m_sAcctEOPFlag() As String &#039;End-Of-Packet flag Array<BR><BR>Public Property Get AccountNumber() As String()<BR> AccountNumber = m_sAcctNum<BR>End Property<BR><BR>Public Property Get AccountSuffix() As String()<BR> AccountSuffix = m_sAcctSfx<BR>End Property<BR><BR>Public Property Get AccountDescription() As String()<BR> AccountDescription = m_sAcctDesc<BR>End Property<BR><BR>Public Property Get AccountBalance() As String()<BR> AccountBalance = m_sAcctBal<BR>End Property<BR><BR>Private Sub Class_Initialize()<BR> <BR> &#039;Initialize Variables<BR> m_iRecordLen = 51<BR> m_iAcctNumStart = 1<BR> m_iAcctNumLen = 12<BR> m_iAcctSfxStart = 13<BR> m_iAcctSfxLen = 3<BR> m_iAcctDescStart = 16<BR> m_iAcctDescLen = 20<BR> m_iAcctBalStart = 36<BR> m_iAcctBalLen = 12<BR> m_iAcctEOPFlagStart = 48<BR> m_iAcctEOPFlagLen = 4<BR> <BR>End Sub<BR> <BR>Private Sub Class_Terminate()<BR> <BR> &#039;TODO: Destroy all variables<BR><BR>End Sub<BR><BR>Public Sub GetAccountSummary(ByVal sAcctNum As String, ByVal sRemoteIP As String, ByVal sRemotePort As String)<BR> <BR> &#039;I am hardcoding the value for strRecieved here, but normally it would be retrieved<BR> &#039; by connecting to an application on sRemoteIP on port sRemotePort<BR> <BR> Dim strRecieved<BR> strRecieved = "000000012345000Savings 000000180000xxxx" & _<BR> "000000012345001Loan 000000000000xxxx" & _<BR> "000000012345201Checking 000000943977xxxx"<BR><BR> ProcessResponse strRecieved<BR><BR>End Sub<BR><BR>Private Sub ProcessResponse(ByVal strResponse As String)<BR> <BR> m_iNumOfRecords = Len(strResponse) / m_iRecordLen<BR> <BR> ReDim m_sAcctNum(m_iNumOfRecords)<BR> ReDim m_sAcctSfx(m_iNumOfRecords)<BR> ReDim m_sAcctDesc(m_iNumOfRecords)<BR> ReDim m_sAcctBal(m_iNumOfRecords)<BR> ReDim m_sAcctEOPFlag(m_iNumOfRecords)<BR><BR> Dim iCount<BR> For iCount = 0 To (m_iNumOfRecords - 1)<BR> m_sAcctNum(iCount) = Mid$(strResponse, (m_iAcctNumStart + (m_iRecordLen * iCount)), m_iAcctNumLen)<BR> m_sAcctSfx(iCount) = Mid$(strResponse, (m_iAcctSfxStart + (m_iRecordLen * iCount)), m_iAcctSfxLen)<BR> m_sAcctDesc(iCount) = Mid$(strResponse, (m_iAcctDescStart + (m_iRecordLen * iCount)), m_iAcctDescLen)<BR> m_sAcctBal(iCount) = Mid$(strResponse, (m_iAcctBalStart + (m_iRecordLen * iCount)), m_iAcctBalLen)<BR> m_sAcctEOPFlag(iCount) = Mid$(strResponse, (m_iAcctEOPFlagStart + (m_iRecordLen * iCount)), m_iAcctEOPFlagLen)<BR> Next iCount<BR><BR>End Sub<BR><BR>--- End Visual Basic COM object ---<BR>

  2. #2
    IMRAN Q Guest

    Default RE: Passing arrays from a COM object to ASP

    Hi,<BR>you are Response.Writing objClass.AccountNumber(0) <BR>This method returns the value set in m_sAcctNum <BR>but i cant see where you assign an array to m_sAcctNum . You should use a private property let AccountNumber method to set any input to Accountnumber method. Also, ALWAYS return back to ASP as variant, not String !

  3. #3
    James Van Booven Guest

    Default RE: Passing arrays from a COM object to ASP

    I intend for m_sAcctNum to be an array, and for the following code to assign that to AccountNumber:<BR><BR>Public Property Get AccountNumber() As String()<BR> AccountNumber = m_sAcctNum<BR>End Property<BR><BR>Am I declaring m_sAcctNum wrong?<BR><BR>I don&#039;t want to be able to assign values to the arrays (ie AccountNumber) from ASP; they should be read-only, as the COM object gets that information from another program and does not update it.<BR><BR>Out of curiousity, why do you not want to pass back to ASP as String? Isn&#039;t Variant less efficient?

  4. #4

    Default RE: Passing arrays from a COM object to ASP

    James,<BR><BR>Public Property Get AccountNumber() As String()<BR> AccountNumber = m_sAcctNum<BR>End Property<BR><BR>Above code returns your Account number back to ASP from COM, you are returning an empty value, because you havent assigned it. <BR><BR>Assign m_sAcctNum using:<BR><BR>Let m_sAcctNum = accountNo (accountNo you retrieve from your other program)<BR><BR>Variant is less efficient in typed language environments, like VB or C++. BUT, ASP is loose types, so its expensive to explicitly convert variant data types to specific data types, hence WHY COM should return variant, not String as you are passing back to ASP, a loose data type environment<BR><BR><BR><BR>

Posting Permissions

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