Timer の Interval プロパティの動作が変更されている
Visual Basic 6.0 では、Interval プロパティを 0 に設定することにより、Timer コントロールを無効にすることができました。Visual Basic 2008 では、Interval プロパティの下限は 1 です。0 に設定すると、実行時例外が発生します。Visual Basic 2008 の Timer コンポーネントでは、Enabled プロパティを使用して、このコントロールを無効にするか有効にするかを決定できます。
Timer コントロールの変更点を次のコードに示します。
' Visual Basic 6.0
Public Function TimerOn(Interval As Integer)
If Interval > 0 Then
Timer1.Interval = Interval ' Enables the timer.
Else
Timer1.Interval = 0 ' Disables the timer.
End If
End Function
' After upgrade to Visual Basic 2008
Public Function TimerOn(ByRef Interval As Short) As Object
If Interval > 0 Then
' UPGRADE_WARNING: Timer Property Form1.Timer1.Interval has a new
' behavior.
Timer1.Interval = Interval ' Enables the timer.
Else
' UPGRADE_WARNING: Timer property Timer1.Interval cannot have
' a value of 0.
Timer1.Interval = 0 ' Disables the timer.
End If
End Function
次の操作
Interval プロパティを 0 に設定しているコードを探します。
そのコードを、Enabled プロパティに false を設定するコードで置き換えます。
Interval プロパティを 0 より大きい値に設定しているコードを探します。
Enabled プロパティに true を設定するコード行を追加します。
メモ : Enabled プロパティは、間隔を最初に設定するときにだけ設定する必要があります。Timer は、Enabled プロパティを明示的に false に設定するまで有効です。
' Modified Visual Basic 2008 code Public Function TimerOn(ByRef Interval As Short) As Object If Interval > 0 Then Timer1.Enabled = True ' Enables the timer. Else Timer1.Enabled = False ' Disables the timer. End If End Function