
No.2ベストアンサー
- 回答日時:
画面を持たないなら、時間を独自で計測しっちゃった方が、シンプルのような気もします。
Module Module1
Private Declare Function timeGetTime Lib "winmm.dll" Alias "timeGetTime" () As Integer
Private Const LIMIT_TIME As Integer = 5000
Sub Main()
Dim intTime As Integer = timeGetTime
Do
Application.DoEvents()
If (timeGetTime - intTime > LIMIT_TIME) Then
MsgBox("タイムアウト")
Exit Sub
End If
'応答電文受信確認処理コール
'if 正常受信 then
' exit do
'end if
Loop
End Sub
End Module
クラスでタイマを派生させるサンプルも置いておきます。
※Module1.vb
Module Module1
Private Const LIMIT_TIME As Integer = 5000
Sub Main()
Dim objClass1 As New Class1()
objClass1.TimerStart(LIMIT_TIME)
Do
Application.DoEvents()
If Not objClass1.Status = Class1.TimerStatus.timRun Then
MsgBox("タイムアウト")
GoTo PGMEND
End If
'応答電文受信確認処理コール
'if 正常受信 then
' exit do
'end if
Loop
PGMEND:
objClass1 = Nothing
End Sub
End Module
※Class1.vb
Public Class Class1
Enum TimerStatus
timFree
timRun
timEnd
End Enum
Private stsTimer As TimerStatus
WithEvents objTimer As System.Timers.Timer
Protected Overrides Sub Finalize()
If Not (objTimer Is Nothing) Then
objTimer.Enabled = False
End If
objTimer = Nothing
MyBase.Finalize()
End Sub
Public Sub New()
stsTimer = TimerStatus.timFree
End Sub
Public ReadOnly Property Status() As TimerStatus
Get
Return stsTimer
End Get
End Property
Public Sub TimerStart(ByVal inInterval As Integer)
objTimer = New System.Timers.Timer()
With objTimer
.Interval = inInterval
.Enabled = True
End With
stsTimer = TimerStatus.timRun
End Sub
Private Sub objTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles objTimer.Elapsed
Debug.WriteLine("タイマイベント発生")
objTimer.Enabled = False
stsTimer = TimerStatus.timEnd
End Sub
End Class
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Outlookの「受信日時」「件名」...
-
Windows Mobile6.1 メール受信...
-
TCP/IP のパケットの分断と結合...
-
VC++メッセージの送受信につい...
-
シリアル通信時のデータ受信方法
-
ASP.NET C#でPOST受信
-
recv関数の戻り値について
-
パソコンに詳しい方教えて下さ...
-
バッチファイルでディレクトリ...
-
ARCserveの復元方法
-
Windows上のファイル操作の履歴...
-
別のフォルダにファイルを移動...
-
隠しファイルとZip圧縮について
-
Zipファイルをエクセルに指定変...
-
指定ファイルをFTPで自動アップ...
-
Windows 7 標準のZip解凍が出来...
-
ipadで社内ネットワークに接続
-
java.lang.NumberFormatExcepti...
-
グローバルIPアドレスを取得し...
-
Lhaplusが発したと、みられるエ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Outlookの「受信日時」「件名」...
-
TCP/IP のパケットの分断と結合...
-
Outlookの「受信日時」「送信者...
-
UDP受信時の通信異常検知について
-
CRC-CCITTに関しての仕様とサン...
-
ASP.NET C#でPOST受信
-
recv関数の戻り値について
-
VB2010で、シリアル通信の方法...
-
HPのメールフォームについて
-
アンテナってあるでしょ?あれC...
-
シリアル通信時のデータ受信方法
-
赤外線通信
-
C#にてCTI。RS232Cの受信と送信...
-
受信処理の終了条件
-
PICを用いた赤外線通信
-
DHCPOFFERの受信について
-
VB2005でTCP/IPソケット通信で...
-
.NetのTimerについて
-
文字化け
-
winsockを使ったTCP及びUDP通信...
おすすめ情報