From: Shell on
Nice, clean, elegant, short and understandable. Thanks.

I need to study it some more to evaluate how effective it is.
--
Shell


"Mike S" wrote:

> On 6/2/2010 8:28 AM, Shell wrote:
> > In VB6 I have an application where I have 7 characters (numbers and/or
> > letters). I need to generate a list (probably in a database) on all possible
> > combinations of 3, 4, 5, 6, and 7 characters.
> >
> > I keep getting mixed up, trying recursive functions, which I hate. Does
> > anyone have a simpler way of doing this?
> >
> > Thanks
>
> Avoiding recursion I think you can do it this way, to keep it simple you
> can use a separate sub for each different length string, how does this
> look? Using this approach, to make a string 4 chars long you could use a
> new variable n, etc. for longer strings. Is this what you were looking for?
>
> Option Explicit
>
> Private chars() As String, results() As String
>
> Private Sub btnMakeString3_Click()
> On Error GoTo btnMakeString3Err
> Dim j As Long, k As Long, m As Long, ctr As Long
> ctr = 1
> ReDim results(1 To 7 ^ 3)
> Text1.Visible = False
> Text1.Text = ""
> For j = 1 To 7
> For k = 1 To 7
> For m = 1 To 7
> results(ctr) = chars(j) & chars(k) & chars(m)
> Text1.Text = Text1.Text & results(ctr) & vbCrLf
> ctr = ctr + 1
> Next
> Next
> Next
> Text1.Visible = True
> DoEvents
> Exit Sub
> '
> btnMakeString3Err:
> MsgBox "Error " & Err.Number & " " & Err.Description
> End Sub
>
> Private Sub Form_Load()
> ReDim chars(1 To 7)
> chars(1) = "0"
> chars(2) = "1"
> chars(3) = "2"
> chars(4) = "3"
> chars(5) = "4"
> chars(6) = "5"
> chars(7) = "6"
> End Sub
> .
>
From: Larry Serflaten on

"Shell" <Shell(a)discussions.microsoft.com> wrote
> In VB6 I have an application where I have 7 characters (numbers and/or
> letters). I need to generate a list (probably in a database) on all possible
> combinations of 3, 4, 5, 6, and 7 characters.
>
> I keep getting mixed up, trying recursive functions, which I hate. Does
> anyone have a simpler way of doing this?

See if this helps: (quick response, no error checks, test as needed...)

LFS

Private Sub Form_Load()
Dim itm

For Each itm In Permute("A1B2C3D", 3)
Debug.Print itm
Next
End Sub

Function Permute(List As String, Length As Long) As Collection
Dim max As Long, idx As Long, ltr As Long
Dim txt As String
' Returns a collection of strings that are <Length> characters long
' containing all possible combinations of <List> characters

max = Len(List)
ReDim p(0 To Length) As Long
Set Permute = New Collection

txt = String(Length, " ")
For idx = 1 To Length
p(idx) = 1
Next

idx = Length
While idx > 0
For ltr = 1 To Length
Mid(txt, ltr, 1) = Mid(List, p(ltr), 1)
Next
Permute.Add txt
idx = Length
p(idx) = p(idx) + 1
While p(idx) > max
p(idx) = 1
idx = idx - 1
p(idx) = p(idx) + 1
Wend
Wend

End Function


From: Nobody on
"Shell" <Shell(a)discussions.microsoft.com> wrote in message
news:E24A0B73-B3CF-4A57-A616-8A1526FD8220(a)microsoft.com...
> In VB6 I have an application where I have 7 characters (numbers and/or
> letters). I need to generate a list (probably in a database) on all
> possible
> combinations of 3, 4, 5, 6, and 7 characters.
>
> I keep getting mixed up, trying recursive functions, which I hate. Does
> anyone have a simpler way of doing this?

Sounds like a password guesser app.


From: Dave O. on
Nice, clean, elegant, short and wrong.

you must ignore permutations where (in this example) j, k or m are the same,
try adding:

if (j <> k) and (k <> m) then
results(ctr) = chars(j) & chars(k) & chars(m)
ctr = ctr + 1
end if

also this line could be quite slow
Text1.Text = Text1.Text & results(ctr) & vbCrLf

If you want the results in a text box you'd be better of filling it in a
loop at the end.

Regards
Dave O.

"Shell" <Shell(a)discussions.microsoft.com> wrote in message
news:52B4FA27-F0D0-42AE-9D95-F07B5712DC4C(a)microsoft.com...
> Nice, clean, elegant, short and understandable. Thanks.
>
> I need to study it some more to evaluate how effective it is.
> --
> Shell
>
>
> "Mike S" wrote:
>
>> On 6/2/2010 8:28 AM, Shell wrote:
>> > In VB6 I have an application where I have 7 characters (numbers and/or
>> > letters). I need to generate a list (probably in a database) on all
>> > possible
>> > combinations of 3, 4, 5, 6, and 7 characters.
>> >
>> > I keep getting mixed up, trying recursive functions, which I hate.
>> > Does
>> > anyone have a simpler way of doing this?
>> >
>> > Thanks
>>
>> Avoiding recursion I think you can do it this way, to keep it simple you
>> can use a separate sub for each different length string, how does this
>> look? Using this approach, to make a string 4 chars long you could use a
>> new variable n, etc. for longer strings. Is this what you were looking
>> for?
>>
>> Option Explicit
>>
>> Private chars() As String, results() As String
>>
>> Private Sub btnMakeString3_Click()
>> On Error GoTo btnMakeString3Err
>> Dim j As Long, k As Long, m As Long, ctr As Long
>> ctr = 1
>> ReDim results(1 To 7 ^ 3)
>> Text1.Visible = False
>> Text1.Text = ""
>> For j = 1 To 7
>> For k = 1 To 7
>> For m = 1 To 7
>> results(ctr) = chars(j) & chars(k) & chars(m)
>> Text1.Text = Text1.Text & results(ctr) & vbCrLf
>> ctr = ctr + 1
>> Next
>> Next
>> Next
>> Text1.Visible = True
>> DoEvents
>> Exit Sub
>> '
>> btnMakeString3Err:
>> MsgBox "Error " & Err.Number & " " & Err.Description
>> End Sub
>>
>> Private Sub Form_Load()
>> ReDim chars(1 To 7)
>> chars(1) = "0"
>> chars(2) = "1"
>> chars(3) = "2"
>> chars(4) = "3"
>> chars(5) = "4"
>> chars(6) = "5"
>> chars(7) = "6"
>> End Sub
>> .
>>


From: Shell on
No, it is not a password checker. But in the future it might be. Right now
I'm trying to find valid words in the group of possibilities.
--
Shell


"Nobody" wrote:

> "Shell" <Shell(a)discussions.microsoft.com> wrote in message
> news:E24A0B73-B3CF-4A57-A616-8A1526FD8220(a)microsoft.com...
> > In VB6 I have an application where I have 7 characters (numbers and/or
> > letters). I need to generate a list (probably in a database) on all
> > possible
> > combinations of 3, 4, 5, 6, and 7 characters.
> >
> > I keep getting mixed up, trying recursive functions, which I hate. Does
> > anyone have a simpler way of doing this?
>
> Sounds like a password guesser app.
>
>
> .
>
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Tom Shelton ...
Next: Instr problem in VB5