Question

In: Computer Science

How do I make this sort in true alphabetical order instead of ascii(ABCabc) order? I am...

How do I make this sort in true alphabetical order instead of ascii(ABCabc) order? I am trying to get AaBbCc. Currently I get ABCabc. please help... here is the code using VB:

Public Class frmTransfer

    Dim strSortArray() As String

    Private Sub txtInput_TextChanged(sender As Object, e As EventArgs) Handles txtInput.TextChanged

        Dim intUpper As Integer

        Dim intCount As Integer

        intUpper = Len(txtInput.Text) - 1       REM -1 because array starts at 0

        For Each chr As Char In txtInput.Text       REM for each chr(character) entered as a character in the text box

            If ((Asc(chr) > 64) And (Asc(chr) < 91)) Or ((Asc(chr) > 96) And (Asc(chr) < 123)) Or ((Asc(chr) > 31) And (Asc(chr) < 65)) Then     REM If the character entered is a letter

                ReDim Preserve strSortArray(intUpper)           REM preservers previous data and adds new slot to array

                strSortArray(intCount) = chr            REM sets the array at position intCount equal to chr

                intCount = intCount + 1                 REM increases intCount by 1

            End If

        Next chr

    End Sub

    Private Sub btnTransfer_Click(sender As Object, e As EventArgs) Handles btnTransfer.Click

        Dim X As Integer

        Dim Y As Integer

        Dim temp As String

        For X = LBound(strSortArray) To (UBound(strSortArray) - 1)

            For Y = LBound(strSortArray) To (UBound(strSortArray) - 1)

                If Asc(strSortArray(Y)) > Asc(strSortArray(Y + 1)) Then

                    ' exchange the items

                    temp = strSortArray(Y)

                    strSortArray(Y) = strSortArray(Y + 1)

                    strSortArray(Y + 1) = temp

                End If

            Next Y

        Next X

        lblOutput.Text = String.Join("", strSortArray)

    End Sub

End Class

Solutions

Expert Solution

I Have modified the code as below. Basically you need to add the inbuilt function Array.Sort(strSortArray)

Public Class frmTransfer

    Dim strSortArray() As String

    Private Sub txtInput_TextChanged(sender As Object, e As EventArgs) Handles txtInput.TextChanged

        Dim intUpper As Integer

        Dim intCount As Integer

        intUpper = Len(txtInput.Text) - 1       REM -1 because array starts at 0

        For Each chr As Char In txtInput.Text       REM for each chr(character) entered as a character in the text box

            If ((Asc(chr) > 64) And (Asc(chr) < 91)) Or ((Asc(chr) > 96) And (Asc(chr) < 123)) Or ((Asc(chr) > 31) And (Asc(chr) < 65)) Then     REM If the character entered is a letter

                ReDim Preserve strSortArray(intUpper)           REM preservers previous data and adds new slot to array

                strSortArray(intCount) = chr            REM sets the array at position intCount equal to chr

                intCount = intCount + 1                 REM increases intCount by 1

            End If

        Next chr

    End Sub

    Private Sub btnTransfer_Click(sender As Object, e As EventArgs) Handles btnTransfer.Click

        Dim X As Integer

        Dim Y As Integer

        Dim temp As String

        For X = LBound(strSortArray) To (UBound(strSortArray) - 1)
            Array.Sort(strSortArray)

        Next X

        lblOutput.Text = String.Join("", strSortArray)

    End Sub

End Class

OUTPUT


Related Solutions

how do I make a histogram. I am using the example from the book Essentials of...
how do I make a histogram. I am using the example from the book Essentials of Statistics Chapter 2.2, Problem 9BSC.
How would I make a bubble sort and an optimized bubble sort with the code given?...
How would I make a bubble sort and an optimized bubble sort with the code given? I also need to implement a timer into each sort and display runtime with the sorts. NODE.H _______________________________________________________________________________________________________ /* node.h */ /* two classes 1: node.h 2. singlylinkedlist.h nod1 (value + pointer) ---> node2 ---> node3 ---> |||| <--- node.h ^ | singlylinkedlist ----------------*node head; */ #ifndef NODE_H #define NODE_H #include <iostream> using namespace std; class Node {    friend class singlyLinkedList; public:   ...
Modify the quicksort algorithm such that it uses the last item as the pivot instead of the 1st. Also, sort in descending order, instead of ascending order.
Programming Language : JavaModify the quicksort algorithm such that it uses the last item as the pivot instead of the 1st. Also, sort in descending order, instead of ascending order.NOTE: Do not move the last element into the first element of the array. You must treat the algorithm as if the pivot is actually sitting in the last location of the array.After it has been sorted in descending order, go through all the items in the array and make sure...
How do I use ASCII code to generate and display two random letters that are one...
How do I use ASCII code to generate and display two random letters that are one lowercase and one uppercase in C++? Please give me an example.  
I am not understanding how to do this in excel, I have half of it, but...
I am not understanding how to do this in excel, I have half of it, but not sure where to put the 1100, 2900, 2400, 1500. Questions asked are a plus. M4_A1. Edsel Motors produces cars in Los Angeles and Detroit. The company supplies cars to customers in Houston and Tampa. The costs of shipping a car between various points shown in the table below. The dashes in the table indicate a shipment between locations that is not allowed. Los...
Excel sorting In excel how do you sort a column of months in ascending order and...
Excel sorting In excel how do you sort a column of months in ascending order and not alphabetical when the month is in word format?
i have an array of strings, how do i sort them into a binary tree? C...
i have an array of strings, how do i sort them into a binary tree? C Program
I need to write a sort one paper page for a marketing research course I am...
I need to write a sort one paper page for a marketing research course I am taking. Could someone help me think of different ways to answer the following scenario? Thanks! Quantitative data may be more familiar to most people as we see numbers, figures, and percentages in the media every day. Still, data can be interpreted differently. Here is a short scenario for you: We look at the grade chart provided by Jefferson College. A, B, C, D, and...
How do I make the series graph
How do I make the series graph
I am working as a cashier at Home Depot. The question is How do I use...
I am working as a cashier at Home Depot. The question is How do I use accounting in my life and my work? Does my work involve using financial accounting or managerial accounting reports?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT