1 / 20

第4章 VB.NET 程式與 網頁製作的應用

第4章 VB.NET 程式與 網頁製作的應用. 主講人: 姚奉緒 M9153304. 本章重點. 陣列的宣告與使用 副程式與函數 VB 內建函數. 陣列的宣告. Dim 陣列名稱( N) As 資料型別 例 Dim Y(10) As Integer 宣告1個含有11個整數元素的陣列 Y(0),Y(1),Y(2), … .., Y(10). 設定陣列初值. Dim X()= { “ Word ” , ” Excel ” , ” Access ” } 設定 X(0)= “ Word ” X(1)= ” Excel ”

Download Presentation

第4章 VB.NET 程式與 網頁製作的應用

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第4章 VB.NET程式與網頁製作的應用 主講人: 姚奉緒 M9153304

  2. 本章重點 • 陣列的宣告與使用 • 副程式與函數 • VB內建函數

  3. 陣列的宣告 • Dim陣列名稱(N) As資料型別 例 Dim Y(10) As Integer 宣告1個含有11個整數元素的陣列 Y(0),Y(1),Y(2),….., Y(10)

  4. 設定陣列初值 • Dim X()= {“Word”,”Excel”,”Access”} 設定 X(0)= “Word” X(1)= ”Excel” X(2)= ”Access” 注意: 括弧中不可輸入數字

  5. 陣列的使用 Dim I Dim X()={“Word”,”Excel”,”Access”,”Outlook”} For I=0 to 3 Response.Write( X(I) & “<P>”) Next I • UBound()—找出陣列的最大註標 • For I=0 to 3 可改為 For I=0 to Ubound(X)

  6. 排序與搜尋 • Array.Sort() Dim X()={3,9,15,8,4} Array.Sort(X) 執行後, X()={3,4,8,9,15} • Array.IndexOf(陣列名稱,資料,開始位置) 若資料存在則傳回位值, 否則傳回負傳 Dim 姓名()={“Adam”,”Alan”,”Peter”,”Tom”} I=Array.IndexOf(姓名, ”Peter”) 傳回I值為2

  7. 多維陣列 • Dim 陣列名稱(M,N,L,…..) Dim X(4,3) 宣告一個5列(0~4) x 4行(0~3)之二維陣列 Dim X(3,4,5,6) 宣告一個4x5x6x7之四維陣列

  8. 副程式(Subroutine) • ASP.NET規定副程式與函數必須放在<script>與</script>標示之間 <script Language=“VB” runat=“server”> Sub 副程式名稱(參數) . . End Sub </script>

  9. <% ‘例1 無參數的副程式 Name = “張無忌”score = 51Call IsScorePassed‘Call可省略Response.Write( “<HR>” ) %> <script Language=“VB” runat=“server”> Dim Name As String Dim score As IntegerSub IsScorePassedResponse.Write( Name & “, ” ) If score >= 60 Then Response.Write( “你及格了!” )Else Response.Write( "你被當掉了!" )End If End Sub </script>

  10. <% ‘例2 有參數的副程式 IsScorePassed(“張無忌”, 51)IsScorePassed(“王國榮”, 80) Response.Write( “<HR>” ) %> <script Language=“VB” runat=“server”> Dim Name As String Dim score As IntegerSub IsScorePassed( Name, Score)Response.Write( Name & “, ” ) If score >= 60 Then Response.Write( “你及格了!” )Else Response.Write( "你被當掉了!" )End If End Sub </script>

  11. 函數(Function) • 函數是一種特殊形式的副程式, 它包含了副程式所有的功能, 而且增加了回傳值的功能 • 可分為使用者自行定義的自定函數及VB系統的內建函數

  12. <%Dim A = f(3) Response.Write( “A = ” & A & “<P>” ) ’輸出結果: 16 %> <script Language="VB" runat="server"> Function f(X) Return X^2 + 2*X + 1 End Function </script>

  13. 內建函數—字串類(1) • UCase/LCase—字串轉成大寫/小寫字元 X=“AbCdE” UCase(X)  “ABCDE” LCase(X)  “abcde” • Trim—除去不必要的空白字元 X=“ ASP” “ASP”

  14. 內建函數—字串類(2) • Join—合併陣列中資料 Dim A()={“F11”,”F18”,”F23”,”F56”} Dim X=Join(A,”<p>”)  X=“F11<p>F18<p>F23<p>F56” • Split—將字串拆成陣列 Dim B=“John,Ken,Leo” Dim List=Split(B,”,”)  List(0)=“John”, List(1)=“Ken”,List(2)=“Leo”

  15. 內建函數—字串類(3) • Replace—字串取代 X=“ABCBE” Replace(X,”B”,”G”)  X=“AGCGE”

  16. 內建函數—數值類(1) • FormatNumber—格式化數值資料 Dim X=FormatNumber(60.666667,2) • X=60.67 • Value—轉換為數值資料 Dim X=Value(“56.78”) • X=56.78

  17. 內建函數—數值類(2) • Rnd—亂數 0<Rnd<1 X=1+FIX(Rnd*42)  產生介於1~42間之樂透數字

  18. 內建函數—日期時間類(1) • Year/Month/Day–讀取日期資料年/月/天數 Dim D=Now() Y=Year(D)  Y=2004 Z=Month(D)  Z=7 • Hour/Minute/Second–讀取時間資料時/分/秒數 Dim D=Now() H=Hour(D)  H=20 M=Minute(D)  M=30

  19. 內建函數—日期時間類(2) • DateAdd –將日期加上天數 Dim D=(“d”, +60, Now) 現在起60天 Dim D=(“m”, +3, Now) 現在起3個月 • DateDiff –計算時間差 S=DateDiff(“s”,Now,#01/01/2010 00:00:00#)  計算現在時間與2010年1月1日間之秒差 S=DateDiff(“d”,Now,#01/01/2010 00:00:00#)  計算現在時間與2010年1月1日間之日差

  20. 謝謝收看

More Related