Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

4 Digit Permutation Out Of 5 Or More Numbers

I had seen lots of permutation example that generate out of 4 different numbers and it works perfectly well. But I need to generate a 4 digit permutation out of 5 or more different numbers.

Example: I got 5 number: 4,3,2,7,8 and I want some thing like this. 2347,8743,3247,8437,2378!


I got 6 number: 4,3,2,7,8,1 and I want some thing like this. 2317,8743,3217,8437,2378,1287,7128!

No matter how many numbers I have, I Only want 4 digit permutation.
Any ideas?

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Get The Permutation Of Of 4-Digit Number
Thanks for reading below scenario:

It's about generate / get the permutation of 4 digit number .Example:
user will input 4-digit number at a text box, assume use input---> 1116
and there's command button, when you click on it, it will find the permutatiion of 1116 and display it at a label--> 1116 1161 1611 6111

Thank's for any help

Four Digit Numbers
I want it so that when the user presses Command1 it adds the numbers 1 - 9999 and txtWord.text to lstFound, the problem is I want it to add, say for the first ten, this :


I was thinking of, depending on the length of x, it adds 4 - x zeroes with a loop, but I dont know how to determine the length. All help is appreciated.

- Steve

Making Two Digit Numbers
Ok, I have a label, it has a number in it (currency amount) it has the format 00.00 dollar, and then cents. If, there are only 1 digit at the end of the number, I want it to add a 0 after the ., if it is a two digit number ending in 0, i want it to have the 0 behind it. Can i get some help please?

Large (135 Digit) Numbers
I want to be able to accurately add, subtract, multiply, and divide large (135 digit) numbers. None of the built in data types will do this. Does anyone have any suggestions?

Create Four Digit Random Numbers
hi people i need some advice on this...

is it possible for the programme to create random number in either a text box or label box and if so do you have to declare its variable.

i was wondering if any1 has any suggestion how to code this...

if this is impossible to do...are there alternative ways of overcoming this problem.

many thanx


p.s i am using random number for the programme to operate for a reciept.

How To Generate 6 Digit Random Numbers?
Hello everybody,

How can I generate a 6 digit random numbers which is 0-9? Can anybody help me on this?


5-digit Numbers Converting Themselves Into Things Like B51C6100

i have some code where a user enters a 5-digit number. that number is then used to name the subsequently-created excel file. this works okay on my computer. however, when i send the code to another person, the code (or something) converts the 5-digit code to something like B51C6100. [e.g., 47456 turns into B51C6100.]

here is what happens:
Sub Accountabilities_Before()

Dim Enter5 As String 'employee number the real one
Dim Enter6 As String

'this is where they enter the 5-digit number
Enter5 = InputBox("Please enter the Employee's Employee Number", _
"Please enter the Employee Number", "Enter the Employee Number.")

Enter6 = Str(Enter5) & ".xls"


'the file ends up being saved as the 8-digit thing here
ActiveWorkbook.SaveAs FileName:= _
"C:Documents and SettingsfransDesktopEvaluations" & Enter6 & "", FileFormat:= _
xlExcel9795, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
i don't know if it's a simple matter of my messing up the variable declarations, or something bigger. it's difficult to test, as like i said, it works fine on my machine. it's hers that has the problem! at this point, i'm just curious if anyone has any suggestions.


A Fast Primality Test For 14-16 Digit Numbers
I am conducting some research in the field of Prime-Generating Polynoms, and am currently in need of a fast primality test, either a proving algorythm or a probable primality test for primes of the order of 14 digits and higher.

I have built a factorization procedure that applys the rho method, however it is not fast enough for large numbers. (if anyone wants the code just ask)

A procedure implementing the miller-rabin probable primality test or the ECPP would be most appreciated, either in visual basic (preferably 6) or in C, with detailed instructions on how to use it with VB6.

I have found a few examples for download on the internet but non written in VB6, and those written in C are extremely subtle to implement in Visual Basic.

I hope someone can help me out,

Thanks in advance,


