juanjespar
Goto Top

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!

Content-Key: 119072

Url: https://administrator.de/contentid/119072

Printed on: April 25, 2024 at 19:04 o'clock

Member: JuanJespar
JuanJespar Jun 25, 2009 at 15:31:10 (UTC)
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
Member: bastla
bastla Jun 25, 2009 at 15:33:01 (UTC)
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