Mixing Number... help!

alexkong2003

Registered User.
Local time
Tomorrow, 06:13
Joined
Sep 4, 2006
Messages
95
Hi,

Good Afternoon!

I have bounded field call "MixNumber".... Actually is my customer request me to do a Mixing Number function on it... for an example, while i key in a number '1234' then a message box will pop out and ask whether I want to store it as a single no. or mix no., if i click mix no. the my table will automatically store the no. of mixing 1234,2134,3124,4321 and etc... mixing all together are 24 no.

So now my question is how to do that automatically? could anyone help?

Thanks!
 
So if I understand you correctly, instead of having a message box popup offering you a choice, you just want to convert all the numbers In the table as is correct?
 
Yes, you r right Mr Uncle Gizmo~~~ if anyway could do it with the correct mixing of the sample no. 1234 together are 24 set of them and that will be perfect... i just wonder is there any of the code in Access could do it?

Thanks for the reply anyway.
 
Anybody could give me a hand please, i had struggling this problem for 2 weeks already... and haven't comes out a solution~~~

Million Thanks for the one who could help me to solve the problem!!
 
Anybody could give me a hand please, i had struggling this problem for 2 weeks already... and haven't comes out a solution~~~

Million Thanks for the one who could help me to solve the problem!!

So, let me see if I understand the situation.

1. you have numbers in a table

2. you want to be able to get all possible combinations of the number in a record. So, if you had 1234 in the table you also want all combinations of those four numbers 1324, 1423, 2134, etc.

Is that correct?
 
Thanks for the reply larson~~

yes, you r right~~~ I would like to do the possible combination of the a number and store all of them to the table automatically by the program.

i had search all over the threads and the internet as well but still can't get any of the idea how to do it...

Thanks.
 
Thanks for the reply larson~~

yes, you r right~~~ I would like to do the possible combination of the a number and store all of them to the table automatically by the program.

i had search all over the threads and the internet as well but still can't get any of the idea how to do it...

Thanks.

I can't guarantee anything but I'll ponder it and, if nobody comes up with the answer before I can get to it, I'll work on it. I am going to bed now, as it is late, so it won't be for a while.
 
ok... thank you for trying for a help... really appreciate on your consideration for helping me..
 
Alex,

Rough sample attached.


Wouldn't mind making it more general-purpose, but it's the weekend and
I gotta go play.

hth,
Wayne
 

Attachments

Alex,

Rough sample attached.


Wouldn't mind making it more general-purpose, but it's the weekend and
I gotta go play.

hth,
Wayne

Thanks Wayne - I haven't looked at it yet, but your help is appreciated as I haven't been able to get my mind completely around it yet.
 
Bob,

Well, I did go play for a while.

There is a general-purpose recursive solution though ...

Not tonight though.

See ya,
Wayne
 
Oh Well,

Boy it's tough to think recursively on the weekend!

Code:
Private Sub txtSeed_AfterUpdate()
  Me.txtResults = ""
  Me.txtResults = fnGetTerm("", Me.txtSeed)
End Sub

Private Function fnGetTerm(First As String, Last As String) As String
Dim Temp As String
Dim Result As String
Dim i As Long

Select Case Len(Last)
   Case 5
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), "")) & _
             fnGetTerm(First & Mid(Last, 4, 1), Replace(Last, Mid(Last, 4, 1), "")) & _
             fnGetTerm(First & Mid(Last, 5, 1), Replace(Last, Mid(Last, 5, 1), ""))
   Case 4
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), "")) & _
             fnGetTerm(First & Mid(Last, 4, 1), Replace(Last, Mid(Last, 4, 1), ""))
   Case 3
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), ""))
   Case 2
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), ""))
   Case 1
      Me.txtResults = Me.txtResults & First & Last & vbCrLf
      fnGetTerm = First & Last & vbCrLf
      Exit Function
   
   End Select

End Function

Wayne
 
Hi,

Thank for the precious reply wayne~~~ Finally i got some idea continue my code already ~~~~ but i found some problem on it...

when user key in 4 different no. the code work prefectly , but when a duplicate no. appear (exp 1123, 2224) then the combination getting problem already !~~~

I know it is really a tough work... but i still can't stop putting my hand together to u ....
Thank you!
 
Alex,

The s/w uses this to remove the second character.
It essentially replaces all occurences of itself with "".

Replace(Last, Mid(Last, 2, 1), "")

To support Multiple characters the replace becomes an explicit Mid statement.

Replace(Last, Mid(Last, 2, 1), "") now translates to

Mid(Last, 1, 1) & Mid(Last(3, 2))

Personally, I'd use the second model of s/w that I posted.
It's quite a few "replacements", but it should work OK.

Wayne
 
Wayne,

I had try to replace those Replace(Last, Mid(Last, 2, 1), "") by Mid(Last, 1, 1) & Mid(Last(3, 2)) but the code still not work....

Could you please just show me how is the code work?

Thanks
 
Alex,

I just ran this and it works.

Basically it's a recursive procedure.

Each iteration it is passed a First & Last string.

If the Last string is 1-character, it returns a value.

Otherwise, it calls itself with a new First & Last.

This is how it flows

Code:
First   Last
=====   ====
""      1234   <-- One Call

1       234    <-- Turns into 4 Calls
2       134
3       124
4       123

12      34     <-- Turns into 12 calls
13      42
14      23
21      34
23      14
24      13
31      24
32      14
34      12
41      23
42      13
43      12

