juanjespar

Sortieren von eine Textbox in VB6 (nach ascii) wie Bubblesort ohne Array nur

Hallo Liebes Foum,
wieder mal ein kleines Problem was bestimmt ziemlich leicht zu lösen ist (VB)

Ich möchte gern eine TextBox die mit einem Text befüllt ist ( http://juanjespar.dyndns.org/upload/Text.JPG )
sortieren, und zwar der reihenfolge nach wie die Zeichen in Ascii sind ( http://juanjespar.dyndns.org/upload/Sort.JPG )

Hoffe das ist gut erklärt was ich möchte.

Hier noch mein mom. Code (is eh falsch)

Option Explicit

Private Sub btsortieren_Click()
Dim iLauf As Integer, intZeileA As Integer, IntZeileB As Integer
Dim strText As String
Dim strTextinhalt As String
Dim Pruefen As Boolean
Dim test As Integer

strText = tbtext.Text
    For iLauf = 1 To Len(strText)
        Pruefen = True
            intZeileA = Asc(Mid(strText, iLauf, 1))
            IntZeileB = intZeileA + 1
                If intZeileA < IntZeileB Then
                    test = Asc(Mid(strText, intZeileA, 1))
                    intZeileA = IntZeileB
                    strTextinhalt = strTextinhalt & Chr(test)
'                    strTextinhalt = Chr(IntZeileB) + strTextinhalt  
                End If
    Next iLauf
    tbtext.Text = strTextinhalt
End Sub

Private Sub btcancel_Click()
    End
End Sub

'                strTextinhalt = Chr(intZeileA)  
'                Chr(intZeileA) = Chr(IntZeileB)  
'                Chr(IntZeileB) = strTextinhalt  


Schonmal ielen lieben dank an Die, die Helfen können!
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 119072

Url: https://administrator.de/forum/sortieren-von-eine-textbox-in-vb6-nach-ascii-wie-bubblesort-ohne-array-nur-119072.html

Ausgedruckt am: 23.06.2025 um 16:06 Uhr

JuanJespar
JuanJespar 25.06.2009 um 17:31:10 Uhr
Goto Top
Hier die antwort

Option Explicit

Private Sub btsortieren_Click()
Dim iLauf As Integer
Dim strText As String
Dim strTextinhalt As String
Dim Pruefen As Boolean
Dim intLaenge As Integer
Dim strErgebniss As String

strText = tbtext.Text
    For iLauf = 33 To 255
        Pruefen = True
                For intLaenge = 1 To Len(strText)
                    If Asc(Mid(strText, intLaenge, 1)) = iLauf Then
                    strErgebniss = strErgebniss & Chr(iLauf)
                    End If
                Next intLaenge
        Pruefen = False
    Next iLauf
    strTextinhalt = strTextinhalt & strErgebniss
    tbtext.Text = strTextinhalt
End Sub

Private Sub btcancel_Click()
    End
End Sub
bastla
bastla 25.06.2009 um 17:33:01 Uhr
Goto Top
Hallo JuanJespar!

Versuch es damit (weil Du ja "Bubblesort" wolltest):
strText = tbtext.Text
'Sortieren  
N = Len(strText)
For i = 1 To N - 1
    For j = 1 To N - 1
        If Mid(strText, j, 1) > Mid(strText, j + 1, 1) Then
            Mid(strText, j, 2) = Mid(strText, j + 1, 1) & Mid(strText, j, 1)
        End If
    Next 'j  
Next 'i  
strText = Trim(strText)

'Gruppieren  
i = 1
Do
    If Mid(strText, i, 1) <> Mid(strText, i + 1, 1) Then
        strText = Left(strText, i) & " " & Mid(strText, i + 1)  
        i = i + 1
    End If
    i = i + 1
Loop While i < Len(strText)
tbtext.Text = strText
Grüße
bastla