Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through al possible strings

Status
Not open for further replies.
Mar 27, 2002
168
NL
Hi all,

Using Access 2002
there is a field for the company. I want to save the company in clearer way.
E.g. the name is The Pipefactory Next Door, I want to rewrite this by Pipefactory, Next Door The.
I want to make a list with all possibilities and let the user choose. So there are 4! = 24 possible strings
I think there must be something like
splitter = split(company.value, " ")
for i = 0 to factorial(Ubound(splitter)+1)-1
'code in here
next i
But I can't create a simple way to loop through all the strings and put them in a listbox
someone who have an idea for the algoritm.
Thnx in advance,

Gerard
 
Hi Gerard!

Yor solution seems me too difficult for user. I proffer you other way if you want to allow user to change word places on string.
Create on form an unbound list box (row source type=Value List); two text boxes - the first one related to table field, but other one - unbound; two command buttons: first one for reset changes, but other one - for field updating.

Look at following code. By mouse double cklick on list box, which shows all words in the string (current field value) user can compose new string by himself (I think it is better that to show lots of string varios string for choosing.

Private Sub cmdReset_Click()
'cmdReset >>> command button
'Updates new string to zero length

Me.txtNewString = ""
End Sub
'--------------------------------------
Private Sub cmdUpdate_Click()
Dim arr
Dim i As Integer

arr = Split(Me.txtNewString, " ")

'Compare the new string
'If word count is lesser than word count in the source string
'field isn't updated

If UBound(arr) < Me.lstString.ListCount - 1 Then
MsgBox &quot;You didn't add all words in new string...&quot;
Else
Me.txtOldString = Me.txtNewString
End If
End Sub
'--------------------------------------
Private Sub Form_Current()
'Updates list box with words of current field value (string)
'txtOldString >>> current field value

Me.lstString.RowSource = ListOfString(Trim(Me.txtOldString))
End Sub
'--------------------------------------
Private Sub lstString_DblClick(Cancel As Integer)
Dim arr
Dim i As Integer

arr = Split(Me.txtNewString, &quot; &quot;)

'Compare new string
'If string length or word count is greater than source string
'selected word isn't added to new string

If UBound(arr) < Me.lstString.ListCount - 1 And _
InStr(1, Me.txtNewString, Me.lstString, vbTextCompare) = 0 Then
'Adds word from list box to new string
Me.txtNewString = Trim(Me.txtNewString) & &quot; &quot; & Trim(Me.lstString)
End If
End Sub

'--------------------------------------
'--------------------------------------
Function ListOfString(ByVal strString As String)
'Function returns string based on source string for list box
Dim arr
Dim i As Integer
Dim strTemp As String

arr = Split(strString, &quot; &quot;)
For i = LBound(arr) To UBound(arr)
If strTemp <> &quot;&quot; Then
strTemp = strTemp & &quot;;&quot;
End If
strTemp = strTemp & arr(i)
Next i
ListOfString = strTemp
End Function


So user can order words in the string how he wants. Hereto only one time each word can be included into new string.

Aivars
[pipe]
 
It looks great! Can need it anyway, good string manipulation.
I'm not sure if it's enough for my users. They prefer ease ;)
But I'll try, maybe with a little change in code,

Thnx anyway!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top