<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # [X分鐘速成Y](http://learnxinyminutes.com/) ## 其中 Y=Visual Basic 源代碼下載:?[learnvisualbasic.vb-cn](http://learnxinyminutes.com/docs/files/learnvisualbasic.vb-cn) ~~~ Module Module1 Sub Main() ' 讓我們先從簡單的終端程序學起。 ' 單引號用來生成注釋(注意是半角單引號,非全角單引號’) ' 為了方便運行此示例代碼,我寫了個目錄索引。 ' 可能你還不了解以下代碼的意義,但隨著教程的深入, ' 你會漸漸理解其用法。 Console.Title = ("Learn X in Y Minutes") Console.WriteLine("NAVIGATION") ' 顯示目錄 Console.WriteLine("") Console.ForegroundColor = ConsoleColor.Green Console.WriteLine("1\. Hello World Output") ' Hello world 輸出示例 Console.WriteLine("2\. Hello World Input") ' Hello world 輸入示例 Console.WriteLine("3\. Calculating Whole Numbers") ' 求整數之和 Console.WriteLine("4\. Calculating Decimal Numbers") ' 求小數之和 Console.WriteLine("5\. Working Calculator") ' 計算器 Console.WriteLine("6\. Using Do While Loops") ' 使用 Do While 循環 Console.WriteLine("7\. Using For While Loops") ' 使用 For While 循環 Console.WriteLine("8\. Conditional Statements") ' 條件語句 Console.WriteLine("9\. Select A Drink") ' 選飲料 Console.WriteLine("50\. About") ' 關于 Console.WriteLine("Please Choose A Number From The Above List") Dim selection As String = Console.ReadLine Select Case selection Case "1" ' Hello world 輸出示例 Console.Clear() ' 清空屏幕 HelloWorldOutput() ' 調用程序塊 Case "2" ' Hello world 輸入示例 Console.Clear() HelloWorldInput() Case "3" ' 求整數之和 Console.Clear() CalculatingWholeNumbers() Case "4" ' 求小數之和 Console.Clear() CalculatingDecimalNumbers() Case "5" ' 計算器 Console.Clear() WorkingCalculator() Case "6" ' 使用 do while 循環 Console.Clear() UsingDoWhileLoops() Case "7" ' 使用 for while 循環 Console.Clear() UsingForLoops() Case "8" ' 條件語句 Console.Clear() ConditionalStatement() Case "9" ' If/Else 條件語句 Console.Clear() IfElseStatement() ' 選飲料 Case "50" ' 關于本程序和作者 Console.Clear() Console.Title = ("Learn X in Y Minutes :: About") MsgBox("This tutorial is by Brian Martin (@BrianMartinn") Console.Clear() Main() Console.ReadLine() End Select End Sub ' 一、對應程序目錄1,下同 ' 使用 private subs 聲明函數。 Private Sub HelloWorldOutput() ' 程序名 Console.Title = "Hello World Ouput | Learn X in Y Minutes" ' 使用 Console.Write("") 或者 Console.WriteLine("") 來輸出文本到屏幕上 ' 對應的 Console.Read() 或 Console.Readline() 用來讀取鍵盤輸入 Console.WriteLine("Hello World") Console.ReadLine() ' Console.WriteLine()后加Console.ReadLine()是為了防止屏幕輸出信息一閃而過 ' 類似平時常見的“單擊任意鍵繼續”的意思。 End Sub ' 二 Private Sub HelloWorldInput() Console.Title = "Hello World YourName | Learn X in Y Minutes" ' 變量 ' 用來存儲用戶輸入的數據 ' 變量聲明以 Dim 開始,結尾為 As VariableType (變量類型). ' 此教程中,我們希望知道你的姓名,并讓程序記錄并輸出。 Dim username As String ' 我們定義username使用字符串類型(String)來記錄用戶姓名。 Console.WriteLine("Hello, What is your name? ") ' 詢問用戶輸入姓名 username = Console.ReadLine() ' 存儲用戶名到變量 username Console.WriteLine("Hello " + username) ' 輸出將是 Hello + username Console.ReadLine() ' 暫停屏幕并顯示以上輸出 ' 以上程序將詢問你的姓名,并和你打招呼。 ' 其它變量如整型(Integer)我們用整型來處理整數。 End Sub ' 三 Private Sub CalculatingWholeNumbers() Console.Title = "Calculating Whole Numbers | Learn X in Y Minutes" Console.Write("First number: ") ' 輸入一個整數:1,2,50,104,等等 Dim a As Integer = Console.ReadLine() Console.Write("Second number: ") ' 輸入第二個整數 Dim b As Integer = Console.ReadLine() Dim c As Integer = a + b Console.WriteLine(c) Console.ReadLine() ' 以上程序將兩個整數相加 End Sub ' 四 Private Sub CalculatingDecimalNumbers() Console.Title = "Calculating with Double | Learn X in Y Minutes" ' 當然,我們還需要能夠處理小數。 ' 只需要要將整型(Integer)改為小數(Double)類型即可。 ' 輸入一個小數: 1.2, 2.4, 50.1, 104.9,等等 Console.Write("First number: ") Dim a As Double = Console.ReadLine Console.Write("Second number: ") ' 輸入第二個數 Dim b As Double = Console.ReadLine Dim c As Double = a + b Console.WriteLine(c) Console.ReadLine() ' 以上代碼能實現兩個小數相加 End Sub ' 五 Private Sub WorkingCalculator() Console.Title = "The Working Calculator| Learn X in Y Minutes" ' 但是如果你希望有個能夠處理加減乘除的計算器呢? ' 只需將上面代碼復制粘帖即可。 Console.Write("First number: ") ' 輸入第一個數 Dim a As Double = Console.ReadLine Console.Write("Second number: ") ' 輸入第二個數 Dim b As Integer = Console.ReadLine Dim c As Integer = a + b Dim d As Integer = a * b Dim e As Integer = a - b Dim f As Integer = a / b ' 通過以下代碼我們可以將以上所算的加減乘除結果輸出到屏幕上。 Console.Write(a.ToString() + " + " + b.ToString()) ' 我們希望答案開頭能有3個空格,可以使用String.PadLeft(3)方法。 Console.WriteLine(" = " + c.ToString.PadLeft(3)) Console.Write(a.ToString() + " * " + b.ToString()) Console.WriteLine(" = " + d.ToString.PadLeft(3)) Console.Write(a.ToString() + " - " + b.ToString()) Console.WriteLine(" = " + e.ToString.PadLeft(3)) Console.Write(a.ToString() + " / " + b.ToString()) Console.WriteLine(" = " + e.ToString.PadLeft(3)) Console.ReadLine() End Sub ' 六 Private Sub UsingDoWhileLoops() ' 如同以上的代碼一樣 ' 這次我們將詢問用戶是否繼續 (Yes or No?) ' 我們將使用Do While循環,因為我們不知到用戶是否需要使用一次以上。 Console.Title = "UsingDoWhileLoops | Learn X in Y Minutes" Dim answer As String ' 我們使用字符串變量來存儲answer(答案) Do ' 循環開始 Console.Write("First number: ") Dim a As Double = Console.ReadLine Console.Write("Second number: ") Dim b As Integer = Console.ReadLine Dim c As Integer = a + b Dim d As Integer = a * b Dim e As Integer = a - b Dim f As Integer = a / b Console.Write(a.ToString() + " + " + b.ToString()) Console.WriteLine(" = " + c.ToString.PadLeft(3)) Console.Write(a.ToString() + " * " + b.ToString()) Console.WriteLine(" = " + d.ToString.PadLeft(3)) Console.Write(a.ToString() + " - " + b.ToString()) Console.WriteLine(" = " + e.ToString.PadLeft(3)) Console.Write(a.ToString() + " / " + b.ToString()) Console.WriteLine(" = " + e.ToString.PadLeft(3)) Console.ReadLine() ' 詢問用戶是否繼續,注意大小寫。 Console.Write("Would you like to continue? (yes / no)") ' 程序讀入用戶輸入 answer = Console.ReadLine() ' added a bracket here ' 當用戶輸入"yes"時,程序將跳轉到Do,并再次執行 Loop While answer = "yes" End Sub ' 七 Private Sub UsingForLoops() ' 有一些程序只需要運行一次。 ' 這個程序我們將實現從10倒數計數. Console.Title = "Using For Loops | Learn X in Y Minutes" ' 聲明變量和Step (步長,即遞減的速度,如-1,-2,-3等)。 For i As Integer = 10 To 0 Step -1 Console.WriteLine(i.ToString) ' 將計數結果輸出的屏幕 Next i ' 計算新的i值 Console.WriteLine("Start") Console.ReadLine() End Sub ' 八 Private Sub ConditionalStatement() Console.Title = "Conditional Statements | Learn X in Y Minutes" Dim userName As String = Console.ReadLine Console.WriteLine("Hello, What is your name? ") ' 詢問用戶姓名 userName = Console.ReadLine() ' 存儲用戶姓名 If userName = "Adam" Then Console.WriteLine("Hello Adam") Console.WriteLine("Thanks for creating this useful site") Console.ReadLine() Else Console.WriteLine("Hello " + userName) Console.WriteLine("Have you checked out www.learnxinyminutes.com") Console.ReadLine() ' 程序停止,并輸出以上文本 End If End Sub ' 九 Private Sub IfElseStatement() Console.Title = "If / Else Statement | Learn X in Y Minutes" ' 有時候我們需要考慮多于兩種情況。 ' 這時我們就需要使用If/ElesIf條件語句。 ' If語句就好似個自動售貨機,當用戶輸入A1,A2,A3,等去選擇物品時, ' 所有的選擇可以合并到一個If語句中 Dim selection As String = Console.ReadLine() ' 讀入用戶選擇 Console.WriteLine("A1\. for 7Up") ' A1 七喜 Console.WriteLine("A2\. for Fanta") ' A2 芬達 Console.WriteLine("A3\. for Dr. Pepper") ' A3 胡椒醫生 Console.WriteLine("A4\. for Diet Coke") ' A4 無糖可樂 Console.ReadLine() If selection = "A1" Then Console.WriteLine("7up") Console.ReadLine() ElseIf selection = "A2" Then Console.WriteLine("fanta") Console.ReadLine() ElseIf selection = "A3" Then Console.WriteLine("dr. pepper") Console.ReadLine() ElseIf selection = "A4" Then Console.WriteLine("diet coke") Console.ReadLine() Else Console.WriteLine("Please select a product") ' 請選擇你需要的產品 Console.ReadLine() End If End Sub End Module ~~~ ## 參考 我(譯注:原作者)在命令行下學習的VB。命令行編程使我能夠更好的了解程序編譯運行機制,并使學習其它語言變得容易。 如果希望進一步學習VB,這里還有更深層次的?[VB教學(英文)](http://www.vbbootcamp.co.uk/ "VB教學")。 所有代碼均通過測試。只需復制粘帖到Visual Basic中,并按F5運行即可。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看