⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 星期几问题.frm

📁 算法教案
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "星期几计算"
   ClientHeight    =   2580
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3915
   LinkTopic       =   "Form1"
   ScaleHeight     =   2580
   ScaleWidth      =   3915
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   2160
      MaxLength       =   2
      TabIndex        =   9
      Top             =   480
      Width           =   375
   End
   Begin VB.TextBox Text4 
      Height          =   375
      Left            =   960
      TabIndex        =   5
      Top             =   1320
      Width           =   2535
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   3000
      MaxLength       =   2
      TabIndex        =   4
      Top             =   480
      Width           =   375
   End
   Begin VB.TextBox Text1 
      BeginProperty DataFormat 
         Type            =   0
         Format          =   "yyyy-M-d"
         HaveTrueFalseNull=   0
         FirstDayOfWeek  =   0
         FirstWeekOfYear =   0
         LCID            =   2052
         SubFormatType   =   0
      EndProperty
      Height          =   375
      Left            =   1080
      MaxLength       =   4
      TabIndex        =   2
      Top             =   480
      Width           =   615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "计算"
      Height          =   495
      Left            =   1680
      TabIndex        =   0
      Top             =   1920
      Width           =   975
   End
   Begin VB.Label Label5 
      Caption         =   "日"
      Height          =   495
      Left            =   3480
      TabIndex        =   8
      Top             =   480
      Width           =   375
   End
   Begin VB.Label Label4 
      Caption         =   "月"
      Height          =   495
      Left            =   2640
      TabIndex        =   7
      Top             =   480
      Width           =   255
   End
   Begin VB.Label Label3 
      Caption         =   "年"
      Height          =   495
      Left            =   1800
      TabIndex        =   6
      Top             =   480
      Width           =   255
   End
   Begin VB.Label Label2 
      Caption         =   "输入日期:"
      Height          =   495
      Left            =   120
      TabIndex        =   3
      Top             =   480
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "结果:"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   1440
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Function leap(y As Integer) As Integer  '判断是否为闰年函数,是返回1,不是返回0
    If y Mod 100 = 0 Then
       If y Mod 400 = 0 Then leap = 1 Else leap = 0
    Else
       If y Mod 4 = 0 Then leap = 1 Else leap = 0
    End If
End Function

Private Sub Command1_Click()
  Dim year As Integer, month, day, w, c, y, m, d, ok As Integer
  year = Val(Text1.Text)
  month = Val(Text2.Text)
  day = Val(Text3.Text)
  ok = 0
  If (month = 1 Or month = 3 Or month = 5 Or month = 7 Or month = 8 Or month = 10 Or month = 12) And (day >= 1 And day <= 31) Then ok = 1
  If (month = 4 Or month = 6 Or month = 9 Or month = 11) And (day >= 1 Or day <= 30) Then ok = 1
  If leap(year) = 1 And month = 2 And (day >= 1 And day <= 29) Then ok = 1
  If leap(year) = 0 And month = 2 And (day >= 1 And day <= 28) Then ok = 1
  If ok = 0 Then
      Text4.Text = "输入日期有错误"
  Else
      If month = 1 Or month = 2 Then
         year = year - 1
         month = month + 12
      End If
      c = year \ 100
      y = year Mod 100
      m = month
      d = day
      w = Int(c / 4) - 2 * c + y + Int(y / 4) + Int(13 * (m + 1) / 5) + d - 1
      Text4.Text = Str(c) + Str(y) + Str(m) + Str(d) + Str(w)
      w = (w + 700) Mod 7 + 1         '求除以7的余数,w加上700保证余数一定是整数
      Text4.Text = WeekdayName(w)    '转换为星期形式
  End If
End Sub

Private Sub Form_Load()
  Text1.Text = ""
  Text2.Text = ""
  Text3.Text = ""
  Text4.Text = ""
End Sub

Private Sub Text1_Click()
  Text1.Text = ""
  Text2.Text = ""
  Text3.Text = ""
  Text4.Text = ""
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -