訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容
function button_click() Dim Input as Integer Dim Total(100) as Integer, nCounter as Integer Input = 輸入的文字轉成數值 nCounter = 1 select case Input case -1 '找出Total陣列內最大與最小的值,並顯示之 case Else Total(nCounter) = Input nCounter = nCounter +1 end select end function
Dim Input As Integer '輸入值 Dim nCounter As Integer = 0 '計算輸入次數用來增加暫存陣列大小 Dim Total(nCounter) As Integer '輸入暫存陣列 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If IsNumeric(TextBox1.Text) Then '判斷輸入值是否為數字 Input = Int(TextBox1.Text) '輸入值轉成數值 TextBox1.Text = "" : TextBox3.Text = "" '清空tetbox1.tetbox3 If Input = -1 Then '輸入值為-1就結束 Button1.Enabled = False '關閉輸入按鍵 Label3.Text = "最大值:" & Total(UBound(Total)) Label4.Text = "最小值:" & Total(0) Else TextBox2.Text &= Input & vbNewLine ReDim Preserve Total(nCounter) '增加輸入暫存陣列 Total(nCounter) = Input '輸入值新增至輸入暫存陣列中 nCounter = nCounter + 1 '增加陣列 End If Array.Sort(Total) For i As Integer = 0 To UBound(Total) TextBox3.Text &= Total(i) & vbNewLine 'textbox3顯示排序後之數值 Next Else MsgBox("請輸入數字") '輸入值不為數字警告視窗 TextBox1.Text = "" '清空tetbox1 End If End Sub