導航:首頁 > 編程語言 > 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個程序相關的資料

熱點內容
肌肉塑造全書pdf下載 瀏覽:796
安卓簡約拼圖用什麼軟體好 瀏覽:289
fx1n加密程序 瀏覽:844
淘客阿里雲伺服器 瀏覽:476
100壓縮打造 瀏覽:422
安卓手機怎麼和蘋果平板傳文件 瀏覽:973
開始選項卡中的頁眉和頁腳命令選項 瀏覽:424
pdf的字體怎麼改 瀏覽:856
python讀寫視頻 瀏覽:88
科魯茲壓縮機軸承 瀏覽:353
word文檔轉換成pdf文件找不到 瀏覽:27
組件注冊命令 瀏覽:760
安卓大屏導航用的是什麼運放 瀏覽:443
myandroidtools的備份 瀏覽:900
python爬蟲天氣預報 瀏覽:761
android70許可權管理 瀏覽:749
魔獸辛迪加是什麼伺服器 瀏覽:472
電腦文件夾排序怎麼自定義排序 瀏覽:41
android70機型 瀏覽:422
阿里程序員地位 瀏覽:183