Announcement

Collapse
No announcement yet.

Scripting Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scripting Help

    Hello All,

    I am curious as to how to convert the script below to work with a tcpSend command (i.e.: get the xml from a website). Right now it works with reading an xml from a file location. I like the way it parses information since i can tell it which line i want specifically. I am not sure of the syntax though. I can get the information to load but not sure as to the parsing of the xml from a file location differs from an tcpSend.

    Any help is greatly appreciated.

    'Script below
    dim current_line as integer = 0

    dim lines as array[string]

    dim my_content as string
    dim search_string as string


    dim DRIVER as container = scene.findcontainer("DRIVER")


    sub OnInitParameters()
    RegisterFileSelector("my_file", "Select Textfile", "D:/VIZ ARCHIVES 2019/myARCHIVES_92619/Robert", "NewsTicker_Elections.xml", "*.xml")
    RegisterPushButton("GO", " Go ", 1)
    RegisterParameterContainer("race_title", "Race Title")
    end sub


    sub OnExecAction (buttonId As Integer)
    if buttonId = 1 then
    dim new_file as string
    new_file = GetParameterString("my_file")
    read_file(new_file)
    write_Text()
    end if
    end sub

    sub read_file(input as string)
    system.LoadTextFile(input, my_content)
    my_content.split("\n\r",lines)
    'println "There are " & lines.ubound & " lines in this textfile"
    end sub

    sub write_Text()
    for i=lines.lbound to lines.ubound
    if lines[i].Find(DRIVER.geometry.text)>0 then
    'println lines[i]

    ' 'Race Title and Subtitle
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET RaceName1 =" & returnFieldData(lines[i+0]) & ";")
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET RaceName2 =" & returnFieldData(lines[i+1]) & ";")

    ' 'Precints Reporting
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Precincts_Reporting =" & returnFieldData(lines[i+2]) & ";")

    ' 'Candidate 1 First and Last Name
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_First_Name =" & returnFieldData(lines[i+3]) & ";")
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_Last_Name =" & returnFieldData(lines[i+4]) & ";")

    ' 'Candidate 1 Vote Total
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_Vote_Total =" & returnFieldData(lines[i+6]) & ";")

    ' 'Candidate 1 Pct Total
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_Vote_Pct =" & returnFieldData(lines[i+7]) & ";")

    ' 'Candidate 1 Winner Check
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET WINNER01CHECK =" & returnFieldData(lines[i+5]) & ";")

    ' 'Candidate 1 Party
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_Icon =" & returnFieldData(lines[i+8]) & ";")

    ' 'Candidate 1 Pic
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand1_Pic =" & returnFieldData(lines[i+9]) & ";")


    ' 'Candidate 2 First and Last Name
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_First_Name =" & returnFieldData(lines[i+11]) & ";")
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_Last_Name =" & returnFieldData(lines[i+12]) & ";")

    ' 'Candidate 2 Vote Total
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_Vote_Total =" & returnFieldData(lines[i+14]) & ";")

    ' 'Candidate 2 Pct Total
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_Vote_Pct =" & returnFieldData(lines[i+15]) & ";")

    ' 'Candidate 2 Winner Check
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET WINNER02CHECK =" & returnFieldData(lines[i+13]) & ";")

    ' 'Candidate 2 Party
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_Icon =" & returnFieldData(lines[i+16]) & ";")

    ' 'Candidate 2 Pic
    SendCommand("MAIN_SCENE*FUNCTION*DataPool*Data SET Cand2_Pic =" & returnFieldData(lines[i+17]) & ";")

    Exit for
    end if
    Next
    end sub


    function returnFieldData(answer As String) as String
    if answer.FindFirstOf(">")<=answer.length then

    answer = answer.GetSubString(answer.FindFirstOf(">")+1,answer.length)

    answer = answer.GetSubString(0,answer.FindFirstOf("<"))
    end if
    returnFieldData=answer
    end function


    'sub next()
    ' current_line = current_line +1
    ' if current_line>lines.ubound then
    ' current_line = 0
    ' end if
    'end sub



    'function ParseValue(file_lines as array[string], search_tag as String) as array[string]
    ' dim return_array as array[string]
    ' dim tag_value as string
    ' for i=0 to file_lines.ubound
    ' if file_lines[i].find(search_tag)>0 then
    '
    ' tag_value = file_lines[i]
    '
    ' tag_value = tag_value.GetSubString(tag_value.FindFirstOf(">")+1,tag_value.Length)
    ' tag_value = tag_value.GetSubString(0,tag_value.FindFirstOf("<"))
    '
    ' return_array.push(tag_value)
    ' lines[i+1]
    ' end if
    ' next
    ' ParseValue=return_array
    'end function


  • #2
    I believe i figured out the scripting for this one. After a few days off it helped to look at it again. Brains need rest.!!!

    Comment

    Working...
    X