Graphics

 View Only
  • 1.  need VBscript help for sorting script

    Posted 04-04-2018 02:23

    Hi everyone!

    I need some help with a VBscript for sorting things.

    Here is what I would like help with:

    We are having an election this summer. We have about 100 electoral districts, aka "ridings" and each riding has from 4 to 12ish candidates. I want to allow for 15 possible candidates. Each candidate belongs to a political party. However, we only really care about the 4 largest parties.

    So last time, we got an XML file that provided a) each electoral district b) the candidate names c) candidate party d) number of votes

    What I would like to do is take this data, put it into 15 temp variables, then do a FOR-NEXT loop to put this data into the 4 final sets of fields, only if they belong to one of the 4 desired parties and ignore the other numbers.

    The XML data, the candidates arrive in order of who has the most votes. The problem is if anyone has zeroes, we see the random fringe parties, because the XML in that case arrives sorted in alphabetical order by candidate surname. I would LIKE to learn how to use a database with this, but Access is not cooperating, and it might be super complicated, so I figured I would try this first.

    Here is my Commodore BASIC version :) Thanks!!!

    dim party(15)
    dim partyTemp (15)
    dim partyFinal (4)

    for count = 1 to 15
    put party(count) into partyTemp(count)
    put firstname(count) into firstnameTemp(count)
    put lastname(count) into lastnameTemp(count)
    put votes(count) into votesTemp(count)
    next

    for count = 1 to 15
    let countAgain = 1
    if partyTemp(count) = "LIB" or "PC" or "NDP" or "GRN" then
    put partyTemp(count) into partyFinal(countAgain)
    put firstnameTemp(count) into firstnameFinal(countAgain)
    put lastnameTemp(count) into lastnameFinal(countAgain)
    put votesTemp(count) into votesFinal(countAgain)
    countAgain=countAgain+1
    endif
    next


  • 2.  RE: need VBscript help for sorting script

    Posted 04-05-2018 02:42

    Okay I got as far as this with VBScript but I still need some help to get it working

    dim i as integer
    dim party as xpTextObject
    dim quad as xpBaseObject
    dim mat as xpMaterial

    ' loop over 4 candidates
    for i = 1 to 4
    self.GetObjectByName("Party" & i, party)
    self.GetObjectByName("PartyLogo" & i, quad)

    if engine.GetMaterialByName(party.text, mat) then
    quad.SetMaterial(0, mat)
    end if
    next

    dim n as integer


    dim response as boolean
    dim k as integer
    dim m as integer
    dim firstnamefeed as xpTextObject
    dim lastnamefeed as xpTextObject
    dim partyfeed as xpTextObject
    dim votesfeed as xpTextObject

    for n = 1 to 15
    self.GetObjectByName("FirstNameFeed" & k, firstnamefeed)
    self.GetObjectByName("LastNameFeed" & k, lastnamefeed)
    next

    m=1
    for k = 1 to 15

    if (StrComp(partyfeed,"GRN") = 0) or (StrComp(partyfeed,"LIB") = 0) or (StrComp(partyfeed,"PC") = 0) or (StrComp(partyfeed,"NDP") = 0) then
    self.GetObjectByName("FirstName" & m, firstnamefeed)
    m = m + 1
    end if
    next


    dim firstname as xpTextObject
    dim lastname as xpTextObject
    dim combined as xpTextObject
    dim j as integer

    for j = 1 to 4
    self.GetObjectByName("FirstName" & j, firstname)
    self.GetObjectByName("LastName" & j, lastname)
    self.GetObjectByName("Combined" & j, combined)

    combined.text = firstname.text(0) & ". " & lastname.text
    next

    #XPression


  • 3.  RE: need VBscript help for sorting script

    Posted 04-10-2018 00:26


  • 4.  RE: need VBscript help for sorting script

    Posted 04-17-2018 22:06
    Sorry, I could really look into doing it the way you want, but it would take a little while. If you're using datalinq to get the data, though, some basic SQL should help - something like SELECT * WHERE Party IN ("GRN", "LIB", "PC", "NDP") ORDER BY Votes. Let Xpression do the work for you if it can.

    You then can datalinq directly to your four fields, and all the work is done for you.
    #XPression


  • 5.  RE: need VBscript help for sorting script

    Posted 05-18-2018 23:49
    This would probably work better, I agree, I will look into it to see if I can do it with the XML file.

    What about importing into and out of Access, is that something that would work? Using Access to sort or re-order the data?
    #XPression