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
相关推荐
罗西的思考1 小时前
【轻量化复刻大模型 / KIMI K3】AttnRes 模块交互式演示
人工智能·算法·机器学习
聪明的笨猪猪3 小时前
Java 工程案例:AI 生成 @Async 异步线程池踩坑
java·经验分享·面试·ai编程
好悬给我拽开线4 小时前
ZILOT 论文解析
算法
饮水桶_T6 小时前
JAVA IO流笔记
开发语言·数据结构·算法
柳鲲鹏6 小时前
内斗学概论:43、平级内斗
笔记
星夜离尘566 小时前
MATLAB 离散数据分箱:半开区间、末端点与计数、加权和、平均
算法·matlab
Pniubi6 小时前
力扣76.最小覆盖子串
算法·leetcode·职场和发展
地平线开发者7 小时前
征程6|用 hrt\_model\_exec 看清 YOLOv5x 的输入、原始输出和后处理
人工智能·算法
csdn_aspnet8 小时前
C++ 3个有序点的方向(Orientation of 3 ordered points)
c++·算法
星恒随风8 小时前
MySQL 从零入门(四):表的增删改查与基础查询详解
linux·服务器·数据库·笔记·mysql