Solved

StringBuilder in ASP.net vs Classic ASP

Posted on 2015-02-05
5
230 Views
Last Modified: 2015-02-17
Hello

I'm attempting to write a routine that loops trough all the fields from one column of a database and write out a XML
I got a friend who helped me write some pseudo-code in asp.net, but I can't find how to run this in classic asp.

Any help/suggestions? here is the code:
 
Sub PrepareDataForQFE()
Dim strXML as StringBuilder
{You can set up the XML as a string builder that you manually create or as an XML document – your choice, but for this example, a simple string builder can work}
 
Dim dtTable as DataTable
dtTable = {your query results – obviously you have to run your query}
 
Dim drRow as DataRow
 
For Each drRow in dtTable
     Dim dcCol as DataColumn
 
     For Each dcCol in drRow
           strXML.Add(WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes}))
     Next
Next
 
Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
 
End Sub
 
Function WriteXML(strColumnName, strValue, blnReadOnly, strFormat, etc.)
     {This function would write out the field part of the XML}
End Function
0
Comment
Question by:amucinobluedot
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 334 total points
ID: 40592321
As there is no stringbuilder in classic asp you need to use a string

Replace these lines

dim strxml as stringbuilder
with
Dim xmlstr as string

and

 strXML.Add(WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes}))
with
 strxml = strxml & WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes})

finally

Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
with
Result = QFEBridge.CallQuik(FormIDList, strXML, etc.)
0
 

Author Comment

by:amucinobluedot
ID: 40592549
Thank you, This would work for all the values? I have 200 fields on the database and some are extensive (for example, addresses).

Would this hold?
0
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 334 total points
ID: 40592648
As long as the rest of the code supplied is correct, all I have done is replace the stringbuilder in your supplied code with the correct string variable commands, i.e using & to append strings as opposed to the stringbuilder.add method.
0
 

Author Comment

by:amucinobluedot
ID: 40592756
I found some weird mistakes... looks like classic ASP does not accept the "as string"

Microsoft VBScript compilation error '800a0401'
Expected end of statement
/......../page.asp, line 297
Dim strXML As String
-----------------^


Fixed it by removing all the "as", the code ended as follows:

Sub PrepareDataForQFE()
Dim strXML

Dim dtTable
dtTable = rs_usermap

Dim drRow

For Each drRow in dtTable
     Dim dcCol

     For Each dcCol in drRow
           strxml = strxml & WriteXML(drCol.ColumnName, drCol.Fields.Item("QFField"), "&")
     Next
Next
Result = QFEBridge.CallQuik(FormIDList, strXML)
End Sub


Function WriteXML(strColumnName, strValue, blnReadOnly, strFormat)
End Function
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 166 total points
ID: 40593962
as you discovered, there are no data types in classic asp, that's why the statement

dim strXML as string

failed. all variables declared in classic asp are variants, meaning they can be whatever data type you want. you'll also find there are no DataTables in classic asp, instead you'll use a recordset, since you're getting data from a database. so, assuming your recordset has data in it, your code would look like:

Sub PrepareDataForQFE()
Dim strXML, rsData
 
set rs.Execute( "select data from table where conditions = true" )
 
if not rs.BOF and not rs.EOF then    '-- data has been returned 
     for each row in rsData
         for each col in row.Fields
             strXML = strXML & WriteXML( col.Value )
          next
    next
end if 

Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
 
End Sub

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

726 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