當前位置:首頁 » 編程軟體 » 巧用vb編程

巧用vb編程

發布時間: 2023-05-22 13:47:23

① 用VB編寫一個計算器程序的代碼

1、創建控制項組的方法
首先創建一個命令按鈕,塵空調整其大小(覺得合適就行),名稱為Command1,Caption 屬性為數字 0 ;然後進行「復制」和「爛芹粘貼」,當選擇「粘貼」時,出現對話框提示已有一個同名控制項,詢問是否創建控制項組,選擇「是」後,即創建了一個名為「Command」的控制項組。

這時,第一個按鈕的Index屬性值默認為「0」,第二個的Index屬性值自動設為「1」,並且大小與第一個按鈕相同,只需修改其 Caption 屬性為數字「1」並將其拖至合適位置即可。此後繼續使用「粘貼」的方法建立其他控制項組中其餘按鈕,共20個按鈕,每建立一個,就將它拖到合適處,並修改相應的Caption屬性值。

2、各控制項組其屬性設置如飢兄畢下:

二、編寫代碼

Dim s1 As Single, s2 As Single, ysf As String

『定義兩個單精度數變數用與存放參與運算的數,一個字元型存放運算符

Private Sub Command1_Click(Index As Integer)

Text1.Text = Text1.Text & Command1(Index).Caption 』將command1的單擊事件與文本框顯示的內容連接

End Sub

Private Sub Command2_Click()

Text1.Text = Text1.Text + 「。」

If (InStr(Text1.Text, 「。」) = 1) Then 『第一位不能為小數

Text1.Text = 「」

End If

If InStr(Text1.Text, 「。」) 《 Len(Text1.Text) Then 』防止出現兩個小數點

Text1.Text = Left

(Text1.Text, Len(Text1.Text) - 1)

End If

End Sub

Private Sub

Command3_Click()

s2 = Val(Text1.Text) 『開始加減乘除運算

Select Case ysf Case 「+」

Text1.Text = s1 + s2

Case 「-」

Text1.Text = s1 - s2

Case 「*」

Text1.Text = s1 * s2

Case 「/」

If s2 = 0 Then

MsgBox 「分母不能為零!」

Text1.Text = 「」

Else

Text1.Text = s1 / s2 End If End Select

Text1 = IIf(Left(Text1.Text, 1) = 「。」, 0 & Text1.Text, Text1.Text) 『

這個很關鍵,如果沒有這個的話,得出小於1的小數前面沒有0

End Sub

Private Sub Command4_Click()

If Text1.Text = 「」 Then 』文本為空就結束

Exit Sub

End If

Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) 『文本退一格

End Sub

Private Sub Command5_Click()

Text1.Text = 「」 』清除當前框內文本

End Sub

Private Sub Command6_Click(Index As Integer)

s1 = Val(Text1.Text) 『將s1隱藏起來 ysf = Command6(Index).Caption

Text1.Text = 「」

End Sub

Private Sub Command7_Click()

If Left(Text1.Text, 1) 《》 「-」 Then 』判斷作為負數

Text1.Text = 「-」 & Text1.Text

Else

Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)

End If

End Sub

Private Sub Command8_Click()

Text1.Text = Text1.Text * Text1.Text 『平方

End Sub

拓展資料

Visual Basic(VB)是由微軟公司開發的包含環境的事件驅動編程語言。它源自於BASIC編程語言。VB擁有圖形用戶界面(GUI)和快速應用程序開發(RAD)系統,可以輕易的使用DAO、RDO、ADO連接資料庫,或者輕松的創建ActiveX控制項。程序員可以輕松地使用VB提供的組件快速創建一個應用程序。

參考鏈Visual Basic——網路接

② VB怎麼編程

Visual
Basic程序設計主要採用的是基於對象(主要是COM和ActiveX)和基於事件處理的可視化編程工具。在VB的IDE中通過可視化設計和布局窗口界面,並處理對象的事件代碼。
VB可以編寫任意Windows平台上的應用程序,但不包括Win32
Console
Application,到了.NET以後就例外了。
總的來說,VB的特點是簡單易學、入門簡單、操作方面、開發速度快等等。

③ VB編寫程序的步驟

拿本教程先學學語法,vb是面向對象的語言,你可以對照書上的例子在機器上學習編程.這樣影響更深刻,步驟都不是嚴格的,可以根據程序的需要來進行.但是第一步應該是程序的總體演算法,模塊,界面設計.

④ vb如何編程

Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim S As String, S1 As String, S2 As String
Dim I As Integer, J As Integer
Dim G As Integer, Hw As Boolean, Find As Boolean
S = Text1.Text
Text1.Text = Text1 + vbCrLf
S1 = S
G = 0
Do While S1 <> ""
Find = False
For I = 1 To Len(S1)
If Mid(S1, I, 1) = " " Or I = Len(S1) Then
Find = True
S2 = Trim(Left(S1, I))
If I = Len(S1) Then S1 = "" Else S1 = Right(S1, Len(S1) - I)
For J = 1 To Len(S2) \ 2
If Mid(S2, J, 1) <> Mid(S2, Len(S2) - J + 1, 1) Then
Hw = False
Exit For
End If
Hw = True
Next
If Hw Then
G = G + 1
Text1.Text = Text1 + " " + S2
End If
End If
If Find Then Exit For
Next
Loop
Text1.Text = Text1.Text + vbCrLf + "共有"穗山 + Str(G) + "個畝型迴文串"
End If
End Sub
已經運行過了,沒問題!即使串與串之間多輸入幾個空格也不影響猜耐中查找!

⑤ 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

熱點內容
生女的演算法 發布:2025-07-18 08:17:54 瀏覽:644
加密硬碟推薦 發布:2025-07-18 08:11:22 瀏覽:944
oppo手機的密碼是多少 發布:2025-07-18 08:10:27 瀏覽:764
2匹壓縮機重 發布:2025-07-18 08:01:40 瀏覽:181
雲蟻物聯的雲存儲怎麼取消退款 發布:2025-07-18 08:01:39 瀏覽:486
訪問電腦版網頁 發布:2025-07-18 08:01:02 瀏覽:246
php集成軟體 發布:2025-07-18 07:54:36 瀏覽:143
華為密碼多少我忘記了告訴我 發布:2025-07-18 07:53:05 瀏覽:286
安卓怎麼上傳音樂到網易雲 發布:2025-07-18 07:22:22 瀏覽:375
c語言保存txt文件 發布:2025-07-18 07:01:27 瀏覽:175