visual basic源码实列
时间: 2023-12-05 17:01:34 浏览: 42
Visual Basic是一种易学易用的编程语言,可以用来创建各种类型的软件应用程序。以下是一个简单的Visual Basic源码实例,用于创建一个简单的计算器应用程序。
```vb
Public Class Form1
Dim firstNumber As Double
Dim secondNumber As Double
Dim operation As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text & "1"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text & "2"
End Sub
' ... 省略其他数字按钮的处理函数 ...
Private Sub ButtonPlus_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click
firstNumber = Val(TextBox1.Text)
operation = "+"
TextBox1.Text = ""
End Sub
Private Sub ButtonEquals_Click(sender As Object, e As EventArgs) Handles ButtonEquals.Click
secondNumber = Val(TextBox1.Text)
If operation = "+" Then
TextBox1.Text = firstNumber + secondNumber
End If
If operation = "-" Then
TextBox1.Text = firstNumber - secondNumber
End If
If operation = "*" Then
TextBox1.Text = firstNumber * secondNumber
End If
If operation = "/" Then
TextBox1.Text = firstNumber / secondNumber
End If
End Sub
' ... 省略其他运算符按钮的处理函数 ...
End Class
```
上面的源码创建了一个简单的计算器应用程序。当用户点击数字按钮时,数字将显示在文本框中。当用户点击运算符按钮时,将保存当前文本框中的数字,并清零文本框以供用户输入下一个数字。当用户点击“=”按钮时,计算器会执行保存的操作并显示结果。这个源码实例展示了Visual Basic如何用来创建简单的应用程序界面和实现基本的计算功能。
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)