Visio Not Recognizing 3-digit Numbers In If Stmts
I've tried getting visio to recognize the property fields that have nos in them to check conditions for 3 digit nos(>99) but it doesn't do just performs the result assuming the first 2 digits.....what's wrong with the coding ????

Conversion Of Signed Digit To 8 Digit Hexadecimal In Vb6
Hi all,

i need to write a program which convert a signed digit to a 8 digit
If given a decimal number 100, i need to convert to hexadecimal as
How can i set the hexadecimal output to 8-digit?


Hashing A 10 Digit Number To 8 Digit Alphanumeric
Can anyone help me with an algorithm to convert a 10 digit number to an 8 digit alphanumeric?

Preferably, I'd like the following constraints:

1. The number generated is unique - no two numbers will generate the same output
2. The algorithm is one way (irreversable) - not required but would be nice

Eg. Hash(7594865729) returns 8A74BZ65.

Any ideas?

Hashing A 10 Digit Number To A 2 Digit Alphanumeric
I need a function that does the following:

1. Takes a 10 digit number as input and creates a unique hash of that number
2. The hash should allow letters so that it can be shorter than the original number
3. The algorithm should be one-way (ie. irreversable)
4. I'm guessing by adding 26 letters (A to Z) with (0 to 9) will give 36 possibilities for each character. This means a 10 digit number can be hashed to a 2 digit alpha-numeric (?)

10^10 = 10000000000
2^36 = 68719476736

Eg. Hash(0374863796) returns A3 and no other 10 digit number (or < 10 digits) should produce A3.

Does anyone have any ideas about the algorithm to do such a thing. I've looked over the Net at hashing algs such as MD5, but it's not really suited for my purpose. I'm afraid I'm not much good at maths either...

MOD Of 1st 7digit = The 8th Digit Of A 8 Digit Number ?
Hi all,

I am new here and this forums is the best for VB, I use search a lot on this forum and always get what i am jamming at.
But after a whole days search, I am not able find this thing any where.

I have a text box which can take only 8 digits, the thing is, if the : MOD of 1st seven digit = 8th digit then it should focus on next fillup other wise prompt a msg of not been equal.

I know its not that hard for ppl around this great place.

Help would be really appreciated

Regards to all ..

I have to display all the permutation of n numbers.
For example for the first three number (1,2,3) they are:
The number of permutation for n numbers is n!
Is there an algoritm for this use?
Thanks for your answer

Permutation ?: Please Help A Newbie
I'm VERY NEW to VB. I'm generating a matrix of all possible feature sets for a new product. I'm using Excel to track the material cost and add'l overhead of each feature.

Here's the scenario:

I have six categories of features. They have varying numbers of items within them.

Category 1: 1,2,3,4
Category 2: 5,6,7
Category 3: 8,9,10
Category 4: 11,12,13
Category 5: 14,15
Category 6: 16,17

From each category, I must select exactly one item. I seek to generate a list of ALL possible options.

For Example:

Model 1: 1/5/8/11/14/16
Model 2: 2/5/8/11/14/16
Model 3: 3/5/8/11/14/16

et cetera

Any ideas? Any help would be GREATLY appreciated.

My Permutation Algorithm. Nearly There!
I tried to do it recursively before but that didn't work. Here's a graphical solution that nearly works.. can someone please read through and fix any logic problems? It's definitely on the verge of working!

Permutation Problems . . .
Hey all, it's been a while, but I'm back to working in VB. Now, sure enough, I've got another problem.
I'm writing a little program that will write all possible permutations of the given characters to a text file. The problem is, when I specify a minimum number of characters per line, and have more than one given character, a loop occurs. I have to forcefully shutdown the program, and the generated text file displays the same sequence of numbers over and over again . . .
Here's the code I use for calculating permutations:

txtMin is the minimum number of chars a line,
txtMax is the maximum number of chars a line,
and txtChars is a textbox containing all applicable characters.

Private Sub cmdCalculate_Click()

