Chapter 3 Visual Basic.Net Visual Basic, like most programming languages, uses variables for storing values. Variables have a name (the word you use to.

Slides:



Advertisements
Similar presentations
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Advertisements

6-1 指標簡介 6-2 指標與陣列 6-3 動態配置記憶體 6-4 本章綜合練習
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
Introduction to Java Programming Lecture 13 Classes I OO Programming.
學習C++的基本語法 認識關鍵字與識別字的不同 學習程式碼偵錯的流程 學習如何提高程式的可讀性
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
T-SQL 運算子介紹 11/29. 運算子的總類 指定運算子 算術運算子 比較運算子 邏輯運算子 位元運算子 字串連結運算子 單一運算元運算子.
如何將數字變成可用之資訊 現代化資料處理與應用概念. 如何將數字變成可用之資訊 人最容易接受的訊息是圖像化資訊。 在一堆數字中,要進行比較分析,一般會使用表格形 式計算與分析。 所以一般我們會將數字依關聯性, 轉換成表格計算與分析。 此表格一般稱試算表或稱表格。 再將結果轉換為圖表,進行比較與分析。
1 Web of Science 利用指引 單元二 瀏覽與處理查詢結果. 2 瀏覽檢索結果 查出的結果,預設以時間排列, 使用者可改變結果的排列方式: 還可以依被引用次數、相關度、 第一作者、刊名、出版年等排序 回到前先查的結果畫面 點選想看資料的完整書目 本館訂購範圍的期刊 全文,便可直接連結.
:New Land ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11871: New Land 解題者:施博修 解題日期: 2011 年 6 月 8 日 題意:國王有一個懶兒子,為了勞動兒子,他想了一個 辦法,令他在某天早上開始走路,直到太陽下山前,靠.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
第一章 變數、常數及資料型態. 變數 C 程式語言的變數名稱 第一個字必須是英文字母或底線 (_) 之後可以是數字, 英文字母或底線 (_) 不可以是保留字 例: Num (Ο) _score (Ο) C&C (X) 8num (X)
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
JAVA 程式設計與資料結構 第二章 JAVA 程式基本概念及操作. 第一個程式 /* * 這是第一個程式 (FirstP.java) */ class FirstP{ public static void main(String args[]){ System.out.println("Whatever.
1.1 電腦的特性 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。
: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
MATLAB 程式設計 第 11 章 多維陣列 多維陣列的定義 在 MATLAB 的資料型態中,向量可視為 一維陣列,矩陣可視二維陣列,對於維 度 (Dimensions) 超過 1 的陣列則均可視 為「多維陣列」 (Multidimesional Arrays , 簡稱 N-D Arrays)
第 18 章 名稱空間與例外處理 18-1 名稱空間 18-1 名稱空間 18-2 例外處理 18-2 例外處理.
第三章 變數與繫結 陳維魁 博士 儒林圖書公司. 2 大綱  變數的定義  變數元件  儲存區配置問題  參考的透明性  完全計算  捷徑計算  繫結 (binding)  繫結時間  精選習題.
程式註解說明. 2 程式註解格式 塊狀註解 對檔案、 class 、 method 、資料結構、一段程式 …. 等程式區塊 做說明。 第一行的開頭必需為 “/*” 且沒有其他文字,最後一行的開頭 必需以 “*/” 做為結束,在中間每一行的開頭都必需是一個 “*” 。 單行註解 佔據一整行的說明。 以.
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
: The Playboy Chimp ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10611: The Playboy Chimp 解題者:蔡昇宇 解題日期: 2010 年 2 月 28 日 題意:給一已排序的數列 S( 升冪.
Introduction to Java Programming Lecture 5: Using Java Classes : String & Math Spring 2009.
Introduction to pointers in C/C++. Pointers 特殊變數 存放變數在記憶體中的位址 MinGW C++ 中佔用 4 bytes 間接定址取執法 位址 指標變數 變數內容 變數.
Introduction to Java Programming Lecture 15 Objects and Classes.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
7 陣列與搜尋 7.1 陣列 一般資料變數 宣告一維陣列 起始一維陣列 7-4
: Tight words ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: : Tight Words 解題者:鐘緯駿、林一帆 解題日期: 2006 年 03 月 14 日 題意: 給定數字 k 與 n (0 ≦ k.
Hung-Hsiang WuWindows Processing Design1 Chapter 3 基本觀念 變數宣告與型態 特殊運算子符號 字串與數值的轉換 類別與物件的觀念 建立新的專案 WinMain 程式進入點 Include Header File.
第五章 資料庫暨資料表設計與建立.
Fourier Series. Jean Baptiste Joseph Fourier (French)(1763~1830)
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
參考書籍:古頤榛, Visual C++ 6教學範本 , 碁峰資訊股份有限公司。
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
4 堆疊與佇列 4.1 前言 四種基本的資料結構 (可儲存資料的容器) 陣列 (Array)、串列(List): 最基本
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
資料結構實習-二.
Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式.
Visual Basic 簡介 Visual Basic 基礎語法 東海大學物理系‧施奇廷 《程式設計》
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Visual Basic 簡介 Visual Basic 基礎語法 東海大學物理系‧施奇廷 《程式設計》
第 17 章 樣板 17-1 樣板的基礎 17-1 樣板的基礎 17-2 樣板函數 17-2 樣板函數 17-3 樣板類別 17-3 樣板類別 17-4 非型態參數的樣板類別 17-4 非型態參數的樣板類別 17-5 樣板類別的繼承 17-5 樣板類別的繼承 17-6 特化樣板與靜態成員 17-6 特化樣板與靜態成員.
資料型態名稱用途儲存空間儲存值範圍 short 短整數儲存較小的 整數 2 bytes-32,768~32,767 Int 整數儲存整數 16 位元 : 2 bytes 32 位元 : 4 bytes 16 位元 : 32,768~32, 位元 : -2,147,483,648 ~ 2,147,483,647.
Chapter 10 m-way 搜尋樹與B-Tree
本章重點 2-1 有序串列(Ordered List) 2-2 介紹陣列(array) 2-3 矩陣(matrix)的應用
第 17 章 泛型類別與.NET Framework 17-1.NET Framework 類別函式庫 17-1.NET Framework 類別函式庫 17-2 使用.NET FCL 的類別 17-2 使用.NET FCL 的類別 17-3 My 名稱空間的類別 17-3 My 名稱空間的類別 17-4.
: Help My Brother ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11033: Help My Brother 解題者: 呂明璁 解題日期: 2007 年 5 月 14 日.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
2 C++ 程式概論 2.1 C++ 程式結構 程式註解 // 插入標題檔 #include 2-3
INTRODUCTION TO MATLAB SHAWNNTOU. What Is MATLAB? MATLAB® is a high-performance language for technical computing. MATLAB® is a high-performance language.
連續隨機變數 連續變數:時間、分數、重量、……
Miscellanea Switch Bitwise operations ?,. break; continue; (example) (example) do { a = getc(stdin); if (a=='q') break; else if (a=='c') continue; n++;
Visual C++重點複習.
資料結構實習-六.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
數字系統與資料表示法 教師: 陳炯勳 數系轉換 r進制數字 稱為 base r或 radix r 有r個計數符號,計數順序逢r歸零(進位) A n A n - 1 ‥‥A 2 A 1 A 0 ﹒A -1 A -2 ‥‥A -m 其中A n 及A.
第8章 字串與陣列 8-1一維陣列的處理 8-2 字串處理 8-3 多維陣列的處理 8-4 動態陣列與參數傳遞 8-5 陣列排序與搜尋.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
VHDL語法(3).
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
第 8 章 記憶體指標. 8.0 變數、數值、位址 8.1 指標與變數 對 C++ 語言而言,指標( pointers )是存放 變數或陣列的位址,因此也可以藉由指標 間接取得變數或陣列中的值。 對 C++ 語言而言,指標( pointers )是存放 變數或陣列的位址,因此也可以藉由指標 間接取得變數或陣列中的值。
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
Presentation transcript:

Chapter 3 Visual Basic.Net Visual Basic, like most programming languages, uses variables for storing values. Variables have a name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store). Arrays can be used to store indexed collections of related variables. Introduction to Variables, Constants and Data Types

Chapter 3 Visual Basic.Net Constants also store values, but as the name implies, those values remain constant throughout the execution of an application. Data types control the internal storage of data in Visual Basic. Introduction to Variables, Constants and Data Types

Chapter 3 Visual Basic.Net Variables ( 變數 ) To declare a variable is to tell the program about it in advance. You declare a variable with the Dim statement, supplying a name for the variable: 宣告變數 Dim variablename [As type] Dim shtAge As Short Dim shtAge, shtHeight, shtWeight As Short Dim shtAge As Short, strAddress As String 省略則為 Object 型態

Chapter 3 Visual Basic.Net 一個變數名稱不能超過 255 個字元 第一個字元必須是字母 (A-Z) ,大小寫均可或中文名稱 ,除第一個字元外,其它字元可以為 A-Z, a-z, 0-9, 或 _ 等。 Variable Name 不可以是 VB.Net 的保留字 變數名稱最後一個字元可用型態宣告字元,如 %, $, &,!,# Variable Name

Chapter 3 Visual Basic.Net Variable Type See Page 83 資料型態儲存大小 (Byte) 說明 Char2 字元 String10+ 字串 Short2 精簡整數 Integer4 (2) 整數 Long8 (4) 長整數 Single4 單精準度浮點數 Double8 雙精準度浮點數 Boolean4 布林 Object4 物件 Decimal12 數值 Date8 日期 Byte1 位元

Chapter 3 Visual Basic.Net Variable 的初值設定 Dim strUserName As String = “Charles” Dim shtAge As Short=30 Question: Dim shtAge As Short=30, shtWeight As Short

Chapter 3 Visual Basic.Net 型態宣告字元 Dim intIncome% v.s. Dim intIncome As Integer 資料型態 態宣告字元 Single Double Integer Long String !#%&$!#%&$

Chapter 3 Visual Basic.Net 型態宣告字元 Question: Dim intIncome%, shtAge As Single Dim intIncome%, shtAge!

Chapter 3 Visual Basic.Net <% dim shtHeight as Short dim shtWeight as Short shtHeight=173 shtWeight=(shtHeight-80)*0.7 response.write(shtWeight) %>

Chapter 3 Visual Basic.Net VB 運算子 * 4 / 4 - ( 負數 ) 3 \ ( 整數除法 ) 5 Mod ( 餘數 ) 6 ^ 2 & ( 字串連接 ) 8 ( ) 1 Ex : 100^2-50*3/5+(10/2)^5\9 優先順序

Chapter 3 Visual Basic.Net VB.NET 新增運算子 += A+=1 A=A+1 -= B-=1 B=B-1 *= C*=2 C=C*2 /= D/=2 D=D/2 \= E\=3 E=E\3 ^= F^=2 F=F^2 &= G&=H G=G&H

Chapter 3 Visual Basic.Net Constant The syntax for declaring a constant is: Const constantname [ As type ] = expression Const conPi = Const conMaxPlanets As Integer = 9

Chapter 3 Visual Basic.Net <% Dim shtR As Short=10 Response.Write("Round:") Response.Write(2* *shtR) Response.Write(" Area:") Response.Write(2* *(shtR^2)) %>

Chapter 3 Visual Basic.Net <% Const cnPI= Dim shtR As Short=10 Response.Write("Round:") Response.Write(2*cnPI*shtR) Response.Write(" Area:") Response.Write(2*cnPI*(shtR^2)) %>

Chapter 3 Visual Basic.Net Arrays ( 陣列 ) Arrays allow you to refer to a series of variables by the same name and data type and to use a number (an index, 索引 ) to tell them apart. Arrays allow you to refer to a series of variables by the same name and data type and to use a number (an index, 索引 ) to tell them apart. This helps you create smaller and simpler code in many situations, because you can set up loops that deal efficiently with any number of cases by using the index number. This helps you create smaller and simpler code in many situations, because you can set up loops that deal efficiently with any number of cases by using the index number.

Chapter 3 Visual Basic.Net In Visual Basic there are two types of arrays: –a fixed-size array which always remains the same size –a dynamic array whose size can change at run-time. Arrays ( 陣列 ) Redim 指令

Chapter 3 Visual Basic.Net Arrays ( 陣列 ) When declaring an array, follow the array name by the upper bound in parentheses. The upper bound cannot exceed the range of a Long data type (2^64 - 1). Dim 陣列名稱(元素數量) [As Type] Dim 陣列名稱() [As Type] = {V1, V2, … } Ex: Dim Counters(14) As Integer ' 15 elements. Dim Sums(20) As Double ‘ 21 elements. Dim shtAge() As Short = {20,21,22,23,24}

Chapter 3 Visual Basic.Net Multidimensional Arrays ( 多維陣列 ) With Visual Basic, you can declare arrays of multiple dimensions. With Visual Basic, you can declare arrays of multiple dimensions. Example: Dim score(2, 30) As integer

Chapter 3 Visual Basic.Net 1. The ReDim statement can appear only in a procedure. Unlike the Dim and Static statements, ReDim is an executable statement 2. The ReDim statement supports the same syntax used for fixed arrays. Each ReDim can change the number of elements, as well as the lower and upper bounds, for each dimension. However, the number of dimensions in the array cannot change. Example: ReDim DynArray(12) 3. The bounds of a dynamic array can be set using variables: Example: ReDim Matrix1(X) Allocate the actual number of elements with a ReDim statement Allocate the actual number of elements with a ReDim statement

Chapter 3 Visual Basic.Net Preserving the Contents of Dynamic Arrays Preserving the Contents of Dynamic Arrays Each time you execute the ReDim statement, all the values currently stored in the array are lost. Visual Basic resets the values to the Empty value (for Variant arrays), to zero (for numeric arrays), to a zero-length string (for string arrays), or to Nothing (for arrays of objects). This is useful when you want to prepare the array for new data, or when you want to shrink the size of the array to take up minimal memory. Sometimes you may want to change the size of the array without losing the data in the array. Syntax: ReDim Preserve ArrayName(Index)

Chapter 3 Visual Basic.Net 物件型態陣列 Dim objStudent(4) As Object objStudent(0)= “Lin” objStudent(1)=“Hello” objStudent(2)=29 objStudent(3)=#10/03/1973# Example:

Chapter 3 Visual Basic.Net VB.NET (ASP.NET) 之資料輸入與輸出 網頁資料的輸出 Response.Write(“string”) 網頁資料的輸入 變數 = Request(“ 參數名稱 ”)

Chapter 3 Visual Basic.Net <% dim strName As String strNAme=request("MyNAme") response.write("Hello, ") response.write(strName) %>

Chapter 3 Visual Basic.Net 資料型別的轉換 VB.NET 強型別語言 二個不同型態資料要作處理需轉換成相同的資料型態 P.100 型別轉換函式 To 方法 P.102

Chapter 3 Visual Basic.Net 程式的續行與註解 Response.Write(CStr(sngFeet) & “ 英呎 ” & _ CStr(sngInches) & “ 英吋等於 ” & _ CStr(sngCentimeters) & “ 公分 ”) 續行符號 ‘ ( 上單引號 ) REM 註解 必需再新的一行