• 2009-10-09

    vb.net - [VB]

    <%@ Page language="VB" %>

    <script runat="server">

    dim arrColors(5) as String
    sub Page_Load(obj as object, e as eventargs)
     arrColor(0) = "green"
     arrColor(1) = "red"
     arrColor(2) = "yellow"
     arrColor(3) = "blue"
     arrColor(4) = "violet"
     
     Response.Write("The first element is: ")
     Response.Write(arrColor(0)&"<p>")

     Response.Write("The third element is: ")
     Response.Write(arrColor(2) & "<p>")

    end sub
    </script>
    <html>
    <body>
    </body>
    </html>

    ReDim Preserver arrColor(12) 增加长度
    Erase arrColor 清空数组

    if (condition ) then
     some code
    end if

    Select Case variable
     Case option1
     code
     Case Else
      code
    End

    Select Case FirstName
     Case "sun"
     Response.Write("")
     Case "Paul"
     Response.Write("ds")
    End Select


    while condition
     code
    End While

    dim intCount as Integer = 1
    while intCount < 10 
      Response.Write(intCount & "<pr>")
     intCount = intCount -1;
    End While

    For intCount = 1 to 12
     Response.Write(intCount)
    Next

    在VB.NET中有两种分支逻辑:函数和子程序,去区别在于函数能返回信息,而子程序不能。

    Sub name(parameters)
     code
    End Sub

    function name(parameters) as type
     code
     Return value
    end function

    sub Page_Load(obj as object, e as eventargs)
     code
    end sub


    <script runat="server">
      sub Page_Load(obj as object, e as eventargs)
     MultiplyNumbers(3,4)
     MultiplyNumbers(3,6)
      end sub


      sub MultiplyNumbers(intA as integer, intB as integer)
     Response.Wirte(intA*intB &<br>)
      end sub
    </script>


    可选参数 function MutliplyNumbers(intA as integer, optional intB as integer) as Integer
    <script runat="server">
      Class Clock
     public second as integer
     public minute as integer
     public hour as integer
     
     sub SetTime(intSec as integer, intMin as integer,intHour as as integer)
      Second = integer
      Minute = intMin
      hour = intHour
     end sub
      End Class

    </script>