For tempvar = 1 To 20
Letter(tempvar) = Left$(txtChars.Text, 1)
LetterPosition(tempvar) = 1
Next tempvar

NumOfPerms = 0

Set A = CreateObject("Scripting.FileSystemObject")
Set Text = A.CreateTextFile(OutputFile, True)

For NumDigits = 1 To (Val(txtMax.Text) - Val(txtMin.Text))
finished = False
Do Until finished = True
LetterSequence = Empty
For tempvar = 1 To NumDigits
LetterSequence = LetterSequence + Letter(tempvar)
Next tempvar
Text.writeline LetterSequence: NumOfPerms = NumOfPerms + 1
For tempvar = 1 To NumDigits
If Letter(tempvar) <> Right$(txtChars.Text, 1) Then Exit For
If tempvar = NumDigits Then finished = True
Next tempvar
If chkBGprocesses.Value = 1 Then DoEvents
LetterPosition(NumDigits) = LetterPosition(NumDigits) + 1
If LetterPosition(NumDigits) = Len(txtChars.Text) + 1 Then
LetterPosition(NumDigits) = 1
For tempvar = 1 To (NumDigits - Val(txtMin.Text))
LetterPosition(NumDigits - tempvar) = LetterPosition(NumDigits - tempvar) + 1
If LetterPosition(NumDigits - tempvar) = Len(txtChars.Text) + 1 Then
LetterPosition(NumDigits - tempvar) = 1
Exit For
End If
Next tempvar
End If
For tempvar = Val(txtMin.Text) To NumDigits
Letter(tempvar) = Mid$(txtChars.Text, LetterPosition(tempvar), 1)
Next tempvar
Next NumDigits

MsgBox Str$(NumOfPerms) + " permutations derived."
End Sub
Can anyone see what the problem might be?
By the way, it works fine when I have a minimum of one, which makes me think that it has something to do with someplace that "Val(txtMin.Text)" is used. But as of yet I haven't been able to find the bug.

Gamer X

Permutation Algorithm

I am trying to work out a way to code a vba function that would accept an array of variables, for instance say a list of 20 names, from which you would input a number, say perhaps 5. And on this basis the function would generate a list of permutations based on all the possible combinations of 5 people from the list of 20. Is there some form of algorithm I should perhaps look at, or maybe it is more simple than I think it is.

Any help or pushes in the right direction would be greatly appreciated.

Array Permutation
I've searched the forum, i suppose you call this 'anagram', but all the examples i've found on this forum is with letters/strings
I have to do it with numbers, for example;

i have an array like this
and i want to find it's combinations


I want to write a routine to do this, but i don't know how to do it or how to modify the examples on this forum

the array's dimension is variable, for example it can be

Array Permutation
i have a tricky problem. i have for example three arrays of different dimestion

A =[1,2,3,4]

i would like to generate all the different combinations of values in these arrays and the values inside the array should not be repeated.

e.g. the resultset should be


any idea how to do this for any number N of arrays?

Number Permutation

let say i have a number : 1234 , in this number, it can group to 1243, 1324, 1423, 1342 ... in 24 groups,

any formula to do this?

Permutation And Combination About The Particular Value
Suppose if we r giving any value like 100, what are the
permutations going to satisfy this value(100).

Combination / Permutation
How could I go about finding every different permutation of a string possible? Like, I want to be able to go through each possibility of a scrambled string:

abc goes to
abc, acb, bac, bca, cab, cba

All help is appreciated! Thanks!

Permutation Program
Hi! I am not good with math and I am making a permutation program. I am trying to list all the possible permutation in a listview but i am having trouble with the combination.. specifically how to swap the numbers. i am using the same concept as the one i read about in this link but this program uses notepad can anyone help me with this?

Having Difficulties With Permutation Function
Maybe its late in the day but I cant see how to do this. Ignore the actual application for this code but if anyone can help me come up with a function which will just output to the immediate window I can integrate it into the classes it needs to be in later (and of course I will be very greatfull).

The function has 2 inputs, 2 equal length strings of different charecters. I need to obtain every permutation in the correct order of the 2 strings

