Graphics

 View Only
  • 1.  Event Script Conditional Logic

    Posted 10-28-2019 15:30

    Hi. I do not come from a programming background, and I'm finding VBA very difficult to write.

    I have created some code to "count" the number of text objects that aren't empty and write the result to another text object. My code always writes out 3. What am I doing wrong here?

    If Line2.Text = "" and Line3.Text = "" then
    NumLines.Text = "1"
    elseif Line3.Text = "" then
    NumLines.Text = "2"
    else
    NumLines.Text = "3"
    End If

    Also, I haven't been able to Dim Integers and perform simple math on them. If someone can show me how that works, then I might be able to accomplish this more easily. Any advice is greatly appreciated! Please help!



  • 2.  RE: Event Script Conditional Logic

    Posted 10-28-2019 18:57
     
    If you had much more than 3 then you want to do this in a loop so you're not duplicating code, but in this case I think it would be cleaner to evaluate each one separately. Just make a counter and increment it for each field that is not empty. Something like this:
    dim notEmptyCount as integer = 0

    if Line1.text <> "" then
      notEmptyCount = notEmptyCount + 1
    end if

    if Line2.text <> "" then
      notEmptyCount = notEmptyCount + 1
    end if

    if Line3.text <> "" then
      notEmptyCount = notEmptyCount + 1
    end if

    NumLines.text = cstr(notEmptyCount)

    #XPression


  • 3.  RE: Event Script Conditional Logic

    Posted 10-28-2019 19:15

    Also, make sure your "empty" lines are actually empty, for example if they contain only a space or tab character, they may look empty in your preview, but won't be considered empty by the script. You can use the trim function to clean them up to be safe.

    if trim(Line1.text) <> "" then

    ...

    #XPression


  • 4.  RE: Event Script Conditional Logic

    Posted 10-28-2019 19:57

    Thank you for the help! I can't seem to get this to work, although now I think I can use integers properly.

    Could using a datalinq to populate these text boxes be causing a problem?

    I double checked that Visual Logic reads the lines as empty, but I'd like to script this in VBA.


    #XPression


  • 5.  RE: Event Script Conditional Logic

    Posted 10-28-2019 20:11

    Yeah, depending on where your script is running, it could be that DataLinq is doing something to the text fields. I would verify the current contents of the text fields when the script runs using debugMonitor. It sounds like somehow your text fields are becoming non-empty when the script runs. Do you have "Return Empty On Failure" checked for the DataLinq properties of those fields? Do you have any other scripts running on objects that would be writing into those fields (like in an OnSetText script or something)? Are the fields empty in Layout?

    engine.debugMessage("Line 1 = |" + Line1.text + "|", 0)

    engine.debugMessage("Line 2 = |" + Line2.text + "|", 0)

    engine.debugMessage("Line 3 = |" + Line3.text + "|", 0)

    The reason I put the pipe characters in is so you can see if there's any whitespace in the text field.


    #XPression


  • 6.  RE: Event Script Conditional Logic

    Posted 10-29-2019 12:52

    Again, thank you for your help.

    I attached this screenshot because you seem to be onto something. Interestingly, it now seems to be counting lines correctly, but the script is seeing the same graphic in the sequencer despite displaying correctly in preview... 

    The database is manually filled. This is my only script running at the moment. I started a brand new project to reduce lag I was encountering with visual logic.

    Any thoughts?

    Edit: I just noticed that the entry it's reading over and over is what I currently have set as the datakey value in my scene.


    #XPression


  • 7.  RE: Event Script Conditional Logic

    Posted 10-29-2019 23:16

    Where is your script running? If it's in OnPreviewRender, you'll want to duplicate it to OnBeforeOnline to see it live.


    #XPression


  • 8.  RE: Event Script Conditional Logic

    Posted 10-30-2019 12:45

    I had the script in OnPrepare.

    Moving it to the two events you mention fixed it.

    Thanks so much!


    #XPression


  • 9.  RE: Event Script Conditional Logic

    Posted 10-30-2019 13:34

    To help explain this..  OnPrepare runs before the scene has queried the datalinq server for the current values.  OnPrepare is where you would have any scripting that needs to modify the row/column/table values of the fields that are querying datalinq.  

    OnBeforeOnline and OnOnline both run after the datalinq server has returned the data that was requested during the scene prepare phase.

     


    #XPression