Events 即使用户在visual basic中单击垂直滚动条更改事件一次,该事件仍会被激发两次或多次

Events 即使用户在visual basic中单击垂直滚动条更改事件一次,该事件仍会被激发两次或多次,events,vb6,vertical-scrolling,vertical-scroll,Events,Vb6,Vertical Scrolling,Vertical Scroll,我正在开发VisualBasicV6.0应用程序 我有一个表格,有垂直的滚动条来改变日历和标签上的日期 我附上了表格的截图。当用户只在高亮显示的竖条箭头上单击一次时,会多次触发更改事件 我不明白为什么我们只点击了一次,但却多次开火 我已经尝试在debug more中运行应用程序-我没有看到任何问题 此外,我还尝试将log msg(也表示)事件触发两次。 还尝试在第二次调用时将标志变量放入退出子对象 这不是每次都会发生,但大多数时候都会发生 如有任何建议,我们将不胜感激 致以最热烈的问候 维沙尔帕

我正在开发VisualBasicV6.0应用程序

我有一个表格,有垂直的滚动条来改变日历和标签上的日期

我附上了表格的截图。当用户只在高亮显示的竖条箭头上单击一次时,会多次触发更改事件

我不明白为什么我们只点击了一次,但却多次开火

我已经尝试在debug more中运行应用程序-我没有看到任何问题

此外,我还尝试将log msg(也表示)事件触发两次。 还尝试在第二次调用时将标志变量放入退出子对象

这不是每次都会发生,但大多数时候都会发生

如有任何建议,我们将不胜感激

致以最热烈的问候

维沙尔帕特尔

Private Sub Vscroll2_Change()
Dim newmonth As Integer
Dim pass_date As String
Dim curr_dtime As String
Dim yeard As Variant
Dim chg_date As String
Dim set_new_month As Integer


newmonth = VScroll2.Value
curr_dtime = GetFormTagVar(Me, "CURR_DTIME")
Call SetFormTagVar(Me, "OLD_DTIME", curr_dtime)
yeard = Year(curr_dtime)

'set calendar refresh on if we have changed year or month
If (yeard <> Year(curr_dtime)) Or (Month(CVDate(curr_dtime)) <> newmonth) Then
   SetCalRefresh (True)
End If

If Month(CVDate(curr_dtime)) <> newmonth Then
   set_new_month = False
   If newmonth = 13 Then
      newmonth = 1
      set_new_month = True
      yeard = Year(curr_dtime)
      yeard = yeard + 1
   End If

   If newmonth = 0 Then
      newmonth = 12
      set_new_month = True
      yeard = Year(curr_dtime)
      yeard = yeard - 1
   End If

   '* figure out the new date
   If newmonth < 10 Then
       pass_date = yeard & "0" & newmonth & "01" & "0000"
   Else
       pass_date = yeard & newmonth & "01" & "0000"
   End If
   pass_date = DatePaint(pass_date, True)

   Call SetFormTagVar(Me, "CURR_DTIME", pass_date)
   Call SetFormTagVar(Me, "NEW_DTIME", "1")
   lbldate.Caption = DatePaint(DateParseFnc(pass_date), True)
   chg_date = GetFormTagVar(Me, "CURR_DTIME")
   If set_new_month Then
    Call SetFormTagVar(Me, "NEW_MONTH", YES_FLAG)
    VScroll2.Value = newmonth
   End If
   Call check_calendar(Me)
   Call SetupNotesMenuItems
End If

'We're done
End Sub
Private Sub Vscroll2_Change()
将newmonth设置为整数
Dim pass_date作为字符串
Dim curr\u dtime作为字符串
作为变异体
Dim chg_日期作为字符串
Dim set_new_month为整数
newmonth=VScroll2.Value
curr\u dtime=GetFormTagVar(Me,“curr\u dtime”)
调用SetFormTagVar(Me,“OLD\u DTIME”,curr\u DTIME)
yeard=年(当前时间)
'如果我们更改了年份或月份,则设置日历刷新
如果是(yeard Year(curr_dtime))或(Month(CVDate(curr_dtime))newmonth),则
SetCalRefresh(真)
如果结束
如果月份(CVDate(curr\u dtime))为新月份,则
设置新月份=假
如果newmonth=13,则
newmonth=1
设置新月份=真
yeard=年(当前时间)
yeard=yeard+1
如果结束
如果newmonth=0,则
新月份=12
设置新月份=真
yeard=年(当前时间)
yeard=yeard-1
如果结束
’*算出新的日期
如果newmonth<10,则
通过日期=年月日&“0”和月日&“01”和“0000”
其他的
通过日期=年月日和月日以及“01”和“0000”
如果结束
通过日期=日期绘制(通过日期,真)
调用SetFormTagVar(Me,“当前时间”,传递日期)
调用SetFormTagVar(Me,“新时间”,“1”)
lbldate.Caption=DatePaint(DateParseFnc(传递日期),True)
chg_date=GetFormTagVar(Me,“CURR_DTIME”)
如果设置为新月份,则
调用SetFormTagVar(Me,“新月份”,是标志)
VScroll2.Value=newmonth
如果结束
呼叫检查日历(Me)
调用setupnotesnumitems
如果结束
“我们完了
端接头


在这里,您可以从
\u Change
事件中设置滚动条的值。这会导致另一个
\u Change
触发。当你这样做的时候,你会得到你描述的情况。通常的解决方案是用一个布尔值包围更改,表示更改已经发生。

很抱歉响应太晚。谢谢@Jim Mack。我会试试的。嗨@Jim Mack,我已经试着按照你的建议放下面的代码进行测试
如果we=True,则在到达VScroll2之前we=False退出Sub-End If
。Value=newmonth我已放置we=True,并且我看到,只有当鼠标悬停在滚动条上时,才会触发更改事件。单击一次并将鼠标移动到其他控件或窗体区域不会导致滚动条出现任何问题/调用更改事件。添加到注释2。这个解决方案无助于解决问题,我试图删除将scrollbar的值更改为newmonth的部分,但仍然是一样的issue@VishalPatel-您的布尔值在过程中是否声明为静态?如果您将陷阱放置在Sub的最开始处,则在仍然处于活动状态时无法进入陷阱<代码>静态bHere为布尔值//如果bHere则退出sub//bHere=true/。。。。主要内容..../bHere=false试试看,告诉我们你看到了什么。
If set_new_month Then
    Call SetFormTagVar(Me, "NEW_MONTH", YES_FLAG)
    VScroll2.Value = newmonth
End If