Solved

StringBuilder in ASP.net vs Classic ASP

Posted on 2015-02-05
5
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

717 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