i have 15 checkboxes in vb6.0 form. i want to display selected checkbox value in sort order in single textbox. i have tried using below code but one issue is comma display after last value. i want to just display in which two value like 1,2 if selected value is only one like 1 then comma should not be display prefex or sufix.
also value should be display in sort order like 1,4,7,8 etc.
kindly help me to solve this i have many tried but still not resolved and its urgent.
Sub cBoxSelection()
Dim m As Integer
m = Me.Controls.Count
ReDim TheArray(m) As String 'Max size the array will be
Dim cBoxes As Object, Index As Integer
Index = 0
For Each cBoxes In Me.Controls
'Debug.Print TypeName(cBoxes), cBoxes.Value
If TypeName(cBoxes) = "CheckBox" Then
If cBoxes.Value = 1 Then
TheArray(Index) = cBoxes.Caption
Index = Index + 1
End If
End If
Next
ReDim Preserve TheArray(Index) 'Get rid of the empty spaces
'SortArray TheArray
Dim s As String
s = Join(TheArray, ",")
Me.Text2.Text = s
End Sub
Public Sub SortArray(ByRef TheArray As Variant)
Dim Sorted As Boolean
Sorted = True
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 = True
End If
Next X
Loop
End Sub