導航:首頁 > 編程語言 > vb編程必背50個程序

vb編程必背50個程序

發布時間:2022-12-27 07:58:54

⑴ VB編程:編寫程序,產生50個互不相同的10~99的隨機整數,統計各數值段有多少個數

Dim a(1 To 50) As Integer, b(1 To 9) As Integer
Dim i As Integer, j As Integer
Randomize
For i = 1 To 9
b(i) = 0 '初始化數組
Next
For i = 1 To 50
a(i) = Int(90 * Rnd + 10) '產生隨機數
For j = 1 To 9 '判定范圍存入數組
If a(i) > j * 10 - 1 And a(i) < j * 10 + 10 _
Then b(j) = b(j) + 1
Next
Next
'輸出
For i = 1 To 50
Debug.Print "數" & i & "=" & a(i)
Next
For j = 1 To 9
Debug.Print "范圍" & (j * 10) & "到" & (j * 10 + 9) & "的數有" & b(j) & "個。"
Next

⑵ VB編程,超簡單的。求編寫代碼

第一題:
Private Sub Form_Click()
Dim x As Double, Y As Double
x = InputBox("請輸入當前顧客購買雞蛋的重量(以公斤為單位)")
If x < 3 Then
Y = 7.6 * x
Else
Y = 7.6 * x * 0.8
End If
Print Format(Y, "0.00")
End Sub

第二題:
Private Sub Form_Click()
Dim x As Double, Y As Double
x = InputBox("請輸入顧客所乘的公里數")
If x / Fix(x) = 1 Then
x = x
Else
x = Fix(x) + 1
End If

If x > 15 Then
Y = 7 + 13 * 1.5 + (x - 15) * 2.1
ElseIf x > 2 Then
Y = 7 + (x - 2) * 1.5
Else
Y = 7
End If

Print Y
End Sub

⑶ 求VB中必須背過的命令

789+
456-
123*
0.=/

每個一個按鈕(每個按鈕對應數字),一個文本框。
一下是最基礎代碼(其實可以用按鈕數組)
----------------------

Dim d As Integer
Dim x As String
Dim y As String
Dim k As Integer
Private Sub Command1_Click(Index As Integer)
Label1.Caption = Label1.Caption + Command1(Index).Caption
End Sub

Private Sub Command2_Click()
y = Label1.Caption
If d = 0 Then
Label1.Caption = Val(x) + Val(y)
End If
If d = 1 Then
Label1.Caption = Val(x) - Val(y)
End If
If d = 2 Then
Label1.Caption = Val(x) * Val(y)
End If
If d = 3 Then
If Val(y) = 0 Then
Label1.Caption = "被除數不能為零"
Else
Label1.Caption = Val(x) / Val(y)
End If
End If
End Sub

Private Sub Command3_Click()
x = Label1.Caption
Label1.Caption = ""
d = 0
k = 0
End Sub

Private Sub Command4_Click()
x = Label1.Caption
Label1.Caption = ""
d = 1
k = 0
End Sub

Private Sub Command5_Click()
x = Label1.Caption
Label1.Caption = ""
d = 2
k = 0
End Sub

Private Sub Command6_Click()
x = Label1.Caption
Label1.Caption = ""
d = 3
k = 0
End Sub

Private Sub Command7_Click()
Label1.Caption = Sqr(Val(Label1.Caption))
End Sub

Private Sub Command8_Click()
Label1.Caption = ""
d = 9
k = 0
End Sub

Private Sub Command9_Click()

If k = 0 Then
If Label1.Caption = "" Then
Label1.Caption = Label1.Caption + Str(0) + Command9.Caption
k = k + 1
Else
Label1.Caption = Label1.Caption + Command9.Caption
k = k + 1
End If
End If
End Sub

⑷ VB編程的程序

'再窗體上放一個按鈕command1,一個圖形控制項image1,和一個滾動條HScroll1,代碼如下:
Dim W, H As Double
Private Sub Command1_Click() '按鈕單擊事件
Image1.Stretch = True

With HScroll1
.Enabled = True
.Min = 100
.Max = 2400
.LargeChange = 200
.SmallChange = 20
End With
End Sub
Private Sub Form_Load()
HScroll1.Enabled = False
W = Me.Image1.Width
H = Me.Image1.Height
End Sub

Private Sub HScroll1_Change()
Me.Image1.Width = W + Me.HScroll1.Value
Me.Image1.Height = H + Me.HScroll1.Value
End Sub

閱讀全文

與vb編程必背50個程序相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:144
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:736
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163