簡體   English   中英

即使用戶在Visual Basic中單擊一次,垂直滾動條更改事件也會觸發兩次或多次

[英]Vertical scrollbar change event gets fired twice or more than once even though user click on it once in visual basic

我正在使用Visual Basic V6.0應用程序。

我有一個具有垂直滾動條的表單,可以更改日歷和標簽中的日期。

我已附上表格的屏幕截圖。 當用戶僅在突出顯示的垂直條箭頭上單擊一次時-更改事件被觸發多次。

即使我們只單擊一次,我也無法弄清楚為什么會多次觸發。

我已經嘗試過在調試中運行應用程序-我看不到任何問題。

另外,我嘗試將日志味精-也說-事件觸發了兩次。 如果第二次調用,還嘗試將flag變量退出sub。

這並非每次都發生,但是是的,在大多數情況下都是如此。

任何建議表示贊賞。

以最誠摯的問候

維沙爾·帕特爾(Vishal Patel)

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

在此處輸入圖片說明

If set_new_month Then
    Call SetFormTagVar(Me, "NEW_MONTH", YES_FLAG)
    VScroll2.Value = newmonth
End If

您可以在_Change事件中設置滾動條的值。 這將導致另一個_Change觸發。 執行此操作時,您會得到描述的情況。 通常的解決方案是用一個布爾值將更改括起來,該布爾值指示已在進行更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM