标签标题到微调按钮值
Label caption to spinbutton value
我在将值从标签标题加载到微调按钮值并返回时遇到问题。我有一些来自报告的数据,但我只需要 6-8 小时的报告,所以我制作了表格,我想在其中设置开始时间和结束时间 (yyyy,mm,dd hh:mm) 然后我想要删除行,这不是我的时间,所以我将年、月、日、小时和分钟作为 Now() 加载到标题中,然后我需要将标签的标题加载到旋转按钮的值,然后我需要将标题更改为值,就像有旋转按钮。感谢您的帖子,对不起我的英语 ;) 这是我的代码:
Sub spust()
formtime.lblrok1.Caption = Format(Now, "yyyy")
formtime.lblmes1.Caption = Format(Now, "mm")
formtime.lblden1.Caption = Format(Now, "dd")
formtime.lblhod1.Caption = Format(Now, "hh")
formtime.lblmin1.Caption = Minute(Now)
If Len(formtime.lblmin1.Caption) = 1 Then
formtime.lblmin1.Caption = "0" & Minute(Now)
End If
formtime.lblrok2.Caption = Format(Now, "yyyy")
formtime.lblmes2.Caption = Format(Now, "mm")
formtime.lblden2.Caption = Format(Now, "dd")
formtime.lblhod2.Caption = Format(Now, "hh")
formtime.lblmin2.Caption = Minute(Now)
If Len(formtime.lblmin2.Caption) = 1 Then
formtime.lblmin2.Caption = "0" & Minute(Now)
End If
With formtime.spbutrok1
'my problem -> .Value = CInt(formtime.lblrok1.Caption)
.Min = 2010
.Max = 2030
End With
formtime.lblrok1.Caption = CStr(formtime.spbutrok1.Value)
formtime.Show
End Sub
SpinButton
可能非常棘手
你的问题是由于默认的 SpinButton
控制边界是 0 (Min
属性) 和 100 (Max
属性) 和您正在尝试将其 Value
属性 设置为明显超过它的某个 20XX 数字(lblrok1.Caption
之前已初始化为该数字!
似乎解决方案是推迟该设置:
With formtime.spbutrok1
.Min = 2010
.Max = 2030
.Value = CInt(formtime.lblrok1.Caption)
End With
但还有另一个 SpinButton
问题:
到 link Label
标题到 SpinButton
值你必须在用户窗体代码窗格中编码如下:
Private Sub spbutrok1_Change()
With Me
.lblrok1.Caption = .spbutrok1.value
End With
End Sub
关于 SpinButton
边界的定义,如果它的 current Value
不在它们之间,那么它被设置为其 当前 Min
和 Max
值之间的最小值
如果后一个条件适用并导致 SpinButton
Value
) 的 实际 更改,那么它将触发其 'Change()' 事件会将标签标题再次更改为您期望的值
在你的情况下,结果将是 SpinButton
Value
和相应的 Label
Caption
设置为 2010...
所以你可能想采用这样的顺序:
With formtime.spbutrok1
.max = 2030'<--| this may trigger SB 'Change()' event handler that, via appropriate event handler coding, changes corresponding label capition accordingly
.min = 2011'<--| this may trigger SB 'Change()' event handler that, via appropriate event handler coding, changes corresponding label capition accordingly
.value = Format(Now, "yyyy"),'<-- set SB value to wanted value. And if this results in an actual change of the preceding value, then it'll trigger its 'Change()' event also that changes corresponding label capition accordingly
End With
除此之外,日期问题(月份界限不同,闰年会造成更多混乱)可能会给您带来更多编码问题:如果是这种情况,您可能需要发布其他帖子...
我在将值从标签标题加载到微调按钮值并返回时遇到问题。我有一些来自报告的数据,但我只需要 6-8 小时的报告,所以我制作了表格,我想在其中设置开始时间和结束时间 (yyyy,mm,dd hh:mm) 然后我想要删除行,这不是我的时间,所以我将年、月、日、小时和分钟作为 Now() 加载到标题中,然后我需要将标签的标题加载到旋转按钮的值,然后我需要将标题更改为值,就像有旋转按钮。感谢您的帖子,对不起我的英语 ;) 这是我的代码:
Sub spust()
formtime.lblrok1.Caption = Format(Now, "yyyy")
formtime.lblmes1.Caption = Format(Now, "mm")
formtime.lblden1.Caption = Format(Now, "dd")
formtime.lblhod1.Caption = Format(Now, "hh")
formtime.lblmin1.Caption = Minute(Now)
If Len(formtime.lblmin1.Caption) = 1 Then
formtime.lblmin1.Caption = "0" & Minute(Now)
End If
formtime.lblrok2.Caption = Format(Now, "yyyy")
formtime.lblmes2.Caption = Format(Now, "mm")
formtime.lblden2.Caption = Format(Now, "dd")
formtime.lblhod2.Caption = Format(Now, "hh")
formtime.lblmin2.Caption = Minute(Now)
If Len(formtime.lblmin2.Caption) = 1 Then
formtime.lblmin2.Caption = "0" & Minute(Now)
End If
With formtime.spbutrok1
'my problem -> .Value = CInt(formtime.lblrok1.Caption)
.Min = 2010
.Max = 2030
End With
formtime.lblrok1.Caption = CStr(formtime.spbutrok1.Value)
formtime.Show
End Sub
SpinButton
可能非常棘手
你的问题是由于默认的 SpinButton
控制边界是 0 (Min
属性) 和 100 (Max
属性) 和您正在尝试将其 Value
属性 设置为明显超过它的某个 20XX 数字(lblrok1.Caption
之前已初始化为该数字!
似乎解决方案是推迟该设置:
With formtime.spbutrok1
.Min = 2010
.Max = 2030
.Value = CInt(formtime.lblrok1.Caption)
End With
但还有另一个 SpinButton
问题:
到 link
Label
标题到SpinButton
值你必须在用户窗体代码窗格中编码如下:Private Sub spbutrok1_Change() With Me .lblrok1.Caption = .spbutrok1.value End With End Sub
关于
SpinButton
边界的定义,如果它的 currentValue
不在它们之间,那么它被设置为其 当前Min
和Max
值之间的最小值如果后一个条件适用并导致
SpinButton
Value
) 的 实际 更改,那么它将触发其 'Change()' 事件会将标签标题再次更改为您期望的值在你的情况下,结果将是
SpinButton
Value
和相应的Label
Caption
设置为 2010...
所以你可能想采用这样的顺序:
With formtime.spbutrok1
.max = 2030'<--| this may trigger SB 'Change()' event handler that, via appropriate event handler coding, changes corresponding label capition accordingly
.min = 2011'<--| this may trigger SB 'Change()' event handler that, via appropriate event handler coding, changes corresponding label capition accordingly
.value = Format(Now, "yyyy"),'<-- set SB value to wanted value. And if this results in an actual change of the preceding value, then it'll trigger its 'Change()' event also that changes corresponding label capition accordingly
End With
除此之外,日期问题(月份界限不同,闰年会造成更多混乱)可能会给您带来更多编码问题:如果是这种情况,您可能需要发布其他帖子...