Hello.
I have a script that sorts the result on the highest number first.
It works fine.
Then I use the same script, but the with different types of numbers, not with a comma but a dot.
Is it possible to sort them also?
Hello.
I have a script that sorts the result on the highest number first.
It works fine.
OnSetText in script event on the datalinqed text i’ve did this:
Text = Replace(Text, “.”, “,”)
It replaces the dot, but the sorting is still not right.
Looks like it is sorting alphabetically instead of numerically. You can convert the strings to numbers before sorting. Also, as you have figured out, if your culture uses ‘,’ instead of ‘.’ for decimals you have to either replace the ‘.’ with ‘,’ or use a different culture. Demo:
’ Create test array
Dim a As String() = “7.6,6.2,5.8,4.8,2.8,2.4,2.3,28.4,1.4,16.5,11.3,9.3,0.7,0.4,0.1,0”.Split(“,”)
'Create new array with doubles
Dim i As Integer
Dim b As Double() = New Double(a.Length){}
For i = 0 To a.Length-1
b(i) = Double.Parse(a(i).Replace(“.”, “,”))
Next
’ Sort reverse
Array.Sort(b)
Array.Reverse(b)
’ Test results
For Each s As String In b
Engine.DebugMessage(s, 0)
Next
Too bad we can’t use Linq (as far as I know). It would be simpler:
Dim b = a.OrderBy(Function(x) Double.Parse(x.Replace(“.”, “,”))).Reverse()
It won’t debug message.
Don’t see any message, where would I se it?
How about placing the results at the right position?
Right now I use Vusual Logic to sort and place them.
In the XPression debug monitor, it opens automatically in systray when you have messaged,
Looks like this;![]()
Or it flashes if there is warning.
If you open it up it will have messages in it.
In the first message you said scripting but now you are asking about Visual Logic. Which is it? What is the data source? Maybe you can sort it in the DataLinq Server if using SQL.
Also, for the debug monitor, check that it is enabled in the Preferences under Advanced-Enable debug monitor for scripting.
The datasource is xml/json feed.
At first I made a big Visual Logic to sort the first.
I tryed to use the same Visual Logic to sort the next one, but does’nt work as I assumed.
So therefor I tryed to replace “.” with “,” in a simple script.
I’ve tried this, but doesn’t seem to work?
Dim mandater(15) As xpTextObject
For i As Integer = 0 To 15
self.GetObjectByName("Mandater " + CStr(i + 1), mandater(i))
Next
’ Create array
Dim a As String() = “mandater(1),mandater(2),mandater(3),mandater(4),mandater(5)”.Split(“,”)
When I use the piece of code you wrote John, then it stores the numbers.
I tryed to make my own piece, like the above, to store the text field “Mandater 1” to “Mandater 16”
Then I tryed to put that in an array, like you did, but not sure if it works, I would not print anything in the debug message then.
Hey Tue,
You can check if there is anything in the array with something like the length parameter.
engine.debugmessage(a.length,0)
I’m a little confused right now about what you are trying to do, but here’s what I think you want…
The biggest question is about the data source. I think it is a JSON file. As far as I know you can’t sort JSON data through the DataLinq Server (anyone?). So you will need to create 15 hidden text objects and assign each text object one field in the data. Then create 15 visible text objects to display the data.
’ Load the JSON data from hidden texts to array
’ The hidden texts have the DataLinq that ties each one to one entry in the JSON array
Dim data(15) As Double
For i As Integer = 1 to 15
Dim txt As xpTextObject
Self.GetObjectByName(“hiddenText” & i, txt)
data(i - 1) = CDbl(txt.Text.Replace(“.”, “,”))
Next
’ Now we have the data as numbers we can sort
Array.Sort(data)
Array.Reverse(data)
’ Last step, put the sorted data into the visible text objects
For i As Integer = 1 to 15
Dim txt As xpTextObject
Self.GetObjectByName(“mandater” & i, txt)
txt.Text = data(i - 1).ToString(“N2”)
Next
Correct?
Basicly, what I want, is to readout data from the json link I have.
I get this for each party:
logo - percent - +/- percent
These are now all my objects:
I have tried as you describe, IT works, when I put it on the OnRender in scrpt!
But I also need to move the logo and the +/- with the percent…