Results 1 to 35 of 35

Thread: [vb.net] Sorting decimal in ascending order in richtextbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    [vb.net] Sorting decimal in ascending order in richtextbox

    I need to sort in ascending numbers the lines of a richtextbox, which got decimals in the follow format:

    0.00001302 - 283000
    0.00001315 - 295800
    0.00001328 - 292600
    0.00001333 - 7700
    0.00001341 - 308500
    I'm trying to sort the lines to obtain an output like:

    0.00001341 - 308500
    0.00001333 - 7700
    0.00001328 - 292600
    0.00001315 - 295800
    0.00001302 - 283000
    Ive tried

    Code:
    RichTextBox1.Lines = RichTextBox1.Lines.OrderBy(Function(x) Decimal.Parse(x)).ToArray
    and


    Code:
    Dim lines() As String = RichTextBox1.Lines
            Dim value = lines.Select(Function(x) Convert.ToInt32(x)).OrderByDescending(Function(x) x)
            RichTextBox1.Text = String.Join(Environment.NewLine, value)
    but for both I get the same error:

    System.FormatException: '"Input string is not in correct format"'
    Clearly the sorting doesn't like the format of the lines, so how can I make it to do not care about the format and just caring about the decimals? Thanks
    Last edited by matty95srk; Feb 14th, 2022 at 07:28 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,685

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Try this. Note blank lines will cause an error...

    Code:
    RichTextBox1.Lines = RichTextBox1.Lines.OrderByDescending(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Hey Paul, unfortunately it gives me the same error
    System.FormatException: '"Input string is not in correct format"'
    no blanklines

  4. #4
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,462

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    You might like to try...
    Code:
    RichTextBox1.Text &= vbNewLine, value.ToString

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    What it has to do with the question.. ?

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    Hey Paul, unfortunately it gives me the same error


    no blanklines
    The blank lines cause the error. You have to filter those out:-
    Code:
            RichTextBox1.Lines = RichTextBox1.Lines.
                Where(Function(x) Not String.IsNullOrEmpty(x)).
                OrderByDescending(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    If you want to preserve the space between the lines then you can do this:-
    Code:
            RichTextBox1.Lines = (From line In RichTextBox1.Lines
                                  Where Not String.IsNullOrEmpty(line)
                                  Order By Decimal.Parse(line.Split(" "c)(0)) Descending
                                  Select String.Concat(line, Environment.NewLine)).ToArray
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by Niya View Post
    The blank lines cause the error. You have to filter those out:-
    Code:
            RichTextBox1.Lines = RichTextBox1.Lines.
                Where(Function(x) Not String.IsNullOrEmpty(x)).
                OrderByDescending(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray

    Hey Niya, thanks it works! Sorry but in the output I don't have blanklines, I don't know why it formatted like this in my question .
    The code just works properly!
    Might I just ask you how to reverse this code ordering by ascending?

    Again, Thanks

  9. #9
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,462

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    What it has to do with the question.. ?
    System.FormatException: '"Input string is not in correct format"'
    Seemed to me that you're trying to format a number as a string.
    Along with the sunshine there has to be a little rain sometime.

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    Might I just ask you how to reverse this code ordering by ascending?
    Change this:-
    Code:
    OrderByDescending
    To this:-
    Code:
    OrderBy
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Hey Niya, I just sow a bug. Look this is the numbers I'm working on( without being sorted)

    Code:
    0.000012 - 204412500
    0.00001206 - 390500
    0.00001219 - 359600
    0.00001231 - 375000
    0.00001243 - 351800
    0.00001255 - 336400
    0.00001268 - 382800
    0.00001281 - 382800
    0.00001293 - 390500
    0.00001306 - 386600
    0.00001319 - 348000
    0.00001333 - 378900
    0.00001346 - 409800
    0.00001359 - 382800
    0.00001373 - 390500
    0.00001375 - 690000
    0.00001387 - 448500
    0.00001401 - 409800
    0.0000141 - 5414000
    0.00001415 - 460100
    0.00001426 - 900800
    0.00001429 - 355700
    0.00001443 - 359600
    0.0000145 - 4347800
    0.00001457 - 363400
    0.00001472 - 336400
    0.00001487 - 324800
    0.00001499 - 4220500
    0.000015 - 100000
    0.00001502 - 386600
    0.00001517 - 429200
    0.00001527 - 393100
    0.00001532 - 444700
    0.00001547 - 402100
    0.00001549 - 12041100
    0.00001563 - 359600
    0.00001573 - 3264400
    0.00001576 - 12041200
    0.00001578 - 390500
    0.00001594 - 363400
    0.00001598 - 3000000
    0.0000161 - 351800
    0.0000165 - 4876600
    0.00001668 - 500000
    0.000017 - 100000
    0.00001721 - 1000000
    0.00001729 - 500000
    0.0000175 - 20798800
    0.00001771 - 300000
    0.0000179 - 37893900
    0.00001794 - 1144700
    0.000018 - 23236700
    0.0000185 - 27555600
    0.00001861 - 1000000
    0.00001873 - 320000
    0.000019 - 17507300
    0.0000195 - 20887600
    0.0000197 - 2800000
    0.00001975 - 73300
    0.00001999 - 157400
    0.00002 - 33303500
    0.00002026 - 1432000
    0.00002059 - 75000
    0.00002062 - 45568900
    0.00002094 - 49114800
    0.000021 - 17342000
    0.00002114 - 2610000
    0.00002117 - 17100
    0.00002163 - 100000
    0.00002171 - 33900
    0.0000218 - 100000
    0.000022 - 59426600
    0.00002202 - 41000
    0.00002223 - 100000
    0.0000227 - 100000
    0.00002279 - 100000
    0.0000229 - 100000
    0.000023 - 5262000
    0.00002301 - 2978500
    0.00002314 - 100000
    0.00002334 - 100000
    0.00002394 - 100000
    0.000024 - 47296500
    0.00002429 - 100000
    0.0000245 - 100000
    0.00002458 - 389300
    0.000025 - 123015400
    0.0000255 - 100000
    0.00002573 - 100000
    0.00002678 - 100000
    0.00002702 - 100000
    0.000028 - 11406300
    0.00002801 - 1326600
    0.00002812 - 100000
    0.00002813 - 36540500
    0.00002837 - 100000
    0.0000286 - 1870300
    0.00002862 - 1200
    0.00002874 - 2655700
    0.00002899 - 100000
    0.00002958 - 16769100
    0.00003 - 15516800
    0.00003044 - 100000
    0.000033 - 1000000
    0.00003494 - 2365600
    0.00003512 - 4530000
    0.000036 - 706100
    0.0000369 - 32000
    0.00003755 - 2365600
    0.000038 - 39782400
    0.00003868 - 2049200
    0.000039 - 29604800
    0.00004 - 4897500
    0.00004047 - 1453400
    0.000042 - 1684700
    0.00004299 - 7800
    0.000043 - 795300
    0.00004798 - 1000000
    0.000048 - 3021700
    0.00004815 - 96000
    0.00004904 - 300
    0.00005 - 477000
    0.000057 - 116600
    0.00005804 - 5010000
    0.00006 - 2141500
    0.0000652 - 38345000
    0.0000675 - 10291200
    0.000068 - 24012300
    0.00006847 - 1000000
    0.000069 - 7903000
    0.00007 - 15616700
    0.00007019 - 22000
    0.000073 - 13986200
    0.000074 - 833000
    0.00007447 - 27100
    0.000075 - 1477400
    0.00007692 - 60000
    0.00007751 - 19000
    0.0000789 - 7346700
    0.00008 - 8219000
    0.00008069 - 3125000
    0.000082 - 369500
    0.00008451 - 683400
    0.000085 - 245800
    0.000086 - 174500
    0.00008898 - 1000000
    0.0000905 - 1474000
    0.000093 - 1400000
    0.00009591 - 260000
    0.000096 - 32500
    Ascending order:
    Code:
    0.00002 - 33303500
    0.00003 - 15516800
    0.00004 - 4897500
    0.00005 - 477000
    0.00006 - 2141500
    0.00007 - 15616700
    0.00008 - 8219000
    0.000012 - 204412500
    0.000015 - 100000
    0.000017 - 100000
    0.000018 - 23236700
    0.000019 - 17507300
    0.000021 - 17342000
    0.000022 - 59426600
    0.000023 - 5262000
    0.000024 - 47296500
    0.000025 - 123015400
    0.000028 - 11406300
    0.000033 - 1000000
    0.000036 - 706100
    0.000038 - 39782400
    0.000039 - 29604800
    0.000042 - 1684700
    0.000043 - 795300
    0.000048 - 3021700
    0.000057 - 116600
    0.000068 - 24012300
    0.000069 - 7903000
    0.000073 - 13986200
    0.000074 - 833000
    0.000075 - 1477400
    0.000082 - 369500
    0.000085 - 245800
    0.000086 - 174500
    0.000093 - 1400000
    0.000096 - 32500
    0.0000141 - 5414000
    0.0000145 - 4347800
    0.0000161 - 351800
    0.0000165 - 4876600
    0.0000175 - 20798800
    0.0000179 - 37893900
    0.0000185 - 27555600
    0.0000195 - 20887600
    0.0000197 - 2800000
    0.0000218 - 100000
    0.0000227 - 100000
    0.0000229 - 100000
    0.0000245 - 100000
    0.0000255 - 100000
    0.0000286 - 1870300
    0.0000369 - 32000
    0.0000652 - 38345000
    0.0000675 - 10291200
    0.0000789 - 7346700
    0.0000905 - 1474000
    0.00001206 - 390500
    0.00001219 - 359600
    0.00001231 - 375000
    0.00001243 - 351800
    0.00001255 - 336400
    0.00001268 - 382800
    0.00001281 - 382800
    0.00001293 - 390500
    0.00001306 - 386600
    0.00001319 - 348000
    0.00001333 - 378900
    0.00001346 - 409800
    0.00001359 - 382800
    0.00001373 - 390500
    0.00001375 - 690000
    0.00001387 - 448500
    0.00001401 - 409800
    0.00001415 - 460100
    0.00001426 - 900800
    0.00001429 - 355700
    0.00001443 - 359600
    0.00001457 - 363400
    0.00001472 - 336400
    0.00001487 - 324800
    0.00001499 - 4220500
    0.00001502 - 386600
    0.00001517 - 429200
    0.00001527 - 393100
    0.00001532 - 444700
    0.00001547 - 402100
    0.00001549 - 12041100
    0.00001563 - 359600
    0.00001573 - 3264400
    0.00001576 - 12041200
    0.00001578 - 390500
    0.00001594 - 363400
    0.00001598 - 3000000
    0.00001668 - 500000
    0.00001721 - 1000000
    0.00001729 - 500000
    0.00001771 - 300000
    0.00001794 - 1144700
    0.00001861 - 1000000
    0.00001873 - 320000
    0.00001975 - 73300
    0.00001999 - 157400
    0.00002026 - 1432000
    0.00002059 - 75000
    0.00002062 - 45568900
    0.00002094 - 49114800
    0.00002114 - 2610000
    0.00002117 - 17100
    0.00002163 - 100000
    0.00002171 - 33900
    0.00002202 - 41000
    0.00002223 - 100000
    0.00002279 - 100000
    0.00002301 - 2978500
    0.00002314 - 100000
    0.00002334 - 100000
    0.00002394 - 100000
    0.00002429 - 100000
    0.00002458 - 389300
    0.00002573 - 100000
    0.00002678 - 100000
    0.00002702 - 100000
    0.00002801 - 1326600
    0.00002812 - 100000
    0.00002813 - 36540500
    0.00002837 - 100000
    0.00002862 - 1200
    0.00002874 - 2655700
    0.00002899 - 100000
    0.00002958 - 16769100
    0.00003044 - 100000
    0.00003494 - 2365600
    0.00003512 - 4530000
    0.00003755 - 2365600
    0.00003868 - 2049200
    0.00004047 - 1453400
    0.00004299 - 7800
    0.00004798 - 1000000
    0.00004815 - 96000
    0.00004904 - 300
    0.00005804 - 5010000
    0.00006847 - 1000000
    0.00007019 - 22000
    0.00007447 - 27100
    0.00007692 - 60000
    0.00007751 - 19000
    0.00008069 - 3125000
    0.00008451 - 683400
    0.00008898 - 1000000
    0.00009591 - 260000[/QUOTE]
    
    Descending order:
    [QUOTE]0.00009591 - 260000
    0.00008898 - 1000000
    0.00008451 - 683400
    0.00008069 - 3125000
    0.00007751 - 19000
    0.00007692 - 60000
    0.00007447 - 27100
    0.00007019 - 22000
    0.00006847 - 1000000
    0.00005804 - 5010000
    0.00004904 - 300
    0.00004815 - 96000
    0.00004798 - 1000000
    0.00004299 - 7800
    0.00004047 - 1453400
    0.00003868 - 2049200
    0.00003755 - 2365600
    0.00003512 - 4530000
    0.00003494 - 2365600
    0.00003044 - 100000
    0.00002958 - 16769100
    0.00002899 - 100000
    0.00002874 - 2655700
    0.00002862 - 1200
    0.00002837 - 100000
    0.00002813 - 36540500
    0.00002812 - 100000
    0.00002801 - 1326600
    0.00002702 - 100000
    0.00002678 - 100000
    0.00002573 - 100000
    0.00002458 - 389300
    0.00002429 - 100000
    0.00002394 - 100000
    0.00002334 - 100000
    0.00002314 - 100000
    0.00002301 - 2978500
    0.00002279 - 100000
    0.00002223 - 100000
    0.00002202 - 41000
    0.00002171 - 33900
    0.00002163 - 100000
    0.00002117 - 17100
    0.00002114 - 2610000
    0.00002094 - 49114800
    0.00002062 - 45568900
    0.00002059 - 75000
    0.00002026 - 1432000
    0.00001999 - 157400
    0.00001975 - 73300
    0.00001873 - 320000
    0.00001861 - 1000000
    0.00001794 - 1144700
    0.00001771 - 300000
    0.00001729 - 500000
    0.00001721 - 1000000
    0.00001668 - 500000
    0.00001598 - 3000000
    0.00001594 - 363400
    0.00001578 - 390500
    0.00001576 - 12041200
    0.00001573 - 3264400
    0.00001563 - 359600
    0.00001549 - 12041100
    0.00001547 - 402100
    0.00001532 - 444700
    0.00001527 - 393100
    0.00001517 - 429200
    0.00001502 - 386600
    0.00001499 - 4220500
    0.00001487 - 324800
    0.00001472 - 336400
    0.00001457 - 363400
    0.00001443 - 359600
    0.00001429 - 355700
    0.00001426 - 900800
    0.00001415 - 460100
    0.00001401 - 409800
    0.00001387 - 448500
    0.00001375 - 690000
    0.00001373 - 390500
    0.00001359 - 382800
    0.00001346 - 409800
    0.00001333 - 378900
    0.00001319 - 348000
    0.00001306 - 386600
    0.00001293 - 390500
    0.00001281 - 382800
    0.00001268 - 382800
    0.00001255 - 336400
    0.00001243 - 351800
    0.00001231 - 375000
    0.00001219 - 359600
    0.00001206 - 390500
    0.0000905 - 1474000
    0.0000789 - 7346700
    0.0000675 - 10291200
    0.0000652 - 38345000
    0.0000369 - 32000
    0.0000286 - 1870300
    0.0000255 - 100000
    0.0000245 - 100000
    0.0000229 - 100000
    0.0000227 - 100000
    0.0000218 - 100000
    0.0000197 - 2800000
    0.0000195 - 20887600
    0.0000185 - 27555600
    0.0000179 - 37893900
    0.0000175 - 20798800
    0.0000165 - 4876600
    0.0000161 - 351800
    0.0000145 - 4347800
    0.0000141 - 5414000
    0.000096 - 32500
    0.000093 - 1400000
    0.000086 - 174500
    0.000085 - 245800
    0.000082 - 369500
    0.000075 - 1477400
    0.000074 - 833000
    0.000073 - 13986200
    0.000069 - 7903000
    0.000068 - 24012300
    0.000057 - 116600
    0.000048 - 3021700
    0.000043 - 795300
    0.000042 - 1684700
    0.000039 - 29604800
    0.000038 - 39782400
    0.000036 - 706100
    0.000033 - 1000000
    0.000028 - 11406300
    0.000025 - 123015400
    0.000024 - 47296500
    0.000023 - 5262000
    0.000022 - 59426600
    0.000021 - 17342000
    0.000019 - 17507300
    0.000018 - 23236700
    0.000017 - 100000
    0.000015 - 100000
    0.000012 - 204412500
    0.00008 - 8219000
    0.00007 - 15616700
    0.00006 - 2141500
    0.00005 - 477000
    0.00004 - 4897500
    0.00003 - 15516800
    0.00002 - 33303500
    You see? I think it might be a problem of the Json and how it is builded, becauses the decimal like "0.00005" is supposed to be "0.00005000" so basically the code is not sorting very well.
    For example in ascending:

    0.00002 - 33303500 it is supposed to be sorted after 0.000019 - 17507300 , cause 0.00002 ( that because of the bad format of the api where I'm getting the numbers) it is supposed to be 0.00002000 so higher than 0.00001900..
    The sortings are f*ked up basically, since I'm expecting ascending to be starting with the first value: 0.000012 - 204412500 and ending with the last value 0.000096 - 32500 . Can we fix by the sorting algo or I must fix something while I'm getting the numbers?
    Which I'm getting them with:

    Code:
     Public Class Result
            Public Property asks As String()()
            Public Property seqNum As Integer
            Public Property prevSeqNum As Integer
            Public Property lastTs As Double
        End Class
    
        Public Class Root
            Public Property [error] As Object
            Public Property result As Result
            Public Property id As Integer
        End Class
        Private URI As String = "https://api.hotbit.io/api/v1/order.depth?market=KIBA/USDT&limit=150&interval=1e-8"
    
        Private Async Function GetJsonFromApi() As Task(Of Root)
    
            Using http As New HttpClient(),
                      response As HttpResponseMessage = Await http.GetAsync(URI)
                Return JsonConvert.DeserializeObject(Of Root)(Await response.Content.ReadAsStringAsync())
            End Using
        End Function
    
        Private Sub OutputAsks(asks As String()())
            'VENDITE
            Dim contents As New StringBuilder
            For Each ask In asks
                contents.AppendLine(String.Join(" - ", ask))
            Next
    
            RichTextBox1.BeginInvoke(Sub()
                                         RichTextBox1.Text = contents.ToString()
                                     End Sub)
        End Sub
    
        Private Async Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim root As Root = Await GetJsonFromApi()
            OutputAsks(root.result.asks)
        End Sub
    End Class
    Thanks
    Last edited by dday9; Feb 14th, 2022 at 03:53 PM. Reason: replaced quote with code tags to provide a vertical scrollbar

  12. #12
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    It works correctly for me. This is what I tested with:-
    Code:
    Imports System.Net.Http
    Imports System.Text
    Imports Newtonsoft.Json
    
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            RichTextBox1.Lines = RichTextBox1.Lines.
                Where(Function(x) Not String.IsNullOrEmpty(x)).
                OrderByDescending(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
        End Sub
        Public Class Result
            Public Property asks As String()()
            Public Property seqNum As Integer
            Public Property prevSeqNum As Integer
            Public Property lastTs As Double
        End Class
    
        Public Class Root
            Public Property [error] As Object
            Public Property result As Result
            Public Property id As Integer
        End Class
        Private URI As String = "https://api.hotbit.io/api/v1/order.depth?market=KIBA/USDT&limit=150&interval=1e-8"
    
        Private Async Function GetJsonFromApi() As Task(Of Root)
    
            Using http As New HttpClient(),
                      response As HttpResponseMessage = Await http.GetAsync(URI)
                Return JsonConvert.DeserializeObject(Of Root)(Await response.Content.ReadAsStringAsync())
            End Using
        End Function
    
        Private Sub OutputAsks(asks As String()())
            'VENDITE
            Dim contents As New StringBuilder
            For Each ask In asks
                contents.AppendLine(String.Join(" - ", ask))
            Next
    
            RichTextBox1.BeginInvoke(Sub()
                                         RichTextBox1.Text = contents.ToString()
                                     End Sub)
        End Sub
    
        Private Async Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            Dim root As Root = Await GetJsonFromApi()
            OutputAsks(root.result.asks)
    
    
        End Sub
    End Class
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Endeed that the exactly code I'm working on too, but maybe I didn't explain correctly what Is the issue ..
    The json where I'm getting the data,is an Api of a crypto exchange.
    So basically, in the website, ALL of the decimals are in the format ex: 0.00001234, and also 0.00001000, but the Json is cutting those 000 after the 1, so when I 'm going to parse the numbers, instead of getting 0.00001000, I'm getting 0.00001 . So basically, this is making the sorting to freak out. So after explained this, I'm coming back to the numbers I used before in the previous post.
    Using ascending sort:

    0.00002 - 33303500 it is sorted before 0.000019 - 17507300, which is not correctly. The entire big input list should start from the smallest value 0.000012 - 204412500 to the biggest 0.000096 - 32500 , but unfortunately this is not happening
    I might need to place the missing decimals with 0's in order to make the sorting algo sort correctly?

    Hope I've been clear this time.
    Thanks

  14. #14
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    This is what I get. It is sorted in descending order(from biggest to smallest) and it is correct:-
    Code:
    0.000093 - 1400000
    0.0000905 - 1474000
    0.00008898 - 1000000
    0.000086 - 174500
    0.000085 - 245800
    0.00008451 - 683400
    0.000082 - 369500
    0.00008069 - 3125000
    0.00008 - 8219000
    0.0000789 - 7346700
    0.00007751 - 19000
    0.00007692 - 60000
    0.000075 - 1477400
    0.00007447 - 27100
    0.000074 - 833000
    0.000073 - 13986200
    0.00007019 - 22000
    0.00007 - 15616700
    0.000069 - 7903000
    0.00006847 - 1000000
    0.000068 - 24012300
    0.0000675 - 10291200
    0.0000652 - 38345000
    0.00006 - 2141500
    0.00005804 - 5010000
    0.000057 - 116600
    0.00005 - 477000
    0.00004904 - 300
    0.00004815 - 96000
    0.000048 - 3021700
    0.00004798 - 1000000
    0.000043 - 795300
    0.00004299 - 7800
    0.000042 - 1684700
    0.00004047 - 1453400
    0.00004 - 4897500
    0.000039 - 29604800
    0.00003868 - 2049200
    0.000038 - 39782400
    0.00003755 - 2365600
    0.0000369 - 32000
    0.000036 - 706100
    0.00003512 - 4530000
    0.00003494 - 2365600
    0.000033 - 1000000
    0.00003044 - 100000
    0.00003 - 15516800
    0.00002958 - 16769100
    0.00002899 - 100000
    0.00002874 - 2655700
    0.00002862 - 1200
    0.0000286 - 1870300
    0.00002837 - 100000
    0.00002813 - 36540500
    0.00002812 - 100000
    0.00002801 - 1326600
    0.000028 - 11406300
    0.00002702 - 100000
    0.00002678 - 100000
    0.00002573 - 100000
    0.0000255 - 100000
    0.000025 - 123015400
    0.00002458 - 389300
    0.0000245 - 100000
    0.00002429 - 100000
    0.000024 - 47636400
    0.00002394 - 100000
    0.00002334 - 100000
    0.00002314 - 100000
    0.00002301 - 2978500
    0.000023 - 5262000
    0.0000229 - 100000
    0.00002279 - 100000
    0.0000227 - 100000
    0.00002223 - 100000
    0.00002202 - 41000
    0.000022 - 59426600
    0.0000218 - 100000
    0.00002171 - 33900
    0.00002163 - 100000
    0.00002117 - 17100
    0.00002114 - 2610000
    0.000021 - 17342000
    0.00002094 - 49114800
    0.00002062 - 45568900
    0.00002059 - 75000
    0.00002026 - 1432000
    0.00002 - 33303500
    0.00001999 - 157400
    0.0000198 - 50323900
    0.00001975 - 73300
    0.0000197 - 2800000
    0.0000195 - 38390600
    0.000019 - 17507300
    0.00001873 - 320000
    0.00001861 - 1000000
    0.0000185 - 27555600
    0.000018 - 5733700
    0.00001794 - 1144700
    0.0000179 - 37893900
    0.00001771 - 300000
    0.0000175 - 20798800
    0.00001729 - 500000
    0.00001721 - 1000000
    0.00001701 - 19337000
    0.000017 - 100000
    0.00001668 - 500000
    0.0000165 - 4876600
    0.0000161 - 351800
    0.00001598 - 3000000
    0.00001594 - 363400
    0.00001578 - 390500
    0.00001576 - 12041200
    0.00001573 - 3264400
    0.00001563 - 359600
    0.00001549 - 12041100
    0.00001547 - 402100
    0.00001532 - 444700
    0.00001527 - 393100
    0.00001517 - 429200
    0.00001502 - 386600
    0.000015 - 100000
    0.00001499 - 4220500
    0.00001487 - 324800
    0.00001472 - 336400
    0.00001457 - 363400
    0.0000145 - 4347800
    0.00001443 - 359600
    0.00001429 - 355700
    0.00001426 - 900800
    0.00001415 - 460100
    0.0000141 - 5414000
    0.00001401 - 409800
    0.00001387 - 448500
    0.00001375 - 690000
    0.00001373 - 390500
    0.00001359 - 382800
    0.00001346 - 409800
    0.00001333 - 378900
    0.00001319 - 348000
    0.00001306 - 386600
    0.00001293 - 390500
    0.00001281 - 382800
    0.00001268 - 382800
    0.00001255 - 336400
    0.00001243 - 351800
    0.00001231 - 375000
    0.00001219 - 359600
    0.00001206 - 390500
    0.000012 - 238130300
    I don't understand how you're getting a different result to be honest.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  15. #15
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Also, if I sort it in ascending order(smallest to biggest) using this:-
    Code:
            RichTextBox1.Lines = RichTextBox1.Lines.
                Where(Function(x) Not String.IsNullOrEmpty(x)).
                OrderBy(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
    I get this:-
    Code:
    0.000012 - 124500000
    0.00001206 - 390500
    0.00001219 - 359600
    0.00001231 - 375000
    0.00001243 - 351800
    0.00001255 - 336400
    0.00001268 - 382800
    0.00001281 - 382800
    0.00001293 - 390500
    0.00001306 - 386600
    0.00001319 - 348000
    0.00001333 - 378900
    0.00001346 - 409800
    0.00001359 - 382800
    0.00001373 - 390500
    0.00001375 - 690000
    0.00001387 - 448500
    0.00001401 - 409800
    0.0000141 - 5414000
    0.00001415 - 460100
    0.00001426 - 900800
    0.00001429 - 355700
    0.00001443 - 359600
    0.0000145 - 4347800
    0.00001457 - 363400
    0.00001472 - 336400
    0.00001487 - 324800
    0.00001499 - 4220500
    0.000015 - 100000
    0.00001502 - 386600
    0.00001517 - 429200
    0.00001527 - 393100
    0.00001532 - 444700
    0.00001547 - 402100
    0.00001549 - 12041100
    0.00001563 - 359600
    0.00001573 - 3264400
    0.00001576 - 12041200
    0.00001578 - 390500
    0.00001594 - 363400
    0.00001598 - 3000000
    0.0000161 - 351800
    0.0000165 - 4876600
    0.00001668 - 500000
    0.000017 - 100000
    0.00001701 - 19337000
    0.00001721 - 1000000
    0.00001729 - 500000
    0.0000175 - 20798800
    0.00001771 - 300000
    0.0000179 - 37893900
    0.00001794 - 1144700
    0.000018 - 5733700
    0.0000185 - 27555600
    0.00001861 - 1000000
    0.00001873 - 320000
    0.000019 - 17507300
    0.0000195 - 38390600
    0.0000197 - 2800000
    0.00001975 - 73300
    0.0000198 - 50323900
    0.00001999 - 157400
    0.00002 - 33459500
    0.00002026 - 1432000
    0.00002059 - 75000
    0.00002062 - 45568900
    0.00002094 - 49114800
    0.000021 - 17342000
    0.00002114 - 2610000
    0.00002117 - 17100
    0.00002163 - 100000
    0.00002171 - 33900
    0.0000218 - 100000
    0.000022 - 59426600
    0.00002202 - 41000
    0.00002223 - 100000
    0.0000227 - 100000
    0.00002279 - 100000
    0.0000229 - 100000
    0.000023 - 5262000
    0.00002301 - 2978500
    0.00002314 - 100000
    0.00002334 - 100000
    0.00002394 - 100000
    0.000024 - 47636400
    0.00002429 - 100000
    0.0000245 - 100000
    0.00002458 - 389300
    0.000025 - 123015400
    0.0000255 - 100000
    0.00002573 - 100000
    0.00002678 - 100000
    0.00002702 - 100000
    0.000028 - 11406300
    0.00002801 - 1326600
    0.00002812 - 100000
    0.00002813 - 36540500
    0.00002837 - 100000
    0.0000286 - 1870300
    0.00002862 - 1200
    0.00002874 - 2655700
    0.00002899 - 100000
    0.00002958 - 16769100
    0.00003 - 15516800
    0.00003044 - 100000
    0.000033 - 1000000
    0.00003494 - 2365600
    0.00003512 - 4530000
    0.000036 - 706100
    0.0000369 - 32000
    0.00003755 - 2365600
    0.000038 - 39782400
    0.00003868 - 2049200
    0.000039 - 29604800
    0.00004 - 4897500
    0.00004047 - 1453400
    0.000042 - 1684700
    0.00004299 - 7800
    0.000043 - 795300
    0.00004798 - 1000000
    0.000048 - 3021700
    0.00004904 - 300
    0.00005 - 477000
    0.000057 - 116600
    0.00005804 - 5010000
    0.00006 - 2141500
    0.0000652 - 38345000
    0.0000675 - 10291200
    0.000068 - 24012300
    0.00006847 - 1000000
    0.000069 - 7903000
    0.00007 - 15616700
    0.00007019 - 22000
    0.000073 - 13986200
    0.000074 - 833000
    0.00007447 - 27100
    0.000075 - 1477400
    0.00007692 - 60000
    0.00007751 - 19000
    0.0000789 - 7346700
    0.00008 - 8219000
    0.00008069 - 3125000
    0.000082 - 369500
    0.00008451 - 683400
    0.000085 - 245800
    0.000086 - 174500
    0.00008898 - 1000000
    0.0000905 - 1474000
    0.000093 - 1400000
    0.00009591 - 260000
    Which is also correct. I don't know why you're not getting these results if you're using the same code.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    that's completely a weird behavior Niya O.o ....
    FULL CODE:
    Code:
    Public Class form1
    
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            RichTextBox1.Lines = RichTextBox1.Lines.
                 Where(Function(x) Not String.IsNullOrEmpty(x)).
                 OrderBy(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            RichTextBox1.Lines = RichTextBox1.Lines.
                Where(Function(x) Not String.IsNullOrEmpty(x)).
                OrderByDescending(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
        End Sub
    
        Public Class Result
            Public Property asks As String()()
            Public Property bids As String()()
            Public Property seqNum As Integer
            Public Property prevSeqNum As Integer
            Public Property lastTs As Double
        End Class
    
        Public Class Root
            Public Property [error] As Object
            Public Property result As Result
            Public Property id As Integer
        End Class
        Private URI As String = "https://api.hotbit.io/api/v1/order.depth?market=KIBA/USDT&limit=150&interval=1e-8"
    
        Private Async Function GetJsonFromApi() As Task(Of Root)
    
            Using http As New HttpClient(),
                      response As HttpResponseMessage = Await http.GetAsync(URI)
                Return JsonConvert.DeserializeObject(Of Root)(Await response.Content.ReadAsStringAsync())
            End Using
        End Function
    
        Private Sub OutputAsks(asks As String()())
            'VENDITE
            Dim contents As New StringBuilder
            For Each ask In asks
                contents.AppendLine(String.Join(" - ", ask))
            Next
    
            RichTextBox1.BeginInvoke(Sub()
                                         RichTextBox1.Text = contents.ToString()
                                     End Sub)
        End Sub
    
        Private Async Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim root As Root = Await GetJsonFromApi()
            OutputAsks(root.result.asks)
            End Sub
    End Class
    Descending output:
    Code:
    0.00009591 - 260000
    0.00008898 - 1000000
    0.00008451 - 683400
    0.00008069 - 3125000
    0.00007751 - 19000
    0.00007692 - 60000
    0.00007447 - 27100
    0.00007019 - 22000
    0.00006847 - 1000000
    0.00005804 - 5010000
    0.00004904 - 300
    0.00004798 - 1000000
    0.00004299 - 7800
    0.00004047 - 1453400
    0.00003868 - 2049200
    0.00003755 - 2365600
    0.00003512 - 4530000
    0.00003494 - 2365600
    0.00003044 - 100000
    0.00002958 - 16769100
    0.00002899 - 100000
    0.00002874 - 2655700
    0.00002862 - 1200
    0.00002837 - 100000
    0.00002813 - 36540500
    0.00002812 - 100000
    0.00002801 - 1326600
    0.00002702 - 100000
    0.00002678 - 100000
    0.00002573 - 100000
    0.00002458 - 389300
    0.00002429 - 100000
    0.00002394 - 100000
    0.00002334 - 100000
    0.00002314 - 100000
    0.00002301 - 2978500
    0.00002279 - 100000
    0.00002223 - 100000
    0.00002202 - 41000
    0.00002171 - 33900
    0.00002163 - 100000
    0.00002117 - 17100
    0.00002114 - 2610000
    0.00002094 - 49114800
    0.00002062 - 45568900
    0.00002059 - 75000
    0.00002026 - 1432000
    0.00001999 - 157400
    0.00001975 - 73300
    0.00001873 - 320000
    0.00001861 - 1000000
    0.00001794 - 1144700
    0.00001771 - 300000
    0.00001761 - 378900
    0.00001743 - 429200
    0.00001729 - 500000
    0.00001726 - 344100
    0.00001721 - 1000000
    0.00001709 - 429200
    0.00001701 - 19337000
    0.00001692 - 351800
    0.00001675 - 436900
    0.00001668 - 500000
    0.00001659 - 313200
    0.00001642 - 409800
    0.00001626 - 309300
    0.00001598 - 3000000
    0.00001594 - 363400
    0.00001578 - 390500
    0.00001576 - 12041200
    0.00001573 - 3264400
    0.00001563 - 359600
    0.00001549 - 12041100
    0.00001547 - 402100
    0.00001532 - 444700
    0.00001527 - 393100
    0.00001517 - 429200
    0.00001502 - 386600
    0.00001499 - 4220500
    0.00001487 - 324800
    0.00001472 - 336400
    0.00001457 - 363400
    0.00001443 - 359600
    0.00001429 - 355700
    0.00001426 - 900800
    0.00001415 - 460100
    0.00001401 - 409800
    0.00001387 - 317000
    0.00001373 - 348000
    0.00001359 - 409800
    0.00001346 - 313200
    0.00001333 - 375000
    0.00001319 - 429200
    0.00001294 - 26999900
    0.0000905 - 1474000
    0.0000789 - 7346700
    0.0000675 - 10291200
    0.0000652 - 38345000
    0.0000369 - 32000
    0.0000286 - 1870300
    0.0000255 - 100000
    0.0000245 - 100000
    0.0000229 - 100000
    0.0000227 - 100000
    0.0000218 - 100000
    0.0000198 - 50323900
    0.0000197 - 2800000
    0.0000195 - 38390600
    0.0000185 - 27555600
    0.0000179 - 37893900
    0.0000175 - 20798800
    0.0000165 - 4876600
    0.0000161 - 351800
    0.0000141 - 5414000
    0.0000139 - 14101400
    0.000096 - 32500
    0.000093 - 1400000
    0.000086 - 174500
    0.000085 - 245800
    0.000082 - 369500
    0.000075 - 1477400
    0.000074 - 833000
    0.000073 - 13986200
    0.000069 - 7903000
    0.000068 - 24012300
    0.000057 - 116600
    0.000048 - 3021700
    0.000043 - 795300
    0.000042 - 1684700
    0.000039 - 29604800
    0.000038 - 39782400
    0.000036 - 706100
    0.000033 - 1000000
    0.000028 - 9006100
    0.000025 - 108914000
    0.000024 - 47636400
    0.000023 - 5262000
    0.000022 - 59426600
    0.000021 - 17342000
    0.000019 - 17507300
    0.000018 - 5733700
    0.000017 - 100000
    0.000015 - 100000
    0.00008 - 8219000
    0.00007 - 15616700
    0.00006 - 2141500
    0.00005 - 477000
    0.00004 - 4897500
    0.00003 - 15516800
    0.00002 - 38132900
    Ascending:
    Code:
    0.00002 - 38132900
    0.00003 - 15516800
    0.00004 - 4897500
    0.00005 - 477000
    0.00006 - 2141500
    0.00007 - 15616700
    0.00008 - 8219000
    0.000015 - 100000
    0.000017 - 100000
    0.000018 - 5733700
    0.000019 - 17507300
    0.000021 - 17342000
    0.000022 - 59426600
    0.000023 - 5262000
    0.000024 - 47636400
    0.000025 - 108914000
    0.000028 - 9006100
    0.000033 - 1000000
    0.000036 - 706100
    0.000038 - 39782400
    0.000039 - 29604800
    0.000042 - 1684700
    0.000043 - 795300
    0.000048 - 3021700
    0.000057 - 116600
    0.000068 - 24012300
    0.000069 - 7903000
    0.000073 - 13986200
    0.000074 - 833000
    0.000075 - 1477400
    0.000082 - 369500
    0.000085 - 245800
    0.000086 - 174500
    0.000093 - 1400000
    0.000096 - 32500
    0.0000139 - 14101400
    0.0000141 - 5414000
    0.0000161 - 351800
    0.0000165 - 4876600
    0.0000175 - 20798800
    0.0000179 - 37893900
    0.0000185 - 27555600
    0.0000195 - 38390600
    0.0000197 - 2800000
    0.0000198 - 50323900
    0.0000218 - 100000
    0.0000227 - 100000
    0.0000229 - 100000
    0.0000245 - 100000
    0.0000255 - 100000
    0.0000286 - 1870300
    0.0000369 - 32000
    0.0000652 - 38345000
    0.0000675 - 10291200
    0.0000789 - 7346700
    0.0000905 - 1474000
    0.00001294 - 26999900
    0.00001319 - 429200
    0.00001333 - 375000
    0.00001346 - 313200
    0.00001359 - 409800
    0.00001373 - 348000
    0.00001387 - 317000
    0.00001401 - 409800
    0.00001415 - 460100
    0.00001426 - 900800
    0.00001429 - 355700
    0.00001443 - 359600
    0.00001457 - 363400
    0.00001472 - 336400
    0.00001487 - 324800
    0.00001499 - 4220500
    0.00001502 - 386600
    0.00001517 - 429200
    0.00001527 - 393100
    0.00001532 - 444700
    0.00001547 - 402100
    0.00001549 - 12041100
    0.00001563 - 359600
    0.00001573 - 3264400
    0.00001576 - 12041200
    0.00001578 - 390500
    0.00001594 - 363400
    0.00001598 - 3000000
    0.00001626 - 309300
    0.00001642 - 409800
    0.00001659 - 313200
    0.00001668 - 500000
    0.00001675 - 436900
    0.00001692 - 351800
    0.00001701 - 19337000
    0.00001709 - 429200
    0.00001721 - 1000000
    0.00001726 - 344100
    0.00001729 - 500000
    0.00001743 - 429200
    0.00001761 - 378900
    0.00001771 - 300000
    0.00001794 - 1144700
    0.00001861 - 1000000
    0.00001873 - 320000
    0.00001975 - 73300
    0.00001999 - 157400
    0.00002026 - 1432000
    0.00002059 - 75000
    0.00002062 - 45568900
    0.00002094 - 49114800
    0.00002114 - 2610000
    0.00002117 - 17100
    0.00002163 - 100000
    0.00002171 - 33900
    0.00002202 - 41000
    0.00002223 - 100000
    0.00002279 - 100000
    0.00002301 - 2978500
    0.00002314 - 100000
    0.00002334 - 100000
    0.00002394 - 100000
    0.00002429 - 100000
    0.00002458 - 389300
    0.00002573 - 100000
    0.00002678 - 100000
    0.00002702 - 100000
    0.00002801 - 1326600
    0.00002812 - 100000
    0.00002813 - 36540500
    0.00002837 - 100000
    0.00002862 - 1200
    0.00002874 - 2655700
    0.00002899 - 100000
    0.00002958 - 16769100
    0.00003044 - 100000
    0.00003494 - 2365600
    0.00003512 - 4530000
    0.00003755 - 2365600
    0.00003868 - 2049200
    0.00004047 - 1453400
    0.00004299 - 7800
    0.00004798 - 1000000
    0.00004904 - 300
    0.00005804 - 5010000
    0.00006847 - 1000000
    0.00007019 - 22000
    0.00007447 - 27100
    0.00007692 - 60000
    0.00007751 - 19000
    0.00008069 - 3125000
    0.00008451 - 683400
    0.00008898 - 1000000
    0.00009591 - 260000
    what the duck is going on?
    Last edited by matty95srk; Feb 14th, 2022 at 01:03 PM.

  17. #17
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    that's completely a weird behavior Niya O.o ....
    FULL CODE:.....
    I used your exact code and I get this:-

    Ascending order:-
    Code:
    0.00001293 - 9267200
    0.00001294 - 64999900
    0.00001306 - 394400
    0.00001319 - 429200
    0.00001333 - 375000
    0.00001346 - 313200
    0.00001359 - 409800
    0.00001373 - 348000
    0.00001387 - 317000
    0.0000139 - 14101400
    0.00001401 - 409800
    0.00001415 - 460100
    0.00001426 - 900800
    0.00001429 - 355700
    0.00001443 - 359600
    0.00001457 - 363400
    0.00001472 - 336400
    0.00001487 - 324800
    0.000015 - 100000
    0.00001502 - 386600
    0.00001517 - 429200
    0.00001527 - 393100
    0.00001532 - 444700
    0.00001547 - 402100
    0.00001549 - 12041100
    0.00001563 - 359600
    0.00001573 - 3264400
    0.00001576 - 12041200
    0.00001578 - 390500
    0.00001594 - 363400
    0.00001598 - 3000000
    0.0000161 - 351800
    0.00001626 - 309300
    0.00001642 - 409800
    0.0000165 - 4876600
    0.00001659 - 313200
    0.00001668 - 500000
    0.00001675 - 436900
    0.00001692 - 351800
    0.000017 - 100000
    0.00001701 - 19337000
    0.00001709 - 429200
    0.00001721 - 1000000
    0.00001726 - 344100
    0.00001729 - 500000
    0.00001743 - 429200
    0.0000175 - 20798800
    0.00001771 - 300000
    0.0000179 - 37893900
    0.00001794 - 1144700
    0.000018 - 5733700
    0.0000185 - 27555600
    0.00001861 - 1000000
    0.00001873 - 320000
    0.0000189 - 1000000
    0.000019 - 17507300
    0.0000195 - 38390600
    0.0000197 - 2800000
    0.00001975 - 73300
    0.0000198 - 50323900
    0.00001999 - 157400
    0.00002 - 38132900
    0.00002026 - 1432000
    0.00002059 - 75000
    0.00002062 - 45568900
    0.00002094 - 49114800
    0.000021 - 17342000
    0.00002114 - 2610000
    0.00002117 - 17100
    0.00002163 - 100000
    0.00002171 - 33900
    0.0000218 - 100000
    0.000022 - 59426600
    0.00002202 - 41000
    0.00002223 - 100000
    0.0000227 - 100000
    0.00002279 - 100000
    0.0000229 - 100000
    0.000023 - 5262000
    0.00002301 - 2978500
    0.00002314 - 100000
    0.00002334 - 100000
    0.00002394 - 100000
    0.000024 - 47636400
    0.00002429 - 100000
    0.0000245 - 100000
    0.00002458 - 389300
    0.000025 - 108914000
    0.0000255 - 100000
    0.00002573 - 100000
    0.00002678 - 100000
    0.00002702 - 100000
    0.000028 - 10006100
    0.00002801 - 1326600
    0.00002812 - 100000
    0.00002813 - 36540500
    0.00002837 - 100000
    0.0000286 - 1870300
    0.00002862 - 1200
    0.00002874 - 2655700
    0.00002899 - 100000
    0.00002958 - 16769100
    0.00003 - 15516800
    0.00003044 - 100000
    0.000033 - 1000000
    0.00003494 - 2365600
    0.00003512 - 4530000
    0.000036 - 706100
    0.0000369 - 32000
    0.00003755 - 2365600
    0.000038 - 39782400
    0.00003868 - 2049200
    0.000039 - 29604800
    0.00004 - 4897500
    0.00004047 - 1453400
    0.000042 - 1684700
    0.00004299 - 7800
    0.000043 - 795300
    0.00004798 - 1000000
    0.000048 - 3021700
    0.00004904 - 300
    0.00005 - 477000
    0.000057 - 116600
    0.00005804 - 5010000
    0.00006 - 2141500
    0.0000652 - 38345000
    0.0000675 - 10291200
    0.000068 - 24012300
    0.00006847 - 1000000
    0.000069 - 7903000
    0.00007 - 15616700
    0.00007019 - 22000
    0.000073 - 13986200
    0.000074 - 833000
    0.00007447 - 27100
    0.000075 - 1477400
    0.00007692 - 60000
    0.00007751 - 19000
    0.0000789 - 7346700
    0.00008 - 8219000
    0.00008069 - 3125000
    0.000082 - 369500
    0.00008451 - 683400
    0.000085 - 245800
    0.000086 - 174500
    0.00008898 - 1000000
    0.0000905 - 1474000
    0.000093 - 1400000
    0.00009591 - 260000
    0.000096 - 32500
    Descending order:-
    Code:
    0.000096 - 32500
    0.00009591 - 260000
    0.000093 - 1400000
    0.0000905 - 1474000
    0.00008898 - 1000000
    0.000086 - 174500
    0.000085 - 245800
    0.00008451 - 683400
    0.000082 - 369500
    0.00008069 - 3125000
    0.00008 - 8219000
    0.0000789 - 7346700
    0.00007751 - 19000
    0.00007692 - 60000
    0.000075 - 1477400
    0.00007447 - 27100
    0.000074 - 833000
    0.000073 - 13986200
    0.00007019 - 22000
    0.00007 - 15616700
    0.000069 - 7903000
    0.00006847 - 1000000
    0.000068 - 24012300
    0.0000675 - 10291200
    0.0000652 - 38345000
    0.00006 - 2141500
    0.00005804 - 5010000
    0.000057 - 116600
    0.00005 - 477000
    0.00004904 - 300
    0.000048 - 3021700
    0.00004798 - 1000000
    0.000043 - 795300
    0.00004299 - 7800
    0.000042 - 1684700
    0.00004047 - 1453400
    0.00004 - 4897500
    0.000039 - 29604800
    0.00003868 - 2049200
    0.000038 - 39782400
    0.00003755 - 2365600
    0.0000369 - 32000
    0.000036 - 706100
    0.00003512 - 4530000
    0.00003494 - 2365600
    0.000033 - 1000000
    0.00003044 - 100000
    0.00003 - 15516800
    0.00002958 - 16769100
    0.00002899 - 100000
    0.00002874 - 2655700
    0.00002862 - 1200
    0.0000286 - 1870300
    0.00002837 - 100000
    0.00002813 - 36540500
    0.00002812 - 100000
    0.00002801 - 1326600
    0.000028 - 10006100
    0.00002702 - 100000
    0.00002678 - 100000
    0.00002573 - 100000
    0.0000255 - 100000
    0.000025 - 108914000
    0.00002458 - 389300
    0.0000245 - 100000
    0.00002429 - 100000
    0.000024 - 47636400
    0.00002394 - 100000
    0.00002334 - 100000
    0.00002314 - 100000
    0.00002301 - 2978500
    0.000023 - 5262000
    0.0000229 - 100000
    0.00002279 - 100000
    0.0000227 - 100000
    0.00002223 - 100000
    0.00002202 - 41000
    0.000022 - 59426600
    0.0000218 - 100000
    0.00002171 - 33900
    0.00002163 - 100000
    0.00002117 - 17100
    0.00002114 - 2610000
    0.000021 - 17342000
    0.00002094 - 49114800
    0.00002062 - 45568900
    0.00002059 - 75000
    0.00002026 - 1432000
    0.00002 - 38132900
    0.00001999 - 157400
    0.0000198 - 50323900
    0.00001975 - 73300
    0.0000197 - 2800000
    0.0000195 - 38390600
    0.000019 - 17507300
    0.0000189 - 1000000
    0.00001873 - 320000
    0.00001861 - 1000000
    0.0000185 - 27555600
    0.000018 - 5733700
    0.00001794 - 1144700
    0.0000179 - 37893900
    0.00001771 - 300000
    0.0000175 - 20798800
    0.00001743 - 429200
    0.00001729 - 500000
    0.00001726 - 344100
    0.00001721 - 1000000
    0.00001709 - 429200
    0.00001701 - 19337000
    0.000017 - 100000
    0.00001692 - 351800
    0.00001675 - 436900
    0.00001668 - 500000
    0.00001659 - 313200
    0.0000165 - 4876600
    0.00001642 - 409800
    0.00001626 - 309300
    0.0000161 - 351800
    0.00001598 - 3000000
    0.00001594 - 363400
    0.00001578 - 390500
    0.00001576 - 12041200
    0.00001573 - 3264400
    0.00001563 - 359600
    0.00001549 - 12041100
    0.00001547 - 402100
    0.00001532 - 444700
    0.00001527 - 393100
    0.00001517 - 429200
    0.00001502 - 386600
    0.000015 - 100000
    0.00001487 - 324800
    0.00001472 - 336400
    0.00001457 - 363400
    0.00001443 - 359600
    0.00001429 - 355700
    0.00001426 - 900800
    0.00001415 - 460100
    0.00001401 - 409800
    0.0000139 - 14101400
    0.00001387 - 317000
    0.00001373 - 348000
    0.00001359 - 409800
    0.00001346 - 313200
    0.00001333 - 375000
    0.00001319 - 429200
    0.00001306 - 394400
    0.00001294 - 64999900
    0.00001293 - 9267200
    Is this the output you were expecting?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Your output is correct, mine no. Look at the first numbers in my ascending list.

  19. #19
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,341

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Is this perhaps a regional settings issue where matty's "decimal separator" character is a comma rather than a period? And because of that the comparison being done is strictly alphabetic?

  20. #20
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by OptionBase1 View Post
    And because of that the comparison being done is strictly alphabetic?
    Actually, the comparison is numeric:-
    Code:
    RichTextBox1.Lines = RichTextBox1.Lines.
                 Where(Function(x) Not String.IsNullOrEmpty(x)).
                 OrderBy(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
    The String is converted to a Decimal in the OrderBy clause.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by Niya View Post
    Actually, the comparison is numeric:-
    Code:
    RichTextBox1.Lines = RichTextBox1.Lines.
                 Where(Function(x) Not String.IsNullOrEmpty(x)).
                 OrderBy(Function(x) Decimal.Parse(x.Split(" "c)(0))).ToArray
    The String is converted to a Decimal in the OrderBy clause.
    it might be that the cultureinfo changes between dot and commas?
    just guessing

  22. #22
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    @matty95srk

    Code:
        Private Async Function GetJsonFromApi() As Task(Of Root)
    
            Using http As New HttpClient(),
                      response As HttpResponseMessage = Await http.GetAsync(URI)
    
                Debug.WriteLine(Await response.Content.ReadAsStringAsync)
    
                Return JsonConvert.DeserializeObject(Of Root)(Await response.Content.ReadAsStringAsync())
            End Using
        End Function
    Add the line in red to your GetJsonFromApi function and show us the actual JSON that printed to the immediate window.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  23. #23
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,703

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    it might be that the cultureinfo changes between dot and commas?
    just guessing
    Execute this line:-
    Code:
    Debug.WriteLine(My.Application.Culture.NumberFormat.NumberDecimalSeparator)
    On my system it prints a decimal point symbol. What does it print on yours?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by Niya View Post
    Execute this line:-
    Code:
    Debug.WriteLine(My.Application.Culture.NumberFormat.NumberDecimalSeparator)
    On my system it prints a decimal point symbol. What does it print on yours?
    In mine it prints a decimal comma, is this the reason?

    Quote Originally Posted by Niya View Post
    @matty95srk

    Code:
        Private Async Function GetJsonFromApi() As Task(Of Root)
    
            Using http As New HttpClient(),
                      response As HttpResponseMessage = Await http.GetAsync(URI)
    
                Debug.WriteLine(Await response.Content.ReadAsStringAsync)
    
                Return JsonConvert.DeserializeObject(Of Root)(Await response.Content.ReadAsStringAsync())
            End Using
        End Function
    Add the line in red to your GetJsonFromApi function and show us the actual JSON that printed to the immediate window.

    this is the Json i'm getting

    Code:
    {"error":null,"result":{"asks":[["0.00001137","302300"],["0.00001148","402100"],["0.00001159","448500"],["0.00001171","413700"],["0.00001183","344100"],["0.00001195","359600"],["0.00001206","386600"],["0.00001219","371200"],["0.00001231","344100"],["0.00001243","456300"],["0.00001255","398200"],["0.00001268","375000"],["0.00001281","398200"],["0.00001293","9619000"],["0.00001306","394400"],["0.00001319","429200"],["0.00001333","375000"],["0.00001346","313200"],["0.00001359","409800"],["0.00001373","348000"],["0.00001387","317000"],["0.00001401","409800"],["0.00001415","460100"],["0.00001426","900800"],["0.00001429","355700"],["0.00001443","359600"],["0.00001457","363400"],["0.00001472","336400"],["0.00001487","324800"],["0.000015","100000"],["0.00001502","386600"],["0.00001517","429200"],["0.00001527","393100"],["0.00001549","12041100"],["0.00001573","3264400"],["0.00001576","12041200"],["0.00001598","3000000"],["0.0000165","4876600"],["0.00001668","500000"],["0.000017","100000"],["0.00001701","19337000"],["0.
    00001721","1000000"],["0.00001729","500000"],["0.0000175","20798800"],["0.00001771","300000"],["0.0000179","37893900"],["0.00001794","1144700"],["0.000018","5733700"],["0.0000185","27555600"],["0.00001861","1000000"],["0.00001873","320000"],["0.0000189","1000000"],["0.000019","17507300"],["0.0000195","38390600"],["0.0000197","2800000"],["0.00001975","73300"],["0.0000198","50323900"],["0.00001999","157400"],["0.00002","38132900"],["0.00002026","1432000"],["0.00002059","75000"],["0.00002062","45568900"],["0.00002094","49114800"],["0.000021","17342000"],["0.00002114","2610000"],["0.00002117","17100"],["0.00002163","100000"],["0.00002171","33900"],["0.0000218","100000"],["0.000022","59426600"],["0.00002202","41000"],["0.00002223","100000"],["0.0000227","100000"],["0.00002279","100000"],["0.0000229","100000"],["0.000023","5262000"],["0.00002301","2978500"],["0.00002314","100000"],["0.00002334","100000"],["0.00002394","100000"],["0.000024","47636400"],["0.00002429","100000"],["0.0000245","100000"],["0.00002458","389
    300"],["0.000025","123015400"],["0.0000255","100000"],["0.00002573","100000"],["0.00002678","100000"],["0.00002702","100000"],["0.000028","10006100"],["0.00002801","1326600"],["0.00002812","100000"],["0.00002813","36540500"],["0.00002837","100000"],["0.0000286","1870300"],["0.00002862","1200"],["0.00002874","2655700"],["0.00002899","100000"],["0.00002958","16769100"],["0.00003","15516800"],["0.00003044","100000"],["0.000033","1000000"],["0.00003494","2365600"],["0.00003512","4530000"],["0.000036","706100"],["0.0000369","32000"],["0.00003755","2365600"],["0.000038","39782400"],["0.00003868","2049200"],["0.000039","29604800"],["0.00004047","1453400"],["0.000042","1684700"],["0.00004299","7800"],["0.000043","795300"],["0.00004798","1000000"],["0.000048","3021700"],["0.00004904","300"],["0.00005","477000"],["0.000057","116600"],["0.00005804","5010000"],["0.00006","2141500"],["0.0000652","38345000"],["0.0000675","10291200"],["0.000068","24012300"],["0.00006847","1000000"],["0.000069","7903000"],["0.00007","15616700
    "],["0.00007019","22000"],["0.000073","13986200"],["0.000074","833000"],["0.00007447","27100"],["0.000075","1477400"],["0.00007692","60000"],["0.00007751","19000"],["0.0000789","7346700"],["0.00008","8219000"],["0.00008069","3125000"],["0.000082","369500"],["0.00008451","683400"],["0.000085","245800"],["0.000086","174500"],["0.00008898","1000000"],["0.0000905","1474000"],["0.000093","1400000"],["0.00009591","260000"],["0.000096","32500"],["0.00009844","333900"],["0.000099","1361400"],["0.0001","7065600"],["0.000101","13986100"]],"bids":[["0.00001121","45730900"],["0.00001113","444700"],["0.00001112","20771200"],["0.00001111","7300000"],["0.0000111","4507900"],["0.00001102","658900"],["0.000011","2027100"],["0.00001091","421500"],["0.00001081","378900"],["0.0000107","324800"],["0.00001059","328600"],["0.00001049","317000"],["0.00001038","429200"],["0.00001035","1000000"],["0.0000103","1000000"],["0.00001028","406000"],["0.0000102","700000"],["0.00001019","200000"],["0.00001018","351800"],["0.00001015","8172000"
    ],["0.0000101","20000000"],["0.00001008","309300"],["0.00001005","25641500"],["0.00001002","900000"],["0.00001001","100000"],["0.00001","79945500"],["0.00000998","452400"],["0.00000988","332500"],["0.0000098","700000"],["0.00000978","313200"],["0.00000968","332500"],["0.00000959","348000"],["0.00000957","16258000"],["0.0000095","1149800"],["0.00000949","394400"],["0.0000094","324800"],["0.00000936","14960700"],["0.00000931","309300"],["0.00000921","836400"],["0.0000092","28000"],["0.00000918","2200"],["0.00000915","1000000"],["0.00000912","313200"],["0.00000907","551200"],["0.00000903","324800"],["0.00000902","38351000"],["0.000009","2000"],["0.00000894","340200"],["0.00000888","200000"],["0.00000885","340200"],["0.00000877","398200"],["0.00000868","320900"],["0.00000859","363400"],["0.00000851","371200"],["0.00000842","375000"],["0.00000834","317000"],["0.00000821","1000000"],["0.000008","1122000"],["0.00000777","1955400"],["0.00000727","600000"],["0.00000666","200000"],["0.00000555","200000"],["0.00000521","
    3000000"],["0.00000507","1373800"],["0.000005","3400000"],["0.00000444","240000"],["0.00000334","1000000"],["0.00000333","330000"],["0.00000321","3000000"],["0.00000262","390000"],["0.00000232","440000"],["0.00000215","460000"],["0.00000202","500000"],["0.000002","50000"],["0.00000181","600000"],["0.00000161","700000"],["0.00000101","200000"],["0.000001","70515600"],["0.00000021","2380900"],["0.00000015","10000000"],["0.00000003","100000"],["0.00000002","136300"],["0.00000001","44200000"]],"seqNum":109373,"prevSeqNum":0,"lastTs":1644866922.885368},"id":249429570}
    Last edited by matty95srk; Feb 14th, 2022 at 03:51 PM.

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,685

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    In mine it prints a decimal comma, is this the reason?
    this is the Json i'm getting

    Code:
    {"error":null,"result":{"asks":[["0.00001137","302300"],["0.00001148","402100"],["0.00001159","448500"],["0.00001171","413700"],["0.00001183","344100"],["0.00001195","359600"],["0.00001206","386600"],["0.00001219","371200"],["0.00001231","344100"],["0.00001243","456300"],["0.00001255","398200"],["0.00001268","375000"],["0.00001281","398200"],["0.00001293","9619000"],["0.00001306","394400"],["0.00001319","429200"],["0.00001333","375000"],["0.00001346","313200"],["0.00001359","409800"],["0.00001373","348000"],["0.00001387","317000"],["0.00001401","409800"],["0.00001415","460100"],["0.00001426","900800"],["0.00001429","355700"],["0.00001443","359600"],["0.00001457","363400"],["0.00001472","336400"],["0.00001487","324800"],["0.000015","100000"],["0.00001502","386600"],["0.00001517","429200"],["0.00001527","393100"],["0.00001549","12041100"],["0.00001573","3264400"],["0.00001576","12041200"],["0.00001598","3000000"],["0.0000165","4876600"],["0.00001668","500000"],["0.000017","100000"],["0.00001701","19337000"],["0.
    00001721","1000000"],["0.00001729","500000"],["0.0000175","20798800"],["0.00001771","300000"],["0.0000179","37893900"],["0.00001794","1144700"],["0.000018","5733700"],["0.0000185","27555600"],["0.00001861","1000000"],["0.00001873","320000"],["0.0000189","1000000"],["0.000019","17507300"],["0.0000195","38390600"],["0.0000197","2800000"],["0.00001975","73300"],["0.0000198","50323900"],["0.00001999","157400"],["0.00002","38132900"],["0.00002026","1432000"],["0.00002059","75000"],["0.00002062","45568900"],["0.00002094","49114800"],["0.000021","17342000"],["0.00002114","2610000"],["0.00002117","17100"],["0.00002163","100000"],["0.00002171","33900"],["0.0000218","100000"],["0.000022","59426600"],["0.00002202","41000"],["0.00002223","100000"],["0.0000227","100000"],["0.00002279","100000"],["0.0000229","100000"],["0.000023","5262000"],["0.00002301","2978500"],["0.00002314","100000"],["0.00002334","100000"],["0.00002394","100000"],["0.000024","47636400"],["0.00002429","100000"],["0.0000245","100000"],["0.00002458","389
    300"],["0.000025","123015400"],["0.0000255","100000"],["0.00002573","100000"],["0.00002678","100000"],["0.00002702","100000"],["0.000028","10006100"],["0.00002801","1326600"],["0.00002812","100000"],["0.00002813","36540500"],["0.00002837","100000"],["0.0000286","1870300"],["0.00002862","1200"],["0.00002874","2655700"],["0.00002899","100000"],["0.00002958","16769100"],["0.00003","15516800"],["0.00003044","100000"],["0.000033","1000000"],["0.00003494","2365600"],["0.00003512","4530000"],["0.000036","706100"],["0.0000369","32000"],["0.00003755","2365600"],["0.000038","39782400"],["0.00003868","2049200"],["0.000039","29604800"],["0.00004047","1453400"],["0.000042","1684700"],["0.00004299","7800"],["0.000043","795300"],["0.00004798","1000000"],["0.000048","3021700"],["0.00004904","300"],["0.00005","477000"],["0.000057","116600"],["0.00005804","5010000"],["0.00006","2141500"],["0.0000652","38345000"],["0.0000675","10291200"],["0.000068","24012300"],["0.00006847","1000000"],["0.000069","7903000"],["0.00007","15616700
    "],["0.00007019","22000"],["0.000073","13986200"],["0.000074","833000"],["0.00007447","27100"],["0.000075","1477400"],["0.00007692","60000"],["0.00007751","19000"],["0.0000789","7346700"],["0.00008","8219000"],["0.00008069","3125000"],["0.000082","369500"],["0.00008451","683400"],["0.000085","245800"],["0.000086","174500"],["0.00008898","1000000"],["0.0000905","1474000"],["0.000093","1400000"],["0.00009591","260000"],["0.000096","32500"],["0.00009844","333900"],["0.000099","1361400"],["0.0001","7065600"],["0.000101","13986100"]],"bids":[["0.00001121","45730900"],["0.00001113","444700"],["0.00001112","20771200"],["0.00001111","7300000"],["0.0000111","4507900"],["0.00001102","658900"],["0.000011","2027100"],["0.00001091","421500"],["0.00001081","378900"],["0.0000107","324800"],["0.00001059","328600"],["0.00001049","317000"],["0.00001038","429200"],["0.00001035","1000000"],["0.0000103","1000000"],["0.00001028","406000"],["0.0000102","700000"],["0.00001019","200000"],["0.00001018","351800"],["0.00001015","8172000"
    ],["0.0000101","20000000"],["0.00001008","309300"],["0.00001005","25641500"],["0.00001002","900000"],["0.00001001","100000"],["0.00001","79945500"],["0.00000998","452400"],["0.00000988","332500"],["0.0000098","700000"],["0.00000978","313200"],["0.00000968","332500"],["0.00000959","348000"],["0.00000957","16258000"],["0.0000095","1149800"],["0.00000949","394400"],["0.0000094","324800"],["0.00000936","14960700"],["0.00000931","309300"],["0.00000921","836400"],["0.0000092","28000"],["0.00000918","2200"],["0.00000915","1000000"],["0.00000912","313200"],["0.00000907","551200"],["0.00000903","324800"],["0.00000902","38351000"],["0.000009","2000"],["0.00000894","340200"],["0.00000888","200000"],["0.00000885","340200"],["0.00000877","398200"],["0.00000868","320900"],["0.00000859","363400"],["0.00000851","371200"],["0.00000842","375000"],["0.00000834","317000"],["0.00000821","1000000"],["0.000008","1122000"],["0.00000777","1955400"],["0.00000727","600000"],["0.00000666","200000"],["0.00000555","200000"],["0.00000521","
    3000000"],["0.00000507","1373800"],["0.000005","3400000"],["0.00000444","240000"],["0.00000334","1000000"],["0.00000333","330000"],["0.00000321","3000000"],["0.00000262","390000"],["0.00000232","440000"],["0.00000215","460000"],["0.00000202","500000"],["0.000002","50000"],["0.00000181","600000"],["0.00000161","700000"],["0.00000101","200000"],["0.000001","70515600"],["0.00000021","2380900"],["0.00000015","10000000"],["0.00000003","100000"],["0.00000002","136300"],["0.00000001","44200000"]],"seqNum":109373,"prevSeqNum":0,"lastTs":1644866922.885368},"id":249429570}
    The Decimal Separator in that is ‘.’ A decimal point. The comma separates the strings

  26. #26
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,341

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by .paul. View Post
    The Decimal Separator in that is ‘.’ A decimal point. The comma separates the strings
    Pretty sure matt's post is two separate and distinct lines of thought. First, he is saying in response to Niya's reply that the result of running
    Code:
    Debug.WriteLine(My.Application.Culture.NumberFormat.NumberDecimalSeparator)
    is, as I suspected, a comma.

    Second, he is pointing out the JSON he is working with, where the decimal separator is a period.

    So I stand by my earlier post suggesting that as the reason for the exact code producing different results for Niya and matty.

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by .paul. View Post
    The Decimal Separator in that is ‘.’ A decimal point. The comma separates the strings
    the first was the answer to Niya question to execute
    Code:
    Debug.WriteLine(My.Application.Culture.NumberFormat.NumberDecimalSeparator)
    The second, was about the json I'm getting during debug.

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by OptionBase1 View Post
    Pretty sure matt's post is two separate and distinct lines of thought. First, he is saying in response to Niya's reply that the result of running
    Code:
    Debug.WriteLine(My.Application.Culture.NumberFormat.NumberDecimalSeparator)
    is, as I suspected, a comma.

    Second, he is pointing out the JSON he is working with, where the decimal separator is a period.

    So I stand by my earlier post suggesting that as the reason for the exact code producing different results for Niya and matty.

    exactly you are right for both assumption.

    About the comma, I'm tryint to set Cultureinfo.Invariantculture when I'm getting the data, like:

    Code:
      Private Sub OutputAsks(asks As String()())
            'VENDITE
            Dim contents As New StringBuilder
            For Each ask In asks
                contents.AppendLine(String.Join(" - ", ask))
            Next
    
            RichTextBox1.BeginInvoke(Sub()
                                         RichTextBox1.Text = contents.ToString((CultureInfo.InvariantCulture))
                                     End Sub)
        End Sub
    but I'm getting the error
    Overload resolution failed because no accessible 'ToString' accepts this number of arguments.
    :\

  29. #29
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,986

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    You are the same guy who asked the question here: https://stackoverflow.com/questions/...36034#71036034

    For context to everyone who is not matty95srk, I suggested the following:
    1. Have Visual Studio create the class definitions by using Paste Special > Paste as JSON
    2. Deserialize the JSON literal to the root object (I renamed the class to Payload in my example)
    3. Use reflection to get the properties of the Result class
    4. Loop over the properties and get the "last" (named last, not the last one in terms of order) property of the currently iterated property using the deserialized payload


    But you were insistent on not using my help.

    All of this could have been resolved by following my initial directions because there would be no need to parse the information in the RichTextBox since the value would have been stored as a property in the class.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by dday9 View Post
    You are the same guy who asked the question here: https://stackoverflow.com/questions/...36034#71036034

    For context to everyone who is not matty95srk, I suggested the following:
    1. Have Visual Studio create the class definitions by using Paste Special > Paste as JSON
    2. Deserialize the JSON literal to the root object (I renamed the class to Payload in my example)
    3. Use reflection to get the properties of the Result class
    4. Loop over the properties and get the "last" (named last, not the last one in terms of order) property of the currently iterated property using the deserialized payload


    But you were insistent on not using my help.

    All of this could have been resolved by following my initial directions because there would be no need to parse the information in the RichTextBox since the value would have been stored as a property in the class.


    David, what it has to do with this question? That's out of topic, I'm not asking how to parse Json in this question. Was that SO answer about sorting numbers in rtb and set cultureinfo? I don't think so.

    For a matter of clarification, I solved that question with 4 lines of codes instead of what there was going to be more than thousand since I told you I needed to parse lots of json lines. Also, before finding an easiest ( which doesn't mean better, just easiest from my knowledge ) solution by myself, you stated " Aside from the class definitions it is like 5 lines of code. I can't help you anymore at this point. –
    David
    Feb 10 at 14:56" so what are you pointing to? I don't understand.
    Last edited by matty95srk; Feb 14th, 2022 at 04:13 PM.

  31. #31
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,986

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    No, the two are related. You're showing data in the RichTextBox when it could be represented in the class.

    At that point, you could use LINQ against the class property value rather than trying to parse the values in your RichTextBox.

    You can simplify the process by having Visual Studio setup the class definitions for you and then you deserialize the JSON into the class representation -or- you can shortcut the deserialization portion and try to work with one large String blob like you're doing.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    To me, is enough to represent data in the richtextbox, it works easily and smooth, but still I don't understand the reason of your intervention here about the SO answer since that doesn't solve my actual problem of setting the culture info.

    p.s. Also, that was a different api with a different case
    so your statement
    All of this could have been resolved by following my initial directions because there would be no need to parse the information in the RichTextBox since the value would have been stored as a property in the class.
    doesn't make sense here, since for this API I NEED to store the informations in the richtextbox . Sorry David, your just reacted impulsively
    Last edited by matty95srk; Feb 14th, 2022 at 04:26 PM.

  33. #33
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,986

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    doesn't make sense here, since for this API I NEED to store the informations in the richtextbox . Sorry David, your just reacted impulsively
    To clarify, you want the data be stored in the RichTextBox but it is more efficient to do things with the data if you store the values in a class.

    Guess what? You can display data from your class in your RichTextBox and manipulate the data more efficiently by grabbing the data from the class.

    You're being a tete dur for no reason, but if you want to continue to spurn my help then by all means I will step out.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by dday9 View Post
    To clarify, you want the data be stored in the RichTextBox but it is more efficient to do things with the data if you store the values in a class.

    Guess what? You can display data from your class in your RichTextBox and manipulate the data more efficiently by grabbing the data from the class.

    You're being a tete dur for no reason, but if you want to continue to spurn my help then by all means I will step out.
    I believe you didn't even checked the API I'm using now. Do you think you can show me an example with the code of SO for this API? I would be happy to learn something new then. I don't need to manipulate basically anything, David. I'm just parsing numbers basically, and need to display them on richtextboxes, so I don't see the point to use classes ( but this can be not true so blame the lack of knowledge). By the way, this is a personal tool so the easiest the better, as far as it is working properly. I don't work with the code, I simply play with.
    Actually you helped me many times so I don't see the reason why you think I spurn your help. Btw, I repeat, all your soup doesn't solve the "cultureinfo" issue.

    It's not my aim to discuss here.
    I solved using
    Code:
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture
    since my app works on single thread only.
    Thanks to everybody who spent his time to help me, especially to Niya.

  35. #35
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,685

    Re: [vb.net] Sorting decimal in ascending order in richtextbox

    Quote Originally Posted by matty95srk View Post
    I believe you didn't even checked the API I'm using now. Do you think you can show me an example with the code of SO for this API? I would be happy to learn something new then. I don't need to manipulate basically anything, David. I'm just parsing numbers basically, and need to display them on richtextboxes, so I don't see the point to use classes ( but this can be not true so blame the lack of knowledge). By the way, this is a personal tool so the easiest the better, as far as it is working properly. I don't work with the code, I simply play with.
    Actually you helped me many times so I don't see the reason why you think I spurn your help. Btw, I repeat, all your soup doesn't solve the "cultureinfo" issue.

    It's not my aim to discuss here.
    I solved using
    Code:
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture
    since my app works on single thread only.
    Thanks to everybody who spent his time to help me, especially to Niya.
    It's simple...

    You get the JSon Object
    Deserialize to classes
    Sort your data,
    Then... display the sorted data in your RTB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width