Object-oriented ASP programming 4-some common functions

Source: Internet
Author: User


Function recordsetasarray (rsado, includeheaderrow)
// Store the data in ADO. recordset to an array.
// When includeheaderrow is true, the field title line is generated. If it is false, no field title line is generated.
{
? VaR rsarray = new array;
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? If (includeheaderrow)
?? {? // Include first row as header of Field Names
??? VaR rsrow = new array (nfields );
??? For (VAR I = 0; I ???? Rsrow [I] = rsado (I). Name;
??? Rsarray [n ++] = rsrow;
??}
??? If (! (Rsado. EOF & rsado. bof ))
????? Rsado. movefirst ()??
?? While (! Rsado. EOF)
?? {? // Add each record to array
??? Rsrow = new array (nfields );
??? For (VAR I = 0; I ???? Rsrow [I] = rsado (I). value;
??? Rsarray [n ++] = rsrow;
??? Rsado. movenext ();
??}
?}
? Return rsarray;
}

Function recordsetasdso (rsado)
// Put the data in ADO. recordset into a table and return the HTML code of the table.
{
? VaR htmldso = '';
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? Htmldso + = '/N ';???
?? While (! Rsado. EOF)
?? {? // Add each record to table
??? Htmldso + = '';???
??? For (VAR I = 0; I ??? {
???? Htmldso + = ''+ rsado (I). Value + '';
???}
??? Htmldso + = '/N ';???
??? Rsado. movenext ();
??}
?? Htmldso + = '';???
?}
? Return htmldso;
}

Function recordsetaslist (rsado, field)
// Put the data of a field in ADO. recordset into the Array
{
? VaR rsarray = new array;
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? If (! (Rsado. EOF & rsado. bof ))
????? Rsado. movefirst ()?
?? While (! Rsado. EOF)
?? {? // Add each value of field into Array
??? Rsarray [n ++] = rsado (field). value;
??? Rsado. movenext ();
??}
?}
? Return rsarray;
}

Function recordasobject (rsado, objectname)
// Return a record in ADO. recordset as an object
{
? If (typeof (objectname) = 'undefined ')
?? Objectname = 'rsobobject ';
? VaR strobject = 'function' + objectname + '(){';
? VaR nfields = rsado. Fields. count;
? If (! Rsado. EOF)
? {
?? VaR value = new string;
?? VaR propname = new string;
?? For (VAR I = 0; I ?? {
??? Propname = rsado (I). Name;
??? VaR C0 = propname. charat (0 );
??? If (propname. indexof ('') =-1) & (C0> = 'A' & C0 = 'A' & C0 ??? {? // Exclude fields that are invalid variable names
???? Value = rsado (I). value;
???? If (isnan (parsefloat (value )))
????? Strobject + = 'this. '+ propname +' = "'+ value + '";';
???? Else
????? Strobject + = 'this. '+ propname +' = '+ value + ';';
???}
??}
?}
? Strobject + = '}';
? Eval (strobject );
? Return eval ('new' + objectname );
}

Function recordsetasarray (rsado, includeheaderrow)
// Store the data in ADO. recordset to an array.
// When includeheaderrow is true, the field title line is generated. If it is false, no field title line is generated.
{
? VaR rsarray = new array;
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? If (includeheaderrow)
?? {? // Include first row as header of Field Names
??? VaR rsrow = new array (nfields );
??? For (VAR I = 0; I ???? Rsrow [I] = rsado (I). Name;
??? Rsarray [n ++] = rsrow;
??}
??? If (! (Rsado. EOF & rsado. bof ))
????? Rsado. movefirst ()??
?? While (! Rsado. EOF)
?? {? // Add each record to array
??? Rsrow = new array (nfields );
??? For (VAR I = 0; I ???? Rsrow [I] = rsado (I). value;
??? Rsarray [n ++] = rsrow;
??? Rsado. movenext ();
??}
?}
? Return rsarray;
}

Function recordsetasdso (rsado)
// Put the data in ADO. recordset into a table and return the HTML code of the table.
{
? VaR htmldso = '';
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? Htmldso + = '/N ';???
?? While (! Rsado. EOF)
?? {? // Add each record to table
??? Htmldso + = '';???
??? For (VAR I = 0; I ??? {
???? Htmldso + = ''+ rsado (I). Value + '';
???}
??? Htmldso + = '/N ';???
??? Rsado. movenext ();
??}
?? Htmldso + = '';???
?}
? Return htmldso;
}

Function recordsetaslist (rsado, field)
// Put the data of a field in ADO. recordset into the Array
{
? VaR rsarray = new array;
? VaR nfields = rsado. Fields. count;
? If (nfields)
? {
?? VaR n = 0;
?? If (! (Rsado. EOF & rsado. bof ))
????? Rsado. movefirst ()?
?? While (! Rsado. EOF)
?? {? // Add each value of field into Array
??? Rsarray [n ++] = rsado (field). value;
??? Rsado. movenext ();
??}
?}
? Return rsarray;
}

Function recordasobject (rsado, objectname)
// Return a record in ADO. recordset as an object
{
? If (typeof (objectname) = 'undefined ')
?? Objectname = 'rsobobject ';
? VaR strobject = 'function' + objectname + '(){';
? VaR nfields = rsado. Fields. count;
? If (! Rsado. EOF)
? {
?? VaR value = new string;
?? VaR propname = new string;
?? For (VAR I = 0; I ?? {
??? Propname = rsado (I). Name;
??? VaR C0 = propname. charat (0 );
??? If (propname. indexof ('') =-1) & (C0> = 'A' & C0 = 'A' & C0 ??? {? // Exclude fields that are invalid variable names
???? Value = rsado (I). value;
???? If (isnan (parsefloat (value )))
????? Strobject + = 'this. '+ propname +' = "'+ value + '";';
???? Else
????? Strobject + = 'this. '+ propname +' = '+ value + ';';
???}
??}
?}
? Strobject + = '}';
? Eval (strobject );
? Return eval ('new' + objectname );
}

?

Note: Some of these functions are derived from Microsoft scripting library in Microsoft InterDev.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.