So if the inputs were "AB" and "CD", I would like to see the following output:


A 3 charecter example should produce the following results.

Inputs "ABC" and "DEF"

There may be more results that I didnt spot.

I hope ive explained myself properly, any help much appreciated.

Permutation Array Algorithm

I need generate all permutation array when the user type n ( n is natural number >0). When The user type for example n=4
I fill the first row and first column with the sequence {1,2,3,4}, if he typed n= 5 I fill with {1,2,3,4,5}
Example: for n=4
* |1234
1 |1234 -- First row
2 |2143
3 |3412
4 |4321

The number in the top and left are number of columns and rows . Look that First row is 1,2,3,4
and first column is 1,2,3,4
In the second column and row I have generate all
permutation possible, but the number only can to be one time in the column and one time in the row. ( the number 1 only one time in the column 1 , one time in the column 2 ...etc).
Other solution for n=4 is
* |1234
1 |1234
2 |2341
3 |3412
4 |4123

do somebody to know the algorithm that generate all
permutation possible without that number show more than one time in the column and row ?
I search abou derangement algorithm but I do not found.
I have to do this program in C or C++ or Pascal or Visual Basic

Thank You in Advance

im havng a problem figuring out how to extract all possible string combination with length n from a set of string... sori if im confusing here's an example
say collection {a,b,c,d} will produce

untill abcd

pls help

Edited by - kmarfilla on 7/6/2006 11:24:20 PM

Combination/permutation Type Problem
Hello everyone-

I write software where i have to display catogories on a screen (menus on a tv screen) that a user can navigate through. Currently i am implemnting new functionality that involves subscription based categories, so that only certain people who are entitled can view a particular category. There can be any number of subscription categories configured and the people should only see on the screen the cateogries that they are entitled to enter. So i need to create a screen for each unigue possible combination of these subscription cateogires on the screen.

So if i have 5 subscription categories configured, that means that i have (2 ^ 5) - 1 or 31 unique combinations of categories. If the category IDs are 10, 20, 30, 40, and 50 then these would be the 31 unique combinations:


The problem that i am having is how to figure out these combinations through code. For some reason my mind is drawing a complete blank today. I would greatly appreciate any help with this problem.


Permutation Function - Urgent ** Resolved
Hi all,

I Know what permutation & I know how to do this. But the thing is I am struggling to make it as a redursive function. Can anybody help me by providing some code which uses recursive logic to produce permutation for n digits.

I have an ex for 4 digit permutation without recursion. I request you people to pl convert this for n numbers in a recursive manner.

VB Code:
Dim I As Integer, J As Integer, K As Integer, L As IntegerFor I = 1 To 4    For J = 1 To 4        If Not (I = J) Then          For K = 1 To 4            If Not (K = J Or K = I) Then              For L = 1 To 4                If Not (L = I Or L = J Or L = K) Then Print I; J; K; L              Next L            End If          Next K        End If    Next JNext I

Tough Combinations Or Permutation Or Tree Or Subset Question
Allright. this one is getting to me now. I have a table that shows the neighbors of a cell. For example, my subject is ID 0. for ID 0 i have possible neighbors with IDS 48 498. Now I have a group of neighbor combinations i.e 0 48 and 0 498 and 0 48 498. Next i go to neighbors of ID 48. 48 has 3 neighbors first is ofcourse 0 and the other two are ID 498 and ID 23. Using ID 48 neighbors we get following set: 48 0; 48 498; 48 23; 48 498 23; 48 0 23 etc ettc. Now we also need our main subject ID 0 we now have the following possible combinations (including the original). i.e exclude anything that

