Graphics

 View Only
  • 1.  VBScript test for smallest time value

    Posted 10-24-2013 20:10
    Hey all,

    I'm stuck on some code (mostly bc I am a VB script newbie)

    I am trying to test 2 values that are being pulled into a scene from a datasource formatted as n:ss

    I want to test for the smaller of the two values and then use it in a text object.

    I've tried a couple ideas but I feel I am limited by my understanding of the syntax. I think I need to convert the time values to numeric values so I can do a math calc on them.

    this is what I'm working with and I know there are errors. It is applied to the text object 4on4 Clock

    dim PPhomeClock as xpTextObject

    dim PPvisClock as xpTextObject

    dim FourClock as xpTextObject

    dim x

    dim y

    'this is where I lack knowledge

    x = PPhomeClock

    y = PPvisClock

    Scene.GetObjectByName("PP Clock Home",PPhomeClock)

    Scene.GetObjectByName("PP Clock Visitor",PPvisClock)

    Scene.GetObjectByName("4on4 Clock",FourClock)

    'I know something is missing here too

    if x > y then

    text = y

    else

    text = x

    end if


  • 2.  RE: VBScript test for smallest time value

    Posted 10-24-2013 20:49
    Here you go Chris..



    dim PPhomeClock as xpTextObject

    dim PPvisClock as xpTextObject

    dim FourClock as xpTextObject

    dim homevalue as Integer

    dim awayvalue as Integer

    dim values(2) as String

    dim mins as Integer

    dim secs as Integer

    Self.GetObjectByName("PP Clock Home",PPhomeClock)

    Self.GetObjectByName("PP Clock Visitor",PPvisClock)

    Self.GetObjectByName("4on4 Clock",FourClock)

    'HOME TEAM

    ' Extract the minutes and seconds for the home penalty

    values = Split(PPHomeClock.Text,":",2)

    ' Convert the minutes and seconds from strings to ints

    mins = CInt(values(0))

    secs = CInt(values(1))

    ' Convert the mins and secs to a total number of seconds

    homevalue = mins*60 + secs

    ' AWAY TEAM

    ' Extract the minutes and seconds for the away penalty

    values = Split(PPvisClock.Text,":",2)

    mins = CInt(values(0))

    secs = CInt(values(1))

    awayvalue = mins*60 + secs

    ' See who has the smaller value

    if homevalue < awayvalue then

    FourClock.Text = PPhomeClock.Text

    else

    FourClock.Text = PPvisClock.Text

    end if



    #XPression


  • 3.  RE: VBScript test for smallest time value

    Posted 10-24-2013 20:51
    Note that I had that script in the OnRender.. The syntax might be slightly different if you put it in OnSetText.

    I think the only change would be Self.GetObjectByName would become Scene.GetObjectByName

    #XPression


  • 4.  RE: VBScript test for smallest time value

    Posted 10-24-2013 21:12
    That works fantastic Brian. Thanks so much. I was sort of on the right track.

    I did find one problem though. I think I need to add an exception or rule of some kind when the value of the mins is blank to force it to use a zero. Ie. the time field coming in is :50. the script only works if the field is 0:50

    Know what I mean?

    #XPression


  • 5.  RE: VBScript test for smallest time value

    Posted 10-24-2013 21:28
    nevermind Brian. I figured it out.

    Thanks again!

    #XPression


  • 6.  RE: VBScript test for smallest time value

    Posted 10-25-2013 01:10
    not sure how you solved it, but off the top of my head I'd probably do something like:

    if(Len(values(0)) > 0 then

    mins = CInt(values(0))

    else

    mins = 0

    end if

    #XPression