Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dll works in vb but not in ASP

Status
Not open for further replies.

jamieslover

Programmer
Feb 4, 2002
16
US
I've created and compiled a dll that works great when I refrence it from vb but causes an error on one of it's methods when I try to use it in a ASP page.
Have any of you had a similar problem or know how to solve mine?
I am able to write and read properties in the ASP page, but something must be wrong with the Sub Routine I call because it says "Type Mismatch: 'AddSource'"
I can post code if it will help you help me.
 
All variables passed in to a component that you plan to use in a vbScript environment must have the variables typed as 'variant' in the declaration of the function.

In vbScript, all variables are just subtypes of the super-type, variant, which is what is causing your problems, and why, in vb (a typed environment), you don't have the same problem.

So, to sum it up, if you plan to pass in an integer, then even though it's a subtype of integer, it's a variant first and formost, so:

function addSource(myInteger AS variant)

Should clear it right up for you.

:)
paul ...that whenever any Form of Technology becomes destructive of these Ends, it is the right of the People to alter or to abolish it, and to institute new Technology, laying its Foundation on such Principles, and organizing its Powers in such Form, as to them shall seem most likely to effect their Efficiency of Development
 
It still didn't work- the parameters are not optional right now, must I make them optional?
 
If you aren't passing them to the function, you do, but that wouldn't cause a "type mismatch" error.

The variant problem I described above is the only thing that has ever caused this problem for me in the past.

