Results 1 to 2 of 2

Thread: vb6 pattern generation

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Question vb6 pattern generation

    I just needed to create all possible combination of 3 lettered alphanumeric string i nthe following set,(a-z), (0-9), and minus(-)..
    int his pattern,
    aaa
    aab
    aac
    aad and so on.
    and store it to some file. and then when I just copy to clipboard, then 1 to 99 of them has to be copied to the clipboard ready to be pasted in other applications, and then the pointer has to move to the 100th string, and another textbox should display what is copied last that is 99th string..

    how do i do this in vb6..
    any help???

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Re: vb6 pattern generation

    Here's an example of generating the combinations:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4.  
    5. Private m_flgStop As Boolean
    6.  
    7. Private Sub cmdGo_Click()
    8.   Dim strChars() As String
    9.   Dim lngLetters() As Long
    10.   Dim lngLetter As Long
    11.   Dim lngLetterReset As Long
    12.   Dim lngMaxChar As Long
    13.   Dim flgIncremented As Boolean
    14.   Dim strCombo As String
    15.   Dim lngComboCount As Long
    16.  
    17.   ' Keep a flag indicating whether the
    18.   ' process should be stopped before it's finished
    19.   m_flgStop = False
    20.  
    21.   ' Create an array of characters to get the combinations of
    22.   strChars = Split( _
    23.     "A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;" & _
    24.     "P;Q;R;S;T;U;V;W;X;Y;Z;" & _
    25.     "0;1;2;3;4;5;6;7;8;9;-", ";")
    26.    
    27.   ' Get the number of characters being used
    28.   lngMaxChar = UBound(strChars)
    29.  
    30.   ' Create an array representing the number of digits
    31.   ' to find combinations of, in this case 3 (Zero based.)
    32.   ReDim lngLetters(2)
    33.   Do
    34.     ' Build a string showing the current combination
    35.     strCombo = ""
    36.     For lngLetter = 0 To UBound(lngLetters)
    37.       strCombo = strCombo & strChars(lngLetters(lngLetter))
    38.     Next
    39.     ' Increment the combination counter and
    40.     ' Display the combination in the form label
    41.     lngComboCount = lngComboCount + 1
    42.     lblCombination.Caption = strCombo
    43.     ' Pause (Added for Demo purposes)
    44.     DoEvents
    45.     Sleep (10) ' Alter this to slow down/speed up the process
    46.     ' Reset the "Has anything incremented" flag
    47.     flgIncremented = False
    48.     ' Enumerate each digit in the combination from right to left
    49.     For lngLetter = UBound(lngLetters) To 0 Step -1
    50.       ' If this digit's current character isn't the last
    51.       ' in the list to get combinations of...
    52.       If lngLetters(lngLetter) < lngMaxChar Then
    53.         ' Increment this digit's character
    54.         lngLetters(lngLetter) = lngLetters(lngLetter) + 1
    55.         ' Indicate that one of the digits was incremented
    56.         flgIncremented = True
    57.         ' If this isn't the last digit, reset the digits
    58.         ' following this one when this digit is incremented
    59.         If lngLetter < UBound(lngLetters) Then
    60.           For lngLetterReset = lngLetter + 1 To UBound(lngLetters)
    61.             lngLetters(lngLetterReset) = 0
    62.           Next
    63.         End If
    64.         ' Because something was incremented, don't
    65.         ' increment any other digits at this time
    66.         Exit For
    67.       End If
    68.     Next
    69.  
    70.   ' Keep going until all the digits have
    71.   ' the last character or the process is canceled
    72.   Loop While flgIncremented And Not m_flgStop
    73.    
    74.   ' Show the no. of combinations created
    75.   Caption = lngComboCount & " Combinations"
    76. End Sub
    77.  
    78. Private Sub cmdStop_Click()
    79.   ' Indicate that we want to stop the process
    80.   m_flgStop = True
    81. End Sub
    Regards,

    - Aaron.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width