[0 48; 0 498; 0 48 498; 0 48 23 (i.e since 498 is already included in original listi have to exclude it for this list).

I need to keep doing this recursively till i run out of neighbors. How would I accomplish this? I do have an exit in the sense that I have to evaluate values for a particular field for these neighbors and when that value crosses 35 i can exit and move to the next row.

I hope I have explained properly.


Last Digit
how can i get the last 2 digit of a number Ex: 12345 = "45"

All 6 Digit
is there a way have all 6 digit number possiblity, with 0 in front for example:
the zero in front is mainly my main in writing thing... can anyone help?

Last Digit
How can i get the lat 2 digit in a number like Ex: 3136 = "36"

60 Digit Calculator
Does anyone know, of how I can create a calculator that will add and subtract 60 digit integers. The integers must stay as whole 60 digits, and not as E..i.e. 121322e+12.
I have tried a simple + & - function, but i get an 'overflow' error.
Thx in advance for any help.

60 Digit Calculator
This is some code that i have written to add
two 60 digit numbers and leave a whole number response. However i can't seem to get it to work with my interface made up of two labels for the input and a text box for the output. Any help will be much apprieciated!!

Dim Num1(0 to 59) As Integer
Dim Num2(0 to 59) As Integer
Dim Result(0 to 60) as Integer
Dim Overflow as Boolean

For Digit=59 to 0 step -1
If TempNum>9 then
If Digit=0 Then
End If
End if
If Overflow=True Then
MsgBox("ERROR: Number is over the expected value")
End If

How To Check A Certain Digit??
Hi all, I am wondering how I can look at a specific spot in an integer. I have two text boxes, one being a date and the other being a time, and I want to check each digit in the integer of for example, 09:30, starting with the first digit, and check to see if it is > 1 and if so have a messege pop up stating it is an incorrect time.

Thanx everyone for the help!

Get Last Two Digit From Combo Box
I have record populate in the combo box for example 2007,2008,2009,2010,2011.

How I can get the last two digit from combo box and show it in the textbox?

Text6.Text = Combo6.Text

2 To 4 Digit Permutations
This is a mini experiment I would like to try out. I had created 4 textboxes joined together, "Text1 to Text4", an "Enter" command button by the text boxes, a "2 number Text" command button, a "3 number Text" command button, a reset command button and an Exit button, all separated by a space one by one below. (The command buttons are the same size as each other.) The space below the 4 joint text boxes is the most puzzling among them all, the Label. I will explain my objective and then the questions:

a) The 4 textboxes are supposed to display numbers between 0 to 9, no letters and no numbers smaller than 0 or bigger then 9. (This part is solved.)

b) When I clicked on the "2 number text" command button, the "3 number text" command button is disabled and Text3 and Text4 are invisible .
When I clicked on the "3 number text" command button, the "2 number text" command button is disabled and Text4 is invisible.
When I clicked Enter without any selection, "2 number text" and "3 number text" command buttons are disabled, assuming that I wanted to input all 4 digits. (These parts are solved.)

c) The Reset button resets all the conditions back to normal. Text1 to Text 4 boxes will be resetted back to "0" with all the 4 Text boxes available (visible) and the 2 common buttons ("2 number text" button and "3 number text" button) made enabled. The exit button quits the programme, as usual. (This part is also solved.)

Now, the question :

1) Notice that there is an empty space under the 4 textboxes? That is for the label to cover the rest of the display. That is the place where I want the enter button to output the permutation. The problem now is how do I write the permutation in the Label after I input my 2 to 4 numbers and pressed enter? Also take in account that the number I planned to input is also supposed to be one of the selected choices. (Example: If I want 0 and 1 as my 2 numbers, "01" and "10" are supposed to be displayed in the label as 2 permutations, not just 10.) Please help me to write a clear display function for the label when I press the reset command button.

2) I wanted only one digit to display in my text boxes but I do not know how to do that.(eg. 09 is also less than 10.) Can anyone help?

For those who have no idea how the display looks like, just imagine it like this display message page. Close current Tag, close all tags and the smilies on the right are the 5 command buttons. The dropdown boxes, option functions and guided mode is roughly the length of the textboxes, number size, 4 of them. This big textbox is something like the label, to store the 1 to 24 permutations.

I hoped that my explanations and the layouts are clear to you guys. Please help. Thanks!!!

Get 6 Digit Permutations
Basically I need to get every 6 digit permutation which only uses three numbers:

