As suggested by @Richard-MacCutchan, build an array, sort it ("ascending order" is in your requirements), join them into a single string and add it to the text box. Here is a working example in VBA. It's very similar to VB6 and I don't have VB6 any more - it went out of support decades ago.
Dim m As Integer
m = Me.Controls.Count
ReDim TheArray(m) As String
Dim cBox As Object, index As Integer
index = 0
For Each cBox In Me.Controls
Debug.Print TypeName(cBox), cBox.Value
If TypeName(cBox) = "CheckBox" Then
If cBox.Value = True Then
TheArray(index) = cBox.Name
index = index + 1
End If
End If
Next
ReDim Preserve TheArray(index - 1)
SortArray TheArray
Dim s As String
s = Join(TheArray, vbCrLf)
Me.TextBox1.Text = s
Note because I have joined the string using carriage return/linefeeds the text box will need to have Multi-line property = True.
Now let's address the elephant in the room...
Quote:
i am new in vb6.0.
If you are learning VB6 so that you can maintain (or rewrite) a legacy system then fair enough. But if you are learning VB6 for
any other reason then please stop. VB6 is ancient technology. You would be far better off learning one of the .NET languages - and they are free to download. The transition from VB6 to VB.NET is not hard, but is not advised as you will miss out on the new way of doing things, and probably have to "unlearn" a lot of bad habits (I did it that way and have regretted it many times since)
Edit: Here is an example of sorting an array adapted from -
FreeVBCode code snippet: Simplified Array Sorting[
^]
Public Sub SortArray(ByRef TheArray As Variant)
Dim Sorted As Boolean
Sorted = False
Do While Not Sorted
Sorted = True
Dim X As Long, Temp As Variant
For X = 0 To UBound(TheArray) - 1
If TheArray(X) > TheArray(X + 1) Then
Temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = Temp
Sorted = False
End If
Next X
Loop
End Sub
Edit: The full set of code that will produce the results as described
Sub chkcheck()
Dim m As Integer
m = Me.Controls.Count
ReDim TheArray(m) As String
Dim cBox As Object, index As Integer
index = 0
For Each cBox In Me.Controls
Debug.Print TypeName(cBox), cBox.Value
If TypeName(cBox) = "CheckBox" Then
If cBox.Value = True Then
TheArray(index) = cBox.Caption
index = index + 1
End If
End If
Next
ReDim Preserve TheArray(index - 1)
SortArray TheArray
Dim s As String
s = Join(TheArray, ",")
Me.TextBox1.Text = s
End Sub
Public Sub SortArray(ByRef TheArray As Variant)
Dim Sorted As Boolean
Sorted = False
Do While Not Sorted
Sorted = True
Dim X As Long, Temp As Variant
For X = 0 To UBound(TheArray) - 1
If TheArray(X) > TheArray(X + 1) Then
Temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = Temp
Sorted = False
End If
Next X
Loop
End Sub