編程vb
1. VB編程。
2樓的是錯的。inputbox函數里輸入的是字元,要用val函數將其轉為數字。
a=val(inputbox(......))
2. 用vb編程
1、
Private Sub Command1_Click()
Dim N As Integer, bF As Boolean, dt As String
Dim k As Integer, m As Integer, nn As Integer, mm As Integer, tt As String
N = InputBox("請輸入N值(N>100)")
nn = 0: mm = 0: tt = ""
For k = 3 To N
bF = False
For m = 2 To k - 1
If (k Mod m) = 0 Then
bF = True
Exit For
End If
Next
If Not bF Then
nn = nn + 1
mm = mm + 1
dt = CStr(k)
tt = tt & Space(8 - Len(dt)) & dt
If mm = 10 Then
mm = 0
Print tt
tt = ""
End If
End If
Next
End Sub
2、
Private Sub Command2_Click()
Dim m As Integer, n As Integer, mm As Integer, nn As Integer
Dim k As Integer, r As Integer
m = InputBox("請輸入一個自然數m")
n = InputBox("請輸入一個自然數n")
mm = m: nn = n
If m < n Then
k = m: m = n: n = k
End If
Do
r = m Mod n
If r > 0 Then
m = n: n = r
End If
Loop Until r = 0
MsgBox mm & "和" & nn & "的最大公約數是" & n
End Sub
3. 編寫程序VB
Option Explicit
Dim a(49) As Integer, i As Integer, j As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "請輸入要查找的內容", vbOKOnly + vbExclamation, "系統提示"
Text1.SetFocus
Exit Sub
End If
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1.Text Then
Label3.Caption = "已生成!"
Exit For
Else
Label3.Caption = "未生成!"
End If
Next
End Sub
Private Sub Form_Load()
List1.Clear
For i = 0 To 49
a(i) = Int(Rnd() * 99 + 1)
For j = 0 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next j
Next i
For j = 0 To 49
List1.AddItem a(j)
Next j
End Sub
4. VB編程用什麼軟體好
VB是微軟出品的,能夠使用的VB編程軟體只有Visual Studio
不過VisualStudio有很多版本
從VB 6.0到VisualStudio2002.Net、VisualStudio2003.Net、VisualStudio2005、VisualStudio2008各有不同,看你的喜好了
5. vb編程是什麼意思,主要幹嘛的
VB程序開發的基本流程是:界面設計(放置窗體和控制項)――屬性設置(設置窗體、控制項的屬性)――編寫代碼――運行調試。其優點是在窗體上添加控制項並設置屬性後就可完成界面的設計使程序員輕易的就可完成界面的設計,而無需過多的進行設計和編程。只需調用預先准備好的、經過測試的、完全就緒的模塊就可完成所需實現的功能。這種備用性的軟體模塊被稱作――組件。窗體和各種控制項就是組件。
VB編程的核心思想就是組件編程。VB是最早引入組件編程的概念,其後被其它語言所採用並成為一種標准,如VC++、Delphi、PowerBuilder都採用組件編程模型,並採用面向對象編程技術,成為當今程序設計的發展方向之一。
VB編程時,因為使用組件技術,所以不必從底層的窗體、控制項開始設計,可以向工廠通過各種部件組裝生產機器一樣,通過微軟或第三方提供的組件,組裝成所需的程序。用什麼組裝?就是用VB的代碼,其作用就像膠水一樣,用有限的代碼和組件聯結成一體。最後形成一個完整的應用程序。
如果沒有現成的組件或需要創建一個新類時,就需要編寫代碼。 組件的種類很多,有多少組件可用,各組件有什麼作用,這需要在實踐中不斷摸索。
6. 用vb編寫一個簡單的程序
上面的程序有問題
'給窗口加3個TEXT控制項
text.text
都設為0,再加個COMMAND
控制項
'付上以下程序
OK了
Private
Sub
Command1_Click()
Dim
D
As
Single,
L
As
Single
D
=
Val(Text1.Text)
L
=
val(Text2.Text)
v
=
0.7854
*
L
*
(D
+
0.5
*
L
+
0.005
*
L
^
2
+
0.000125
*
L
*
(14
-
L)
^
2
*
(D
-
10))
^
2
/
1000
Text3.Text
=
v
End
Sub
7. vb編程超簡單
PrivateSubCommand1_Click()
Text2.Text=""
Text2.Text=Text2.Text+Text1.Text
Fori=0To2
IfOption1(i).Value=TrueThen
Text2.Text=Text2.Text+Space(3)+"職稱:"+Option1(i).Caption+Space(3)
Else
Option1(i).Enabled=False
EndIf
Nexti
Text2.Text=Text2.Text+"愛好:"
Fori=0To2
IfCheck1(i).Value=1Then
Text2.Text=Text2.Text+Check1(i).Caption+Space(1)
Else
Check1(i).Enabled=False
EndIf
Nexti
Text2.Text=Text2.Text+Space(2)+"籍貫:"+List1.List(List1.ListIndex)+Space(3)
Text2.Text=Text2.Text+"部門:"+Combo1.Text
EndSub
PrivateSubCommand2_Click()
End
EndSub
PrivateSubForm_Load()
Option1(0).Caption="初級"
Option1(1).Caption="中級"
Option1(2).Caption="高級"
Check1(0).Caption="音樂"
Check1(1).Caption="體育"
Check1(2).Caption="繪畫"
List1.AddItem"北京市"
List1.AddItem"江蘇省"
List1.AddItem"江西省"
List1.AddItem"山東省"
List1.AddItem"山西省"
List1.AddItem"浙江省"
List1.AddItem"遼寧省"
List1.AddItem"天津市"
List1.AddItem"湖南省"
List1.AddItem"河北省"
List1.AddItem"上海市"
List1.AddItem"廣東省"
Combo1.AddItem"電子系"
Combo1.AddItem"數學系"
Combo1.AddItem"計算機系"
Combo1.AddItem"物理系"
Combo1.AddItem"化學系"
Combo1.AddItem"天文系"
Combo1.AddItem"地質系"
Combo1.AddItem"醫學系"
Text1.Text=""
Text2.Text=""
EndSub
PrivateSubFrame1_Click()
Fori=0To2
IfOption1(Index).Value=FalseThenOption1(Index).Enabled=False
Nexti
EndSub
8. vb編程vb編程
Private Sub Command1_Click()
Dim j%, k%, m%, n%, mArr(1 To 80), OArr(), EArr(), ZArr(), Q%, E%, tmP%, Z%, mSum%
Q = 1
E = 1
Z = 1
Print "80個隨機整數:"
For j = 1 To 80
Randomize
mArr(j) = Int(90 * Rnd + 10)
Print CStr(mArr(j)); Spc(2);
If j Mod 10 = 0 Then Print
Next j
Print
For m = 1 To 79 '排序
For n = 80 To m + 1 Step -1
If mArr(n) < mArr(n - 1) Then tmP = mArr(n): mArr(n) = mArr(n - 1): mArr(n - 1) = tmP
Next n
Next m
For m = 1 To 80 '奇偶分組
If mArr(m) Mod 2 = 1 Then
ReDim Preserve OArr(1 To Q)
OArr(Q) = mArr(m)
Q = Q + 1
Else
ReDim Preserve EArr(1 To E)
EArr(E) = mArr(m)
E = E + 1
End If
If zs(CInt(mArr(m))) = True Then '素數分組
ReDim Preserve ZArr(1 To Z)
ZArr(Z) = mArr(m)
mSum = mSum + ZArr(Z)
Z = Z + 1
End If
Next m
Print
Print "偶數:" '在窗體輸出
For m = 1 To UBound(EArr)
Print CStr(EArr(m)); Spc(2);
If m Mod 10 = 0 Then Print
Next m
Print
Print
Print "奇數:"
For m = 1 To UBound(OArr)
Print CStr(OArr(m)); Spc(2);
If m Mod 10 = 0 Then Print
Next m
Print
Print
Print "素數:"
For m = 1 To UBound(ZArr)
Print CStr(ZArr(m)); Spc(2);
If m Mod 10 = 0 Then Print
Next m
Print
Print "素數個數:"; UBound(ZArr)
Print "素數之和:"; mSum
End Sub
Private Function zs(x As Integer) As Boolean '素數判斷子過程
Dim d%
If x = 2 Then zs = True: Exit Function
For d = 2 To Int(Sqr(x))
If x Mod d = 0 Then Exit For: zs = False
If d = Int(Sqr(x)) Then zs = True
Next
End Function
9. VB編程是什麼
vb是用來編寫應用程序的,它寫出的程序運行於微軟的windows,不同的程序應用於不同的地方,如辦公軟體、監控軟體、計量軟體等等。