永发信息网

求注解 Dim flag As Boolean 里面的flag=false与flag=true不懂

答案:2  悬赏:80  手机版
解决时间 2021-02-07 12:37
  • 提问者网友:喧嚣尘世
  • 2021-02-07 04:36
Private Sub Command1_Click()
Dim y1 As Integer
Dim m1 As Integer
Dim flag As Boolean
y1 = Val(Text1.Text)
m1 = Val(Text2.Text)
flag = False
If y1 / 4 = Int(y1 / 4) And y1 / 100 <> Int(y1 / 100) Then
Text3.Text = Text1.Text & "是闰年"
flag = True
Else
Text3.Text = Text1.Text & "不是闰年"
flag = False
End If
Select Case m1
Case 1, 2, 12
Text4.Text = "冬季winter"
Case 3, 4, 5
Text4.Text = "春季spring"
Case 6, 7, 8
Text4.Text = "夏季summer"
Case 9, 10, 11
Text4.Text = "秋季fall"
End Select
Select Case m1
Case 1, 3, 5, 7, 8, 10, 12
Text5.Text = Text2.Text & "这月31天"
Case 4, 6, 9, 11
Text5.Text = Text2.Text & "这月30天"
Case 2
If flag Then
Text5.Text = Text2.Text & "这月29天"
Else
Text5.Text = Text2.Text & "这月28天"
End If
End Select
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
最佳答案
  • 五星知识达人网友:酒醒三更
  • 2021-02-07 05:29
flag是一个Boolean类型的变量,起标志的作用。

//...
m1 = Val(Text2.Text)
flag = False //初始值为False
If y1 / 4 = Int(y1 / 4) And y1 / 100 <> Int(y1 / 100) Then
Text3.Text = Text1.Text & "是闰年"
flag = True //是闰年时赋值为True
Else
Text3.Text = Text1.Text & "不是闰年"
flag = False //不是闰年时赋值为False
End If
//...
全部回答
  • 1楼网友:封刀令
  • 2021-02-07 06:56
这应该是vb的语法吧,dim是定义在一个范围的修饰词,在哪块定义,它就只能在哪块用.就像你在某个方法内用,它就只能在那个方法里可用.当然,定义全局的,也可以.那就是全局属性了,和public,private,protected理解差不多.flag是一个变量名.as 后接返回类型. 意思就是定义一个返回类型为布尔型的变量flag.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