0

Web構成ページのデバイスから1分間に4回情報を取得するためのvbaコードがあります。

これは、列Cにxを配置してから、ページのさらに下の列Dにxを配置するまで続ける必要があります。Xがcに対してdの適切な場所にあるかどうかを判断する、呼び出すことができる関数があります。

私がやりたいのは、「OK、スキャンの準備ができました」というボタンを用意することです。次に、最初の値がcに入力されたときに開始し、dの値が入力されたときに停止します。また、VBAスクリプトが実際に実行されているときに値を入力する方法を思い付くのに問題があります。

何かアドバイス?ありがとう。

列をチェックするコードは次のとおりです。

Public Function BackgroundScan(MonitorSpreadsheet As Boolean) As Boolean
Dim LastStart As Integer
Dim LastStop As Integer

intDebug = 1

Select Case MonitorSpreadsheet
    Case True
        'We are actively testing
        If intDebug = 1 Then MsgBox "we ARE monitoring the spreadsheet."
        'Call scanning routine here
        'Get the status TestingInProgress
        LastStart = FindLastStartRow("SVQ")
        LastStop = FindLastStopRow("SVQ")
        If intDebug = 1 Then MsgBox "LastStart " & LastStart
        If intDebug = 1 Then MsgBox "LastStop " & LastStop
        Select Case LastStart
            Case Is < 20
                'We have not started.
                If intDebug = 1 Then MsgBox "We have not started."
                BackgroundScan = False
                'Loop around, and check again
            Case Else
                'ok we have started, now check to see if we have stopped.
                Select Case LastStop
                    Case Is < LastStart
                        '**** We ARE testing!!! ****
                        If intDebug = 1 Then MsgBox "We are testing, and haven't finished."
                        BackgroundScan = True
                    Case LastStart
                        'LastStart and LastStop are the same line, we have started AND finished
                        If intDebug = 1 Then MsgBox "We have started AND finished!"
                        BackgroundScan = False
                        'Loop around, and check again
                    Case Else
                        'We have finished testing, and the test spanned multiple rows
                        BackgroundScan = False
                        If intDebug = 1 Then MsgBox "We started on one line, and finished on another."
                End Select
        End Select
    Case False
        'we are not actively testing
        If intDebug = 1 Then MsgBox "We are NOT monitoring the spreadsheet."
        BackgroundScan = False
    Case Else
        MsgBox "Error: Boolean variable reports: " & MonitorSpreadsheet
        BackgroundScan = False
End Select

終了機能

これがウェブページをスキャンするコードです。

Private Sub CommandButton1_Click()
Dim Some         As String 'can't resist a good pun!
Dim intDelay     As Integer
Dim intMinDelay  As Integer
Dim i            As Integer
Dim s            As Integer
Dim RunStart     As Date
Dim WhichSVBeam As String
Dim lLen As Integer
Dim CurrentSVID As String
Dim CurrentBeamID As String
Dim PreviousSVID As String
Dim PreviousBeamID As String
Dim ColonLocation As Integer
'*******************************************************
'***             Test Continuous Button              ***
'***         Where n is specified in cell A6         ***
'*******************************************************

'grab the number of minutes between checking values
intMinDelay = GetValues("A7")

RunStart = Now

'Do this until the end of time, or the execution is halted.
Do 'uncomment do when we are sure the DoEvents will work as we expect
    WhichSVBeam = Scan_SVBeam(PreviousSVID, PreviousBeamID)

    If InStr(WhichSVBeam, ":") Then
        lLen = Len(WhichSVBeam)
        ColonLocation = InStr(WhichSVBeam, ":")
        'MsgBox WhichSVBeam & ", " & ColonLocation
        CurrentSVID = Left(WhichSVBeam, ColonLocation - 1)
        'MsgBox CurrentSVID
        CurrentBeamID = Right(WhichSVBeam, lLen - ColonLocation)
        'MsgBox CurrentBeamID
    Else
        'no colon, nothing to parse (this shouldn't happen)
        MsgBox "No ':' from Scan_SVBeam"
    End If

    'Call sCheckExecutionTimeGap(RunStart)
    'loop for the number of minutes we specified
    For i = 1 To intMinDelay
        'check every second for events
        For s = 1 To 240
            Call AppSleep(250)
            DoEvents
        Next s
    Next i
Loop

End Sub
4

2 に答える 2

0

疑似コードでは、次の行に沿ったものになります。

start when column c=x
    begin loop
        get data
        check value of column d
        if column d= x exit loop
    next loop iteration
end

それはあなたが望むものですか?

フィリップ

于 2013-03-11T14:18:02.577 に答える
0

一定の間隔で実行され、チェックされるスプレッドシートの値を変更できるようにするコードの例は次のとおりです。

Sub testCell()
Dim r1, r2 As Integer
Dim stopIt As Boolean

r1 = doWeStart
r2 = doWeStop(r1)

Debug.Print "The value of cell C1 is now " & [C1].Value
If r1 = 0 Then Debug.Print "We haven't started yet"
If r1 > 0 And r2 = 0 Then Debug.Print "We start but don't stop"
If r1 > 0 And r2 > 0 Then Debug.Print "We started and stopped"

If [C1].Value Like "stop" Or r1 > 0 And r2 > 0 Then stopIt = True Else stopIt = False

If Not stopIt Then
    Application.OnTime Now + TimeValue("00:00:05"), "testCell"
End If

End Sub
'
Function doWeStart()
    Dim xrow As Integer
    ' save old selection
    Set r = Selection
    xrow = 0

    ' search for "x" in column C
    On Error Resume Next
    xrow = Application.WorksheetFunction.Match("x", [C:C], 0)
    doWeStart = xrow

End Function
'
Function doWeStop(r1)
    Dim xrowd As Integer
    xrowd = 0

    ' search for "x" in column D, starting at row r1
    On Error Resume Next
    xrowd = Application.WorksheetFunction.Match("x", Range("D" & r1, "D1048576"), 0)
    If xrowd > 0 Then
        doWeStop = xrowd + r1 - 1
    Else
        doWeStop = 0
    End If

End Function

これは 5 秒ごとに実行され、列 C の最初の「x」と列 D の最初の「x」が C で見つかったものの下にあるのを探します。デバッグ ウィンドウ - そこにコードを配置できます。C1 に「stop」と入力するか、C と D の両方に「x」があると停止します。

于 2013-03-11T19:20:30.843 に答える