123     4     <-- Turns into 24 return values
124     3
134     2
132     4
142     3
143     2
213     4
214     3
231     4
234     1
241     3
243     1
312     4
314     2
321     4
324     1
341     2
342     1
412     3
413     2
421     3
423     1
431     2
432     1


Code:
Private Sub txtSeed_AfterUpdate()
  Me.txtResults = ""
  Me.txtResults = fnGetTerm("", Me.txtSeed)
End Sub

Private Function fnGetTerm(First As String, Last As String) As String
Dim Temp As String
Dim Result As String
Dim i As Long

Select Case Len(Last)
   Case 5
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), "")) & _
             fnGetTerm(First & Mid(Last, 4, 1), Replace(Last, Mid(Last, 4, 1), "")) & _
             fnGetTerm(First & Mid(Last, 5, 1), Replace(Last, Mid(Last, 5, 1), ""))
   Case 4
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), "")) & _
             fnGetTerm(First & Mid(Last, 4, 1), Replace(Last, Mid(Last, 4, 1), ""))
   Case 3
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), ""))
   Case 2
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), ""))
   Case 1
      Me.txtResults = Me.txtResults & First & Last & vbCrLf  <-- If the "Last" string is 1-char
      fnGetTerm = First & Last & vbCrLf                      <-- Return, work is done.
      Exit Function                                          <-- This is the ONLY return in the code.
   
   End Select

End Function

Wayne
 
Hi Wayne,

I had try already, it is good! Thanks....

Actually i wish the code always return 4 digit in the rows but no duplicate,
by input 4 different digit(exp 1234, 8790) the code will return perfectly 24 combination on it, how bout i use duplicate digit like 1123, 2224 then the code still able to return 4-digit of combination for me?
exp:

Code:
1123  -->   1123
            1213
            1231
            2311
            2131
            2113
            3211
            3121
            3112  --> Return 4-digit  of 9 combination

2224 -->    2224
            2242
            2422
            4222  --> Return 4-digit of 4 combination


Thank you!

Regard,
alex
 
Last edited:
Hi Wayne,

I did it! Thanks for the Tips u giving me, the following is the code that i made it... but it comes out so many duplicate record... May i know how to remove those duplicate one? and how could it be able to store every no. in my record ?

Thanks

Regard,
alex kong

Code:
Private Sub txtSeed_AfterUpdate()
  Me.txtResults = ""
  Me.txtResults = fnGetTerm("", Me.txtSeed)
End Sub


Private Function fnGetTerm(First As String, Last As String) As String
Dim Temp As String
Dim Result As String
Dim i As Long

Select Case Len(Last)
'   Case 5
'      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Replace(Last, Mid(Last, 1, 1), "")) & _
'             fnGetTerm(First & Mid(Last, 2, 1), Replace(Last, Mid(Last, 2, 1), "")) & _
'             fnGetTerm(First & Mid(Last, 3, 1), Replace(Last, Mid(Last, 3, 1), "")) & _
'             fnGetTerm(First & Mid(Last, 4, 1), Replace(Last, Mid(Last, 4, 1), "")) & _
'             fnGetTerm(First & Mid(Last, 5, 1), Replace(Last, Mid(Last, 5, 1), ""))
   Case 4
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Mid(Last, 2, 3)) & _
             fnGetTerm(First & Mid(Last, 2, 1), Mid(Last, 1, 1) & Mid(Last, 3, 2)) & _
             fnGetTerm(First & Mid(Last, 3, 1), Mid(Last, 1, 2) & Mid(Last, 4, 1)) & _
             fnGetTerm(First & Mid(Last, 4, 1), Mid(Last, 1, 3))
   Case 3
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Mid(Last, 2, 2)) & _
             fnGetTerm(First & Mid(Last, 2, 1), Mid(Last, 1, 1) & Mid(Last, 3, 1)) & _
             fnGetTerm(First & Mid(Last, 3, 1), Mid(Last, 1, 2))
   Case 2
      fnGetTerm = fnGetTerm(First & Mid(Last, 1, 1), Mid(Last, 2, 1)) & _
             fnGetTerm(First & Mid(Last, 2, 1), Mid(Last, 1, 1))
   Case 1
      Me.txtResults = Me.txtResults & First & Last & vbCrLf  '<-- If the "Last" string is 1-char
      fnGetTerm = First & Last & vbCrLf                      '<-- Return, work is done.
      Exit Function                                          '<-- This is the ONLY return in the code.
   
   End Select

End Function
 
Alex,

There must be some other issues here.

Using the last code:

123 - Gives 6 combinations
1234 - Gives 24 combinations

Even 333 - gives 6 combinations (A lotta duplicates, but that was the mod
that you requested).

Isn't that what you wanted.

I have no idea how (or why) you would want to store them in a record.

Need more info.

Wayne
 
Wayne,

Thanks for the reply, wayne....

The purpose i would like to prevent duplicate and storing in the record is because i want to use these no. as future use... actually i am writing something looks like a lucky draw program... these no. is using to do the calculation like buying 1 number cost at least a dollar. the first prize is 2500 times of the amount they buy, 2nd is 1000 times, and third is 500 times... depend on the lucky draw result...

if the member is buying a no.1234, they could have a choice of buying just the single no. or combination on the no, if combination surely they have to pay 24 times because of 24 combination.

So that is why i want to filter the duplicate one and store it in the record for the future use...

hope u could understand my explaination.... Thanks

Best Regards,
alex
 

Users who are viewing this thread

Back
Top Bottom