Screens Navigation using Combo Box

can anyone explain how to navigate screens using Combo box? i am using the following script (Screen Scripts) to navigate between screens :

'This procedure is executed continuously while this screen is open.
Sub Screen_WhileOpen()

If $SCREENPOS = 0 Then
$Open("FIRST SCREEN")
Else If $SCREENPOS = 1 Then
$Open("SECOND SCREEN")
End If
End If

End Sub

I have assigned a tag SCREENPOS to the combo box (in position).

The problem i am facing is when i select from the list of static lables, the script is executed continuously and after that, i am not able to select from the combo box.

any suggestions are highly requested.
  • Try adding the following to your Screen Script.

    [code]If DateDiff("s", $StrGetElement($ScreenPos->TimeStamp, ".", 1), Now) < 1 Then If $SCREENPOS = 0 Then $Open("FIRST SCREEN") Else If $SCREENPOS = 1 Then $Open("SECOND SCREEN") End If End If End If [/code]

    This way it will only run once when the tag changes.
  • IT WORKS PERFECT!!!!!! can you please explain the script that you have added?
  • If you have room, you could also just put a button next to your drop-down with the open script in your button command.
  • All I added was the DateDiff line. The DateDiff command is a VBScript command that checks the difference between two dates.

    DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])

    "Interval" is the interval you want to use to compare the 2 dates.
    "Date 1" is the first date to compare.
    "Date 2" is the second date to compare.

    DateDiff only works with standard date format, it does not accept the milliseconds field, so that is the reason for $StrGetElement. The timestamp of any tag has the format mm/dd/yyyy hh:mm:ss.ms. The $strGetElement command is an Indusoft command that gets a specific element from a string using a delimiter.

    After it gets the time stamp and takes the first element (mm/dd/yyyy hh:mm:ss), it compares that time to the current time (Now: Built in VBScript function for current date and time on system). I am using an interval of "s" (seconds). Every time the tag ScreenPos changes, the time stamp is updated. If the comparison between the timestamp and the current time is less than 1, the script runs allowing the screen change. The reason it most likely did not work previously, is because it was continuously running the script, not it will only run when the tag changes.

    For more inforation on the DateDiff command see the W3Schools Website (http://www.w3schools.com/vbscript/func_datediff.asp)
    For more information on the StrGetElement command, go the help in Indusoft. Appendix: Built-in Scripting Language > String Functions