2021-07-21 VB窗体求范围质数(Excel复制工作簿)

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
相关推荐
fanchenxinok1 天前
学习笔记:LabVIEW调用DLL解析S19文件教程
笔记·学习·labview·dll解析
疯狂打码的少年1 天前
【软件工程】结构化设计:模块独立性与耦合内聚
java·开发语言·笔记·软件工程
卡提西亚1 天前
leetcode-1438. 绝对差不超过限制的最长连续子数组
算法·leetcode·职场和发展
Java面试题总结1 天前
LeetCode 93.复原IP地址
算法·leetcode·职场和发展·.net
从零开始的代码生活_1 天前
C++ 多态详解:虚函数、动态绑定、抽象类与虚表原理
开发语言·c++·后端·学习·算法
泷寂1 天前
最小生成树 (MST基础)
算法
Daniel_1231 天前
数组——总结篇
算法
德思特1 天前
从人工测试到自动化验证:AutoGNSS 如何重构GNSS测试流程?
经验分享
不懒不懒1 天前
【针对路面识别数据集,结合三轴加速度标准化数据及多路面识别需求,以下是算法选择与处理方案】
算法
Reart1 天前
Leetcode 121. 买卖股票的最佳时机(717)
后端·算法