zoukankan      html  css  js  c++  java
  • ASP中数组的使用

    1.数组的定义
    Dim intArray
    intArray= Array(1,2,3,4,5,6,7,8,9,10,11,12)
    Dim strArray
    strArray = Array("a","b","c","d","e","f","g")
    Dim arr(20)
    注意了这里的20是定义了从0到20的21格数组元素

    2.可扩展数组
    Dim MyArray()
    For i = 0 to 5
       ReDim Preserve MyArray(i)
       MyArray(i)=i
    Next

    3.将字符串分割为数组
    Dim strArray
    strArray= Split("This is Array!"," ")

    For i = LBound(strArray) to UBound(strArray) 
       Response.Write strArray(i)
    Next

    4.数组排序函数
    Function ArraySort(ary) 
            flag= TRUE 

            Do Until flag = FALSE 
                   flag = FALSE 
                   For i = 0 to UBound(ary) 
                          If i = UBound(ary) Then
                                 Exit For 

                          If ary(i) > ary(i+1) Then 
                                 Firstvalue = ary(i) 
                                 Secondvalue = ary(i+1) 
                                 ary(i) = Secondvalue 
                                 ary(i+1) = Firstvalue 
                                 flag = TRUE 
                          End If 
                   Next
            Loop 
            ArraySort = ary
    End Function

    数组排序函数应用例子
    Dim intArray
    intArray = Array(1,5,123,12,98)
    intArray = Sort(intArray )
    For i = Lbound(intArray ) to Ubound(intArray )
         Response.Write intArray (i)
    Next

    5.在Application和Session中使用数组
    Application.Lock
    ApplicationStoredArray) = MyArray
    Application.Unlock

    LocalArray = Application(StoredArray)

    覆盖Application中的数组
    Application.Lock
    Application(StoredArray) = LocalArray
    Application.Unlock

    Session使用方法与Application相同

    6.从数据库中把数据导入数组中
    Dim RsArray
    取出全部记录
    RsArray= RS.GetRows
    取出前10项记录
    RsArray= RS.GetRows(10)

    For row = 0 To UBound(RsArray, 2)
        For col = 0 To UBound(RsArray, 1)
            Response.Write RsArray(col, row) 
        Next
    Next

    7.二维数组
    Dim arr(10,10)

    arr(0,0)="frist"
  • 相关阅读:
    Get distinct count of rows in the DataSet
    单引号双引号的html转义符
    PETS Public English Test System
    Code 39 basics (39条形码原理)
    Index was outside the bounds of the array ,LocalReport.Render
    Thread was being aborted Errors
    Reportviewer Error: ASP.NET session has expired
    ReportDataSource 值不在预期的范围内
    .NET/FCL 2.0在Serialization方面的增强
    Perl像C一样强大,像awk、sed等脚本描述语言一样方便。
  • 原文地址:https://www.cnblogs.com/meil/p/671597.html
Copyright © 2011-2022 走看看