Wish I had more to offer you. :-( ...that whenever any Form of Technology becomes destructive of these Ends, it is the right of the People to alter or to abolish it, and to institute new Technology, laying its Foundation on such Principles, and organizing its Powers in such Form, as to them shall seem most likely to effect their Efficiency of Development
 
Well, I changed them all to variants, but It didn't work so instead of calling the sub with parameters I made each of the parameters properties that I had to set before running the sub:
Instead of

MyReport.AddSource myObjRS, "Header"

I wrote it:

MyReport.ObjRS = myObjRS
myReport.Section = "Header"
MyReport.AddSource

Now it works, but I'd rather have been able to do it another way- It doesn't matter too much- atleast it works now, thanks for your help.
 
jamieslove,

Glad you have a work around. You are correct in that you should do it the other way, because you are now making 3 server calls instead of the single one.

I use functions in COM objects all the time with ASP and avoid using properties.

can you post the Function code + ASP Code so I can figure out the problem?

Codefish
 
These weren't my first problems, my first version had a class withing this class called Export. When things weren't working in ASP I got rid of it and threw all the properties into one fat ugly class. :(
Basically what this is supposed to do is take sql tables and output them to a fixed width file (much like one can do in access). At first I passed it Recordsets, but since my problem I've whittled it down to passing connection strings and SQL statements etc. The worst part is that I never saved my original version! Oh well you live you learn...
Confession: I don't code with comments :(
Here's the code to my class object, it is named FWF for fixed width file:

Option Explicit
'Declare private module-level variable to store value.
Private P_errors As Integer
Private p_OutputFilePath As String
Private p_Spacer As String
Private p_SQL As String
Private p_ArrayIndex As Single
Private p_ArrRecords() As String
Private p_Connection As String
Private p_ColumnNames As String
Private p_TableName As String
Private p_WidthAmounts As String
Private p_SpacerCharacters As String
Private p_ExportSpacer() As String
Private p_bSpacerRedimmed As Boolean
Private p_Width() As Integer
Private p_bWidthRedimmed As Boolean
Private p_FooterDateFormat As String
Private p_HeaderDateFormat As String
Private p_BodyDateFormat As String
Private p_TempSQL As String
Private p_TempConnection As String
Private p_tempSection As String
Public Property Get Errors() As String
Errors = P_errors
End Property
Public Property Let HeaderDateFormat(strHeaderDateFormat As String)
' Store value of argument in module-level variable.
p_HeaderDateFormat = strHeaderDateFormat
End Property
Public Property Get HeaderDateFormat() As String
HeaderDateFormat = p_HeaderDateFormat
End Property
Public Property Let BodyDateFormat(strBodyDateFormat As String)
' Store value of argument in module-level variable.
p_BodyDateFormat = strBodyDateFormat
End Property
Public Property Get BodyDateFormat() As String
BodyDateFormat = p_BodyDateFormat
End Property
Public Property Let FooterDateFormat(strFooterDateFormat As String)
' Store value of argument in module-level variable.
p_FooterDateFormat = strFooterDateFormat
End Property
Public Property Get FooterDateFormat() As String
FooterDateFormat = p_FooterDateFormat
End Property
Public Property Let ConnectionS(ConnectionString As String)
p_Connection = ConnectionString
End Property
Public Property Get ConnectionS() As String
ConnectionS = p_Connection
End Property
Public Property Let TableName(strTableName As String)
' Store value of argument in module-level variable.
p_TableName = strTableName
End Property
Public Property Get TableName() As String
TableName = p_TableName
End Property
Public Property Let ColumnNames(strColumnName As String)
' Store value of argument in module-level variable.
p_ColumnNames = strColumnName
End Property
Public Property Get ColumnNames() As String
ColumnNames = p_ColumnNames
End Property
Public Property Let WidthAmounts(strWidthAmounts As String)
' Store value of argument in module-level variable.
p_WidthAmounts = strWidthAmounts

End Property
Public Property Get WidthAmounts() As String
WidthAmounts = p_WidthAmounts
End Property
Public Property Let SpacerCharacters(strSpacerCharacters As String)
' Store value of argument in module-level variable.
p_SpacerCharacters = strSpacerCharacters

End Property
Public Property Get SpacerCharacters() As String
SpacerCharacters = p_SpacerCharacters
End Property
Public Property Get Spacer(Index As Integer) As String
Spacer = p_ExportSpacer(Index)

End Property
Public Property Let Spacer(Index As Integer, strSpacer As String)
If p_bSpacerRedimmed = False Then 'p_Spacer has no index
ReDim Preserve p_ExportSpacer(Index)
p_bSpacerRedimmed = True
Else 'p_Spacer can be Redimmed
If UBound(p_ExportSpacer) < Index Then
ReDim Preserve p_ExportSpacer(Index)
End If
End If

p_ExportSpacer(Index) = strSpacer

End Property
Public Property Get Width(Index As Integer) As Integer
Width = p_Width(Index)

End Property
Public Property Let Width(Index As Integer, intWidth As Integer)
If p_bWidthRedimmed = False Then 'p_Width() has no index
ReDim Preserve p_Width(Index)
p_bWidthRedimmed = True
Else 'p_Width() can be Redimmed
If UBound(p_Width) < Index Then
ReDim Preserve p_Width(Index)
End If
End If

p_Width(Index) = intWidth

End Property

Public Property Let OutputFilePath(strOutputFilePath As String)
' Store value of argument in module-level variable.
p_OutputFilePath = strOutputFilePath
End Property
Public Property Get OutputFilePath() As String
OutputFilePath = p_OutputFilePath
End Property
Public Property Let TempSQL(strSQL As String)
' Store value of argument in module-level variable.
p_TempSQL = strSQL
End Property
Public Property Get TempSQL() As String
TempSection = p_tempSection
End Property
Public Property Get TempSection() As String
TempSection = p_tempSection
End Property
Public Property Let TempSection(Section As String)
' Store value of argument in module-level variable.
p_tempSection = Section
End Property
Public Property Get TempConnection() As String
TempConnection = p_TempConnection
End Property
Public Property Let TempConnection(TempConnection As String)
' Store value of argument in module-level variable.
p_TempConnection = TempConnection
End Property


Public Sub AddSource()
On Error GoTo ErrorLabel
Dim Recordset As New ADODB.Recordset
Recordset.Open p_TempSQL, p_TempConnection, adOpenDynamic, adLockOptimistic
Dim Section As String
Section = p_tempSection

Call DiscoverWidthsAndSpacers(Recordset, Me)
p_ArrayIndex = WriteDataToArray(Recordset, Me, Section, p_ArrRecords, p_ArrayIndex)
Call ArrayToText(p_ArrRecords, p_OutputFilePath)
Recordset.Close
Set Recordset = Nothing

Exit Sub

ErrorLabel:
P_errors = P_errors + 1

End Sub
'Public Property Get ExportSpecs() As ExportSpecs
' Set ExportSpecs = p_ExportSpecs
'ExportSpecTable.DataSource = p_ExportSpecTable.DataSource
'End Property
'Public Property Let ExportSpecs(strExportSpecTable As ExportSpecs)
' Store value of argument in module-level variable.
' p_ExportSpecs.Connection = strExportSpecTable.Connection
'End Property
Public Property Get LinesWritten() As Integer
LinesWritten = UBound(p_ArrRecords())
End Property


Here is my Code Module:

Option Explicit
Public Function CompleteField(Data As String, Width As Integer, Spacer As String, DateFormat As String, Optional bLeft As Boolean) As String
Dim k As Integer
Dim intSpaces As Integer
Dim strNewString As String

If IsDate(Data) Then
Data = Format(Data, DateFormat)
If IsDate(Data) Then MsgBox Data
End If

Data = Left(Data, Width)
intSpaces = Width - Len(Data)
For k = 1 To intSpaces
strNewString = strNewString & Spacer
Next

If bLeft = True Then
CompleteField = Data & strNewString
Else
CompleteField = strNewString & Data
End If

End Function
Public Sub DiscoverWidthsAndSpacers(objRS As Recordset, ExportSpecifications As FWF)

Dim Columns As Integer
Dim k As Integer
Dim mySQL As String
Dim RSColumn As String
Dim myConnectionString As String
Dim ObjRSExport As ADODB.Recordset
Dim myConnection As New ADODB.Connection
Dim myTableName As String, myWidthColumn As String
Dim mySpacerColumn As String, myColumnNamesColumn As String

myTableName = ExportSpecifications.TableName
myWidthColumn = ExportSpecifications.WidthAmounts
mySpacerColumn = ExportSpecifications.SpacerCharacters
myColumnNamesColumn = ExportSpecifications.ColumnNames
myConnectionString = ExportSpecifications.ConnectionS
myConnection.Open myConnectionString

Columns = objRS.Fields.Count

For k = 0 To (Columns - 1)
RSColumn = objRS.Fields(k).Name

mySQL = &quot;Select &quot; & myWidthColumn & &quot;,&quot; & mySpacerColumn
mySQL = mySQL & &quot; From &quot; & myTableName
mySQL = mySQL & &quot; where &quot; & myColumnNamesColumn & &quot; = '&quot; & RSColumn & &quot;'&quot;

Set ObjRSExport = myConnection.Execute(mySQL)
ExportSpecifications.Width(k) = ObjRSExport.Fields(0)
ExportSpecifications.Spacer(k) = ObjRSExport.Fields(1)

Next


End Sub
Public Function WriteDataToArray(objRS As ADODB.Recordset, Export As FWF, ReportSection As String, arr() As String, ByVal ArrayIndex As Single) As Single
Dim strThisLine As String
Dim Handle As Integer
Dim RecordCounter As Integer
Dim k As Integer, Columns As Integer
Dim strDateFormat As String
Columns = objRS.Fields.Count
objRS.MoveFirst

Select Case ReportSection
Case &quot;Header&quot;
strDateFormat = Export.HeaderDateFormat
Case &quot;Body&quot;
strDateFormat = Export.BodyDateFormat
Case &quot;Footer&quot;
strDateFormat = Export.FooterDateFormat
End Select

Do Until objRS.EOF
strThisLine = &quot;&quot;

For k = 0 To (Columns - 1)
strThisLine = strThisLine & CompleteField(objRS.Fields(k), Export.Width(k), Export.Spacer(k), strDateFormat)

Next
ReDim Preserve arr(ArrayIndex)
arr(ArrayIndex) = strThisLine
objRS.MoveNext
ArrayIndex = ArrayIndex + 1
Loop
WriteDataToArray = ArrayIndex

End Function

Public Sub ArrayToText(arr() As String, OutputPath As String)
Dim s As String
Dim Handle As Integer, k As Integer

Handle = FreeFile
Open OutputPath For Output As #Handle

For k = LBound(arr()) To UBound(arr())
s = arr(k)
Print #Handle, s

Next

Close (Handle)
End Sub

Here is my ASP Code:
Public Function WriteText(strFilePath)
Dim MyReport, MyRecords, ConnectionString, mySQLHeader, mySQLBody
Dim mySQLFooter, ObjRSHeader, ObjRSBody, ObjRSFooter, myConnection

Set myConnection = Server.CreateObject(&quot;Adodb.Connection&quot;)

Set MyReport = Server.CreateObject(&quot;DBtoText.Fwf&quot;)

ConnectionString = &quot;Provider=SQLOLEDB; Data Source=SERVERNAME;Initial Catalog=DataBase;User ID=Uid;password=pword;&quot;
MyReport.OutputFilePath = strFilePath

myConnection.Open ConnectionString
With MyReport
.BodyDateFormat = &quot;mmddyy&quot;
.HeaderDateFormat = &quot;yyyymmdd&quot;
.ConnectionS = ConnectionString
.TableName = &quot;ColumnSpecs&quot;
.ColumnNames = &quot;ColumnName&quot;
.SpacerCharacters = &quot;Spacer&quot;
.WidthAmounts = &quot;ColumnWidth&quot;

.TempConnection = ConnectionString
.TempSection = &quot;SuperHeader&quot;
.TempSQL = &quot;Select * from view_SuperHeader&quot;
.AddSource

.TempConnection = ConnectionString
.TempSection = &quot;Header&quot;
.TempSQL = &quot;Select * from view_bofaheader&quot;
.AddSource

.TempSection = &quot;Body&quot;
.TempSQL = &quot;Select * from view_BofABody&quot;
.AddSource

.TempSection = &quot;Footer&quot;
.TempSQL = &quot;Select * from view_bofatrailer&quot;
.AddSource
End With

If MyReport.Errors >0 then
Response.Write &quot;<font color=red>There were &quot; & MyReport.Errors & &quot; errors during process.</font>&quot;
End if

myConnection.Execute(&quot;delete from importboachecks&quot;)
WriteText = MyReport.LinesWritten -2 'to discount the headers
Set MyReport = Nothing
'Response.Write &quot;<br>Lines Written to file: &quot; & MyRecords
'Response.Write &quot;<br>Output:&quot; & strFilePath

End Function
 
just for the record- i did not mean for that laugh out loud face to be there it's just part of SQL OLE DB...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top