vbnet
Imports System.IO.Ports
'Imports System.IO
'Imports ADOX
Public Class Form1
Dim 列表 As New DataGridView
Dim wb1 As New TextBox
Dim wb2 As New TextBox
Dim aj As New Button
Dim xs As New TextBox
Dim 串行端口 = New SerialPort
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "VB解答专用窗体"
wb1.Parent = Me
wb1.Text = "3"
wb2.Parent = Me
wb2.Text = "47"
xs.Parent = Me
xs.Text = "质数:"
aj.Parent = Me
aj.Text = "查找"
wb2.Location = New Point(wb1.Width + 7)
aj.Location = New Point(wb1.Width + wb2.Width + 7 * 2)
xs.Location = New Point(wb1.Width + wb2.Width + aj.Width + 7 * 3)
xs.Width = Me.Width - (wb1.Width + wb2.Width + aj.Width + 7 * 3)
xs.WordWrap = True
xs.Height = Me.Height
xs.Multiline = True
AddHandler aj.Click, AddressOf 按键单击
End Sub
Private Sub 按键单击(sender As Object, e As EventArgs)
'缘由https://ask.csdn.net/questions/7477534?spm=1005.2025.3001.5141
xs.Text = "质数:"
Dim a = Integer.Parse(wb1.Text.Trim())
Dim b = Integer.Parse(wb2.Text.Trim())
Dim c As Integer = 3
While a <= b And a > 1
If a = 2 Or a = 3 Then
xs.AppendText(a.ToString("0 "))
a = IIf(a = 2, a + 1, a + 2)
ElseIf c <= a / c Then
If (a Mod c = 0) Then
a = a + 2
c = 3
Else
c = c + 2
End If
Else
xs.AppendText(a.ToString("0 "))
a = a + 2
c = 3
End If
End While
End Sub
Private Sub Excel复制工作簿()
Dim myExcelApp As New Microsoft.Office.Interop.Excel.Application
myExcelApp.Workbooks.Open(System.Environment.CurrentDirectory + "\\测试用例.xlsx", Type.Missing)
myExcelApp.Workbooks.Open(System.Environment.CurrentDirectory + "\\复制用例.xlsx", Type.Missing)
Dim worksheet1 As Microsoft.Office.Interop.Excel.Worksheet = CType(myExcelApp.Workbooks(1).Worksheets(1), _
Microsoft.Office.Interop.Excel.Worksheet)
Dim worksheet2 As Microsoft.Office.Interop.Excel.Worksheet = CType(myExcelApp.Workbooks(2).Worksheets(1), _
Microsoft.Office.Interop.Excel.Worksheet)
worksheet1.Copy(After:=worksheet2)
myExcelApp.Workbooks(2).Save()
myExcelApp.Quit()
myExcelApp = Nothing
End Sub
End Class

缘由VB求素数问题,提示:须使用双分支选择结构。_软件工程-CSDN问答
vbnet
Private Sub 按键单击(sender As Object, e As EventArgs)
'缘由https://ask.csdn.net/questions/7477534?spm=1005.2025.3001.5141
xs.Text = "质数:"
Dim a = Integer.Parse(wb1.Text.Trim())
If a < 30 Then
MessageBox.Show("数据无效可重新输入!", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
wb1.Focus()
End If
Dim b = Integer.Parse(wb2.Text.Trim())
Dim c As Integer = 3, h As Integer = 0, q = 2
While q <= a And q > 1
If q = 2 Or q = 3 Then
xs.AppendText(q.ToString("0 "))
h = h + q
q = IIf(q = 2, q + 1, q + 2)
ElseIf c <= q / c Then
If (q Mod c = 0) Then
q = q + 2
c = 3
Else
c = c + 2
End If
Else
xs.AppendText(q.ToString("0 "))
h = h + q
q = q + 2
c = 3
End If
End While
wb2.Text = h
End Sub