用VB写个弹窗确认功能的代码
时间: 2023-04-07 07:03:05 浏览: 120
以下是用VB写弹窗确认功能的代码:
Private Sub btnConfirm_Click()
Dim result As Integer
result = MsgBox("确定要执行此操作吗?", vbOKCancel, "确认")
If result = vbOK Then
'执行操作
Else
'取消操作
End If
End Sub
希望能对您有所帮助。
相关问题
用VB语言写个弹窗确认功能的代码
以下是用VB语言写弹窗确认功能的代码:
Private Sub CommandButton1_Click()
Dim response As Integer
response = MsgBox("确定要执行此操作吗?", vbYesNo, "确认")
If response = vbYes Then
'执行操作
Else
'取消操作
End If
End Sub
希望能对您有所帮助。
用vb写一个求素数代码
以下是用 VB 编写的求素数代码:
Private Function IsPrime(ByVal num As Integer) As Boolean
If num <= 1 Then
Return False
End If
For i As Integer = 2 To Math.Sqrt(num)
If num Mod i = 0 Then
Return False
End If
Next
Return True
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim n As Integer = Integer.Parse(TextBox1.Text)
Dim primes As New List(Of Integer)
For i As Integer = 2 To n
If IsPrime(i) Then
primes.Add(i)
End If
Next
MessageBox.Show(String.Join(", ", primes))
End Sub
这个代码可以在一个文本框中输入一个整数 n,然后输出从 2 到 n 之间的所有素数。