English 中文(简体)
Why does this LotusScript halt during a loop?
原标题:

I am trying to write a LotusScript to control a motor. The script I have for reading the bits seem to work fine, but I wish to add a stop button. I have all the commands for making the device stop, but the trouble I m having is that whenever LotusScript is running through a loop, I cannot click on any of the other buttons.

Does anyone know a way around this???

The scripts I am using are below.

Thank-you kindly.

Andy Barlow

Sub readpositionsub Dim send_string As String
Dim readString As String Dim tempString As String readString = ""

REM Sets the "movement" cell to 6 (the movement int)
[b1].contents = "6"
Do While [b1].contents <> "7"

    readString = ""
    statusBitString = ""

    REM READ STATUS ===!!!===
    REM Open the handle to the motor
    handle =    init_RS232(19200)
    REM #1$ reads the status from the controller.
    send_string = "#1$"+Chr$(13)
    REM Ask the controller to store the results in bits
    resultStatus=write_RS232 (handle,send_string)

    REM Read Status by looping through all of the bits
    For n=0 To 8
        tempString = "*1234567"  
        sendReadCommand = read_RS232(handle,tempString)
        If Mid(tempString,1,1) = Chr$(13) Then
            Exit For
        Else
            statusBitString = statusBitString  + Mid(tempString,1,1)
        End If

    Next
    [b1].contents = Mid(statusBitString,7, 1)
    close_RS232(handle)
    REM End Read Status



    REM READ POSITION ===!!!===
    REM Open the handle to the motor
    handle =    init_RS232(19200)
    send_string = "#1C"+Chr$(13)
    t=write_RS232 (handle,send_string)  
    REM Reading Position
    For n=0 To 20
        tempString = "*1234567"  
        r = read_RS232(handle,tempString)
        If Mid(tempString,1,1) = Chr$(13) Then
            Exit For
        Else
            readString = readString + Mid(tempString,1,1)

        End If

    Next
    REM End Read Position
    [a1].contents=Mid(readString, 4)
    close_RS232(handle)

Loop

End Sub

And the stop button that should work should be... Object btnStop

Sub Click(Source As Buttoncontrol) REM initialise handle = init_RS232(19200)

REM Create the string for starting the motor
send_string = "#1S"+Chr$(13)

REM Send the string for starting the motor
resultStartMotor=write_RS232 (handle,send_string)

REM Close the spin handle
close_RS232(handle)

End Sub

最佳回答

You re not running your Lotusscript in a threaded environment, so how do you expect the code on a button to stop the code already running?

问题回答

If you want to be able to cancel a loop you need to play with the timer object. Basically you start a time that executes one iteration of your loop. At the beginning you look for a changed field value or an ini variable to cancel the timer if set. Now you can use your button to set that variable. The loop will run much slower than without a timer (after all it has a wait interval you set)





相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...

热门标签