<ADODB_Recordset>.Expand

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > ADODB > ADODB Module Classes > ADODB_Recordset > ADODB_Recordset Methods >

<ADODB_Recordset>.Expand

 

Description

 
Create a string buffer using field names and format from current recordset

 

Syntax

 

<ADODB_Recordset>.Expand (sDataFormat)

 

Returns

 

None.

 

Parameters

 

Name

Type

Optional

Meaning

sDataFormat

String

No

A mix of fixed text, field names, field format placeholders to be replaced from current recordset data.

 

Some special sequence are interpreted:

\n means $CRLF

\t means $TAB

 

 

Remarks

 

Field names must be inside a {} pair. Field format can be placed after field name separated by :

{Author:\      \}

means: print Author field only first 8 chars.

 

Examples:

 

"<author>{Author:\      \}</author>"

means to substitute all text from { to } using content of field "Author" formatting data using \      \ placeholder (8 chars).

 

"<id>{Au_ID:00000}</id>"

means to substitute all text from { to } using content of field "Au_ID" formatting data using 00000 placeholder.

 

he following format codes apply:

Char

Meaning

!

The first character of the string is returned

&

The entire string is returned.

\\

The first two characters are returned.

\ \

If backslashes enclose n spaces, n + 2 characters of the string expression are returned.

_

Escape (underscore) character.  The following character is interpreted as a literal character instead of a mask format character.

 

When Expression is a numeric expression, the following format codes apply within StringFormat:

Char

Meaning

#

A numeric digit position, which is space-filled to the left, and zero-filled to the right of the decimal point.  If the number is negative, a minus sign occupies a digit position.

.

The decimal point is placed at this position.

,

A numeric digit position, which signifies that whole number digits should be displayed with a comma each three digits.

$$

Two numeric digit positions which cause a dollar sign to be inserted immediately before the number.

*x

Two numeric digit positions which cause leading blank spaces in the field to be replaced with the character in the second position of the pair "x" (where "x" represents your own choice of character).  For example, two asterisks "**" will convert leading spaces to asterisks, and "*=" converts leading spaces to equals characters, etc.  The *x mask characters also act as two digit (#) placeholders.  Your mask must contain at least three characters to use this.

+

A plus at the start of the field causes the sign of the value (+ -) to be inserted before the number.  A plus at the end of the field causes the sign of the value (+ -) to be added after the number.

-

A minus at the end of the field causes a minus signed to be added after a negative number, or a space to be added after a positive number.  A minus at the start of the field is treated as a literal character, which is always inserted.

^

Numbers can be formatted in scientific notation by including three to six carets (^) in the format string.  Each caret corresponds to a numeric digit position in the exponent, one for E, one for the exponent sign, and one to four for the actual digits of the exponent value.

_

Escape (underscore) character.  The following character is interpreted as a literal character instead of a mask format character.  Therefore, to include a literal underscore character in the format mask, use two underscore characters.

 

 

Restrictions

 

See also

 

Examples

 

#MinVersion 1.10

 

Uses "Console"

Uses "ADODB"

 

'---Declare a new pConnection variable and instantiate it in one line

Dim pConn As New ADODB_CONNECTION

 

printl "-----------------------------------------"

printl " Connection info"

printl "-----------------------------------------"

'---Set the provider and open a DB

pConn.Provider = "Microsoft.Jet.OLEDB.4.0"

pConn.Open(APP_SourcePath & "Biblio.mdb")

 

'---Print some info

PrintL pConn.Provider

Printl pConn.ConnectionString

 

'---If connection is open then Executes a command and print some data

If pConn.State = %ADSTATEOPEN Then

 

  Dim pRS     As New ADODB_RECORDSET

  Dim sSql    As String

  dim nRec    as Long

  dim nField  as Long

 

  PrintL

  printl "-----------------------------------------"

  printl " SQL Query info"

  printl "-----------------------------------------"

  sSql = "Select * from Authors order by Au_ID"' Where Au_ID = 1"

  PrintL "Query is:", sSql

 

  '---Connection Execute in this case returns a recordset

  pRS = pConn.Execute(sSql)

 

  printl

  printl "-----------------------------------------"

  printl " Recordset state:", pRS.State

  printl "-----------------------------------------"  

 

  if pRS.State = %adStateOpen Then

    printl

    printl "-----------------------------------------"

    printl " List some data"

    printl "-----------------------------------------"

    

    nRec = 0

    While not pRS.EOF and nRec <= 10 '---Limit to 10 record

 

      printl  pRS.Expand("<node>\n\t<id>{Au_ID:00000}</id>\n\t<author>{Author:\      \}</author>\n</node>")     , "" in %CColor_fLightRed

 

      incr nRec

      pRS.MoveNext

 

    Wend

 

    pRS.Close

  end If

  

  pConn.Close

 

end If

 

WaitKey