两道vb编程题 两道VB程序设计的题~
\u4e24\u9053vb\u9898Private Sub Form_Click()Dim i As Integer, j As IntegerFor i = 1 To 8 Print Spc(8 - i); For j = 1 To i Print "*"; Next PrintNextEnd SubPrivate Sub Form_Click()Dim i As Integer, n As Integer, sum As IntegerFor i = 1 To 2 n = Val(InputBox("\u8bf7\u8f93\u5165\u7b2c" & i & "\u4e2a\u5b66\u751f\u7684\u6210\u7ee9", "\u63d0\u793a")) sum = sum + n NextMsgBox "\u5168\u73ed10\u540d\u540c\u5b66\u7684\u5e73\u5747\u6210\u7ee9\u662f" & sum / 10End Sub
\u4e00\u3001
\u95ee\u9898\u4e00\uff1a
(1) Label
(2) Text
(3) List
(4) Check
(5) Combo
(6) Picture
(7) Frame
(8) Command
\u95ee\u9898\u4e8c\uff1a
AddItem\u65b9\u6cd5
\u95ee\u9898\u4e09\uff1a
Alignment\u5c5e\u6027
\u4e8c\u3001
\u95ee\u9898\u4e00\uff1a
(1) Label
(2) Combo
(3) Check
(4) Text
\u95ee\u9898\u4e8c\uff1a
BorderStyle\u5c5e\u6027
\u95ee\u9898\u4e09\uff1a
Value\u5c5e\u6027\uff0c\u8bbe\u7f6e\u4e3a vbChecked \u503c\u3002
Private Sub Form_Load()
List1.Clear
List1.AddItem ""大学计算机基础""
List1.AddItem ""VB程序设计""
List1.AddItem ""数据库技术与应用""
List1.AddItem ""C程序设计""
List1.AddItem ""多媒体技术""
List1.AddItem ""硬件技术基础""
List1.AddItem ""网络技术与应用""
List1.AddItem ""WEB程序设计""
End Sub
Private Sub List1_Click()
If List2.ListCount >= 5 Then
MsgBox ""超过5门课程,不能再选!""
Exit Sub
Else
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End If
End Sub
2
Private Sub Command1_Click()
Dim N As Long, Flags As Boolean
N = Val(Text1.Text)
Flags = True
For i = 2 To Sqr(N)
If N Mod i = 0 Then
Flags = False
Exit For
End If
Next
MsgBox N & IIf(Flags, "", "不") & "是一个素数"
End Sub
1.放入两个ListBox控件 名字分别是List1,List2mList1的sorted属性为True
代码:
Private Sub Form_Load()
List1.AddItem "计算机应用"
List1.AddItem "软件工程"
List1.AddItem "信息化技术"
List1.AddItem "数据库"
List1.AddItem "C++"
List1.AddItem "软件重用"
List1.AddItem "web设计"
End Sub
Private Sub List1_Click()
If List2.ListCount = 4 Then
MsgBox "只能选4门课", , ""
Exit Sub
End If
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End Sub
2.
Private Sub Command1_Click()
Dim num As Long, temp As Boolean
num = Val(Text1.Text)
temp = True
For i = 2 To Sqr(num )
If num Mod i = 0 Then
temp= False
Exit For
End If
Next
if temp =false then
MsgBox num & "不是一个素数"
else
MsgBox num & "是一个素数"
end if
End Sub
绛旓細Private Sub Form_Click()x = Val(InputBox("璇疯緭鍏ラ噾棰"))If x < 1500 Then y = x ElseIf x < 2500 Then y = 0.9 * x ElseIf x < 3500 Then y = 0.8 * x Else y = 0.7 * x End If MsgBox "鎮ㄦ诲叡闇浠" & y & "鍏"End Sub Private Sub Command1_Click()y = ...
绛旓細x=1 y=2 鏄袱鍙ヨ鍙 鍦VB涓啋鍙风殑浣滅敤锛屼娇寰椾袱鍙ヨ鍙ュ彲浠ュ啓鍦ㄥ悓涓琛岄噷锛屼緥濡傦細x=1 : y=2 杩樺彲浠ュ鍙ヨ鍙 x=1 : y=2 : z=3 绛夌瓑 鍦╒B涓紝?鍙风殑浣滅敤锛岀浉褰撲簬Print 璇彞锛屽氨鏄湪绐椾綋鎴栬呭浘鐗囨锛圥icTureBox鎺т欢锛変笂杈撳嚭鍐呭锛屽垎鍙风殑浣滅敤灏辨槸浣垮緱涓や釜杈撳嚭鐨勫唴瀹圭揣杩炲湪涓璧凤紱鑰岄楀彿鐨勪綔鐢...
绛旓細绗竴棰樼瓟妗堜负锛3412銆傚厛鍙栧彸杈圭殑涓や釜瀛楃锛屽啀鍙栧乏杈圭殑涓や釜瀛楃锛屼袱鑰呰繛璧锋潵銆傜浜岄锛6銆傜娆¢櫎浠10鍙栦綑鏁帮紝灏辨槸灏嗗悇浣嶄竴浣嶄竴浣嶆嬁鍑烘潵鐩稿姞锛3+2+1=6
绛旓細绗竴棰橈細Private Sub Command1_Click()Dim x As Doublex = Val(Text1.Text)If x < -2 Then Text2.Text = 1 / (5 - x)ElseIf -2 <= x And x < 0 Then Text2.Text = x ^ 3 + 1ElseIf 0 <= x And x < 1 Then Text2.Text = Sin(x)ElseIf 1 <= x Then Text2....
绛旓細Option Base 1 Private Sub Command1_Click()' 1锛氭眰1+1/锛1+2锛+1/锛2+3锛+1/锛3+4锛...鐨勫墠N椤瑰拰 Dim N%, S!, i N = InputBox("N=", "杈撳叆", 5)S = 0 For i = 1 To N S = S + 1 / (i - 1 + i)Next i Print S End Sub Private Sub Command2_Click()...
绛旓細绗1棰橈細Private Sub Command1_Click() Dim a As Double, b As Double, r As Double a = CDbl(Text1.Text) b = CDbl(Text2.Text) r = Int(((a - b) ^ 3 + (a + 3 * b) ^ (1 / 3)) / (2 * a) + a * b) * 100 + 0.5) / 100 Text3.Text = rEnd ...
绛旓細Command1.Caption = "绗竴棰"Command2.Caption = "绗浜岄"Command3.Caption = "閫鍑"End Sub '鎴戣繖涓绋嬪簭鍒颁簡绗10灏忛涔熷嚭閿欙紝鍥犱负amt鍜宐mt鐨勭被鍨嬩笉鍚岋紝涓涓槸鏁板煎瀷锛屼竴涓槸瀛楃鍨嬶紝浜岃呮槸鏃犳硶姣旇緝澶у皬鐨勩'涓嶈浆鎹㈢被鍨嬩笉鑳芥瘮杈冦傛湁涓ょ鏂规硶杞崲锛'1銆佽浆鎹㈡垚鏁板瓧鍨:val(Amt)>Bmt '2銆佽浆鎹㈡垚...
绛旓細绗浜岄锛氫竴涓狢ommand銆侽ption Explicit Private Sub MyFunc _(ByVal n As Integer, ByRef Sum As Long)Dim a, ts As Long Sum = 0 Do While n > 0 ts = 1 For a = 1 To n ts = ts * a DoEvents: Next Sum = Sum + ts n = n - 1 DoEvents Loop End Sub Private Sub ...
绛旓細A鐨凙SCII鐮佸兼槸65,璇寸櫧浜嗗氨鏄绠楁満鍐呴儴鐢65琛ㄧずA,鑰宎鏄97,鎵 if "A">"a"鏄笉鎴愮珛鐨,鏄亣鍊,鎵浠hen鍚庣殑璇彞涓嶆墽琛,閭d箞閫 C,blnCheck涓嶅彉 2.鍒欴im鐨勫彉閲忓兼槸0 鑰0鍙互璁や负鏄疐alse,鏄亣鍊,閭f X灏辨槸鍋,杩欐椂鎵ц Else鍚庨潰鐨勮鍙,鎵浠ュ簲璇ユ樉绀1 閫夋嫨a ...
绛旓細(1)绌蜂妇娉曪紝鍒楀嚭浠1000鍒9999鎵鏈夌殑4浣嶆暟锛屽垎鍒祴璇曞叾鏄惁绛変簬鎵鍒嗕袱涓袱浣嶆暟鍜岀殑骞虫柟銆(2)璁$畻缁撴灉锛2025=(20+25)^2 3025=(30+25)^2 9810=(98+10)^2 (3)浠g爜濡備笅锛歅rivate Sub Command1_Click()For i = 1000 To 9999 If ((i \ 100) + (i Mod 100)) ^ 2 = i Then Print i...