3, 5, 2

Don't know why I can't figure it out on my own, I've done something similar to this before.

Mod 11 Check Digit
Does anyone have a block of VB code to do a Mod 11 Check Digit? Thanks.

Is Charecter Is Digit?
How can i find if a charector is a ditit?

Digit Grouping
Hi there everyone,

I don't know it's me missing something really simple or what, since I haven't been able to find ONE sample code in any language for digit grouping.
I want to have a text box where as you input numbers it groups digits dynamically like in Windows Calculator.
The format function (Format(num, "###,###,###.00") ) or the VB6 "MaskEdBox" don't do it for me because they always assume a fixed number of characters.
I have come up with a rather awkward code with string manipulation using the "KeyUp" event that would work if I could keep the cursor at the right side of the digits being input. Since after each character that's entered the cursor jumps to the left side of the number I try to remedy this with SendKeys.Send("{END 1}"). It works fine in some routines and causes an infinite loop in others.
Does anyone have a cure? If I could just keep the godd*mn cursor at the end of the number, I could solve the thing with string manipulations. Any ideas?
I'd really appreciate your help.


Getting The Middle Digit
Help please !

i have 4 txtboxes and 1 cmdButton:

the first txtbox where the user input a minimum and maximum of 10 digits Ex: "1234567890" or "12345" or "123" or "1234567" and so on.

the second txtbox must get the middle digit in the 1st txtbox Ex: "1234567890" midDigit = "56" || "12345" midDigit="3" || "123" mid = "3"

the third txtbox must squared the midDigit in the 2nd txtbox Ex: 56 * 56 = 3136
|| 3 * 3 = 9

and the fourth txtbox must get the 1st digit of the squared number in the third txtbox Ex: "3136" = "3" || "9" = "9"

help me please !

What Datatype To Use For 12 Digit Number?
The subject basically speaks for itself, What datatype can I use to work with 12 digit numbers?

EDIT: I have tried a single which doesnt produce the overflow error, but when looping through the rows in my spreadsheet, looking for a matching 12 digit number I get the type mismatch errors. Any suggestions please.

Checking If It's A Letter Or A Digit
Hi all,

I was wonderring if in VB there is a function that checks if a string is a letter or a digit. Also is there a function which converts from lower case to upper case (and vise versa)


Yep, Another 60 Digit Calculator Question
Thanks to anyone who's helped me out so far, but I require more help here, if it not too much trouble.

For those who don't know:
My calculator adds or subtracts a 60 digit number, 60 digits is too big to simply just add the numbers together, so the 60 digits are split into 6 boxes. Each box contains 10 digits. So split one number into 6 boxes of 10 digits and then the same with the other, add them together and bob's your uncle. The calc looks like this:

.............................................................. <-- main entry text box (for the 60 digits)

1st number goes here:

2nd number goes here:

.............................................................. <-- answer goes here

Right, I have the addition sorted. With all the carrying of numbers sorted. except the problem with zeros. if 0000000000 is in one box and 1 is in the next box, when I click add, the zeros are ignored. So 10000000000 + 10000000000 would come out as 2. So how can i get the calculator to keep the zeros?

Second problem is subtraction - I haven't really got a clue so any help would be appreciated.


Another Problem With 60 Digit Calculator
Hi, thanks to anyone who helped me for my original post for help with building a calc that can handle 60 digits.
If you look again at that topic, you can see what my calculator looks like.
Now I have another problem.
I have to get the 6 text boxes of 10 digits and place them into one text box. The problem is i cant just add them, I have to literally place them next to each other to look like on number


|1234567890|1234567890|1234567890|1234567890| <-- Have to get these numbers

to look like this:

Position Of A Digit In A Integer
I need to know how to tell the where a certain digit is in a integer. And if it is possible to check certain places in a integer for a specific digit?

How To Convert Digit In Words
is there any built in Function which can convert any Digit figure in to words
if not then please give any hint or example to make this function

Copyright 2005-08, All rights reserved