VB:编程题~~在文本框1中输入一个整数n,判断其能否同时被5和7整除……

[复制链接]
查看11 | 回复2 | 2019-10-9 11:14:34 | 显示全部楼层 |阅读模式
在窗体添加一个文本框和一个标签和一个按钮Private Sub Command1_Click()If Val(Text1.Text) Mod 5 = 0 And Val(Text1.Text) Mod 7 = 0 ThenLabel1.Caption = Text1.Text & "能同时被5和7整除"ElseLabel1.Caption = Text1.Text & "不能同时被5和7整除"End IfEnd Sub
回复

使用道具 举报

千问 | 2019-10-9 11:14:34 | 显示全部楼层
你新建一个窗体,上面text、label、command控件各一个Private Sub Command1_Click()If Not IsNumeric(Text1.Text) Then Exit SubIf Val(Text1.Text) Mod 5 = 0 And Val(Text1.Text) Mod 7 = 0 Then
Label1.Caption = Text1.Text & "能同时被5和7 整除"Else
Label1.Caption = Text1.Text & "不能同时被5和7 整除"End IfEnd Sub
回复

使用道具 举报

千问 | 2019-10-9 11:14:34 | 显示全部楼层
_Partial Class Form1
Inherits System.Windows.Forms.Form
'Form 重写 Dispose,以清理组件列表。
_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
_
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(26, 82)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Tag = ""
Me.Button1.Text = "开始判读"
Me.Button1.UseVisualStyleBackColor = True
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(115, 28)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(159, 21)
Me.TextBox1.TabIndex = 2
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(129, 87)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(65, 12)
Me.Label2.TabIndex = 3
Me.Label2.Text = "判读结果:"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 31)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(89, 12)
Me.Label1.TabIndex = 3
Me.Label1.Text = "请输入一个数字"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(360, 138)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.LabelEnd ClassPublic Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
If Me.TextBox1.Text.Trim()String.Empty Theni = CInt(Me.TextBox1.Text.Trim())
If i Mod 5 = 0 And i Mod 7 = 0 Then
Me.Label2.Text = "判读结果:" + i.ToString() + "能够被 5 和 7 同时整除"
Else
Me.Label2.Text = "判读结果:" + i.ToString() + "不能够被 5 和 7 同时整除"
End If
End If
End SubEnd Class
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行