471,601 Members | 1,636 Online

# URGENT! How to convert 10000 to A000

Hi all,

I have a integer number from 1 to 37000. And I want to create a report in
excel
that shows in 4 alphanumeric length.

Example:
I can write the cutomerID from 1 to 9999 as:
1 ----> 0001
2 ----> 0002
.....
.....
9999 ----> 9999

and I want to write the

10000 -----> as A000
10001 -----> as A001
.....
.....
.....
11000 -----> as B000
11001 -----> as B001

Does anyone knows easiets way to achive this?

Rgds,
Niyazi
I thank you kindly for reading my post.
Apr 4 '06 #1
20 3169
Hello, Niyazi,

There are probably many ways. One is:

Dim chraPrefix As Char() = "0123456789" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim strID = chraPrefix(Int(intID / 1000)) & _
(intID Mod 1000).ToString("000")

Whether this is the easiest (or best) I couldn't say.

But what do you want to have happen when cutomerID > 35999?

Cheers,
Randy
Niyazi wrote:
Hi all,

I have a integer number from 1 to 37000. And I want to create a report in
excel
that shows in 4 alphanumeric length.

Example:
I can write the cutomerID from 1 to 9999 as:
1 ----> 0001
2 ----> 0002
....
....
9999 ----> 9999

and I want to write the

10000 -----> as A000
10001 -----> as A001
....
....
....
11000 -----> as B000
11001 -----> as B001

Does anyone knows easiets way to achive this?

Rgds,
Niyazi
I thank you kindly for reading my post.

Apr 4 '06 #2
Hi Randy,

you are right. Now I am also wondering if the ID number riches 6 digits say
112007. And I have to convert to alphanumeric that has only length of 4.

I guess I have to put 10000 division as well as "0000" but I realy don't

I am realy sorry to say that is it possible to rearrange your code that
converts upto 6 digits number in alphanumeric character that has length of 4.

I very glad that you response very quickly.

Thank you.

Rgds,
Niyazi

"R. MacDonald" wrote:
Hello, Niyazi,

There are probably many ways. One is:

Dim chraPrefix As Char() = "0123456789" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim strID = chraPrefix(Int(intID / 1000)) & _
(intID Mod 1000).ToString("000")

Whether this is the easiest (or best) I couldn't say.

But what do you want to have happen when cutomerID > 35999?

Cheers,
Randy
Niyazi wrote:
Hi all,

I have a integer number from 1 to 37000. And I want to create a report in
excel
that shows in 4 alphanumeric length.

Example:
I can write the cutomerID from 1 to 9999 as:
1 ----> 0001
2 ----> 0002
....
....
9999 ----> 9999

and I want to write the

10000 -----> as A000
10001 -----> as A001
....
....
....
11000 -----> as B000
11001 -----> as B001

Does anyone knows easiets way to achive this?

Rgds,
Niyazi
I thank you kindly for reading my post.

Apr 4 '06 #3
Hi Randy,

I am sure ID number will not reach the 1,000,000 point. But if I have a
integer number between 1 to 999,999 then is it possible to convert starting
from
0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have to start
something like aaaa. Or I am thinking like below example

Example:
0001
0002
....
....
9999
A000
A001
A002
....
....
Aa00
Aa01
Aa02
....
....
Ab00
Ab01
Ab02
....
....
Az00
Az01
Az02
....
....
B000
B001
....
....
....
....
Ba00
Ba01
....
....
Bb..

I am gussing this way may be I am not riching the 999,999 but at least I
will get
Id no around 300,000 and that will be okay with me.

I try to implement in short time above example to your code, but I find I am
not qualified that extend to find the answer.

I am also thinking to use some kind encoding method that converts six digit
Integer number into alphanumeric data that has only lentgh of 4.

But again I am not sure where to start. I search the net and I couldn't find
any good article or example.

One article about "Random Alphanumeric String Generation" uses the randomize
methot to genereate a password. But I my answer wasn't in that.

Say If see a alphanumeric charecter in the report such as zza5 then I will
have to convert into 6 digit integer. But my main goal is know to take the 6
digit integer and convert to alphanumeric characters that has lenthf of 4 and
vice-versa.

I hope you can help me one more time.

I thank you for your kind response.

Rgds,
Niyazi

Apr 4 '06 #4
If you are talking about alpha-numeric codes comprising any combination of
0-9 and A-Z then you can encode values from 0 to 1,679,615 inclusive (thats
1,679,616 combinations or 36 ^ 4 - 1). If you need more then you can add a-z
to your character set and you can then have 62 ^ 4 - 1 or 14,776,336
combinations from 0 to 14,776,335 inclusive.

For 0-9 and A-Z try:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Console.WriteLine(EncodeValue(0))

Console.WriteLine(EncodeValue(1))

Console.WriteLine(EncodeValue(1679615))

Console.WriteLine(DecodeValue("0000"))

Console.WriteLine(DecodeValue("0001"))

Console.WriteLine(DecodeValue("ZZZZ"))

End Sub

Private Function EncodeValue(ByVal value As Integer) As String

If value < 0 OrElse value > (36 ^ 4 - 1) Then Return String.Empty

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As String = String.Empty
For _i As Integer = 0 To 3
Dim _work As Integer = value \ CType(36 ^ _i, Integer) Mod 36
_result = _result.Insert(0, _chars(_work))
value -= _work * CType(36 ^ _i, Integer)
Next
Return _result
Catch
Return String.Empty
End Try

End Function

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return -1

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As Integer = 0
For _i As Integer = 0 To 3
_result += Array.IndexOf(_chars, value.Chars(_i)) * CType(36 ^ (3 -
_i), Integer)
Next
Return _result
Catch
Return -1
End Try

End Function

For 0-9, A-Z and a-z, extend the character arrays and the loop limits
accordingly.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi Randy,

I am sure ID number will not reach the 1,000,000 point. But if I have a
integer number between 1 to 999,999 then is it possible to convert
starting
from
0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have to
start
something like aaaa. Or I am thinking like below example

Example:
0001
0002
...
...
9999
A000
A001
A002
...
...
Aa00
Aa01
Aa02
...
...
Ab00
Ab01
Ab02
...
...
Az00
Az01
Az02
...
...
B000
B001
...
...
...
...
Ba00
Ba01
...
...
Bb..

I am gussing this way may be I am not riching the 999,999 but at least I
will get
Id no around 300,000 and that will be okay with me.

I try to implement in short time above example to your code, but I find I
am
not qualified that extend to find the answer.

I am also thinking to use some kind encoding method that converts six
digit
Integer number into alphanumeric data that has only lentgh of 4.

But again I am not sure where to start. I search the net and I couldn't
find
any good article or example.

One article about "Random Alphanumeric String Generation" uses the
randomize
methot to genereate a password. But I my answer wasn't in that.

Say If see a alphanumeric charecter in the report such as zza5 then I will
have to convert into 6 digit integer. But my main goal is know to take the
6
digit integer and convert to alphanumeric characters that has lenthf of 4
and
vice-versa.

I hope you can help me one more time.

I thank you for your kind response.

Rgds,
Niyazi

Apr 4 '06 #5
Hi Stephany,

The encoding was good way to achive the ID that wiil goto around 1,600,000.
But the report that I have to construct has specific requirment.

In your way of encoding shows integer 10 as 000A, but I have to createa
report in below order as well as I have to consider that
The input should be from 1 to say 999,999 as integer. As you can see the
input lenght might be 1 to 6 but output must be lenght of 4 and in specific
order as:
0001
0002
....
....
9999
A000
A001
A002
....
....
Aa00
Aa01
Aa02
....
....
Ab00
Ab01
Ab02
....
....
Az00
Az01
Az02
....
....
B000
B001
....
....
....
....
Ba00
Ba01
....
....

As you can see the number 9999 will have to show as 9999 but only 10000 will

I guess it is way over me to achive it. I might still searching the right
Or might use Randy's suggestion and stuck with ID upto 61999.

I thank you for your kind response and trying to help me out. I wish I can
get better answer but I am too new to this kind of coding as well as the
report I have to create is very specific.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
If you are talking about alpha-numeric codes comprising any combination of
0-9 and A-Z then you can encode values from 0 to 1,679,615 inclusive (thats
1,679,616 combinations or 36 ^ 4 - 1). If you need more then you can add a-z
to your character set and you can then have 62 ^ 4 - 1 or 14,776,336
combinations from 0 to 14,776,335 inclusive.

For 0-9 and A-Z try:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Console.WriteLine(EncodeValue(0))

Console.WriteLine(EncodeValue(1))

Console.WriteLine(EncodeValue(1679615))

Console.WriteLine(DecodeValue("0000"))

Console.WriteLine(DecodeValue("0001"))

Console.WriteLine(DecodeValue("ZZZZ"))

End Sub

Private Function EncodeValue(ByVal value As Integer) As String

If value < 0 OrElse value > (36 ^ 4 - 1) Then Return String.Empty

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As String = String.Empty
For _i As Integer = 0 To 3
Dim _work As Integer = value \ CType(36 ^ _i, Integer) Mod 36
_result = _result.Insert(0, _chars(_work))
value -= _work * CType(36 ^ _i, Integer)
Next
Return _result
Catch
Return String.Empty
End Try

End Function

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return -1

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As Integer = 0
For _i As Integer = 0 To 3
_result += Array.IndexOf(_chars, value.Chars(_i)) * CType(36 ^ (3 -
_i), Integer)
Next
Return _result
Catch
Return -1
End Try

End Function

For 0-9, A-Z and a-z, extend the character arrays and the loop limits
accordingly.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi Randy,

I am sure ID number will not reach the 1,000,000 point. But if I have a
integer number between 1 to 999,999 then is it possible to convert
starting
from
0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have to
start
something like aaaa. Or I am thinking like below example

Example:
0001
0002
...
...
9999
A000
A001
A002
...
...
Aa00
Aa01
Aa02
...
...
Ab00
Ab01
Ab02
...
...
Az00
Az01
Az02
...
...
B000
B001
...
...
...
...
Ba00
Ba01
...
...
Bb..

I am gussing this way may be I am not riching the 999,999 but at least I
will get
Id no around 300,000 and that will be okay with me.

I try to implement in short time above example to your code, but I find I
am
not qualified that extend to find the answer.

I am also thinking to use some kind encoding method that converts six
digit
Integer number into alphanumeric data that has only lentgh of 4.

But again I am not sure where to start. I search the net and I couldn't
find
any good article or example.

One article about "Random Alphanumeric String Generation" uses the
randomize
methot to genereate a password. But I my answer wasn't in that.

Say If see a alphanumeric charecter in the report such as zza5 then I will
have to convert into 6 digit integer. But my main goal is know to take the
6
digit integer and convert to alphanumeric characters that has lenthf of 4
and
vice-versa.

I hope you can help me one more time.

I thank you for your kind response.

Rgds,
Niyazi

Apr 5 '06 #6
OK. I see where you driving at now.

The basis of the algorithm I demonstrated is still valid but will just need
some amendments to hadle the first 9999 integers.

Insert some code to check for the value of the ID. If it is < 10000 then
just return it to as value.ToString("0000"). If it is >= 10000 then apply
the rest of the algorithm.

When decoding the ID, first try to do an Integer.Parse on the 4 character
string. If it is sucessful then return the result of the Integer.Parse
otherwise continue to decode it according to the algorithm.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hi Stephany,

The encoding was good way to achive the ID that wiil goto around
1,600,000.
But the report that I have to construct has specific requirment.

In your way of encoding shows integer 10 as 000A, but I have to createa
report in below order as well as I have to consider that
The input should be from 1 to say 999,999 as integer. As you can see the
input lenght might be 1 to 6 but output must be lenght of 4 and in
specific
order as:
0001
0002
...
...
9999
A000
A001
A002
...
...
Aa00
Aa01
Aa02
...
...
Ab00
Ab01
Ab02
...
...
Az00
Az01
Az02
...
...
B000
B001
...
...
...
...
Ba00
Ba01
...
...

As you can see the number 9999 will have to show as 9999 but only 10000
will

I guess it is way over me to achive it. I might still searching the right
Or might use Randy's suggestion and stuck with ID upto 61999.

I thank you for your kind response and trying to help me out. I wish I can
get better answer but I am too new to this kind of coding as well as the
report I have to create is very specific.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
If you are talking about alpha-numeric codes comprising any combination
of
0-9 and A-Z then you can encode values from 0 to 1,679,615 inclusive
(thats
1,679,616 combinations or 36 ^ 4 - 1). If you need more then you can add
a-z
to your character set and you can then have 62 ^ 4 - 1 or 14,776,336
combinations from 0 to 14,776,335 inclusive.

For 0-9 and A-Z try:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Console.WriteLine(EncodeValue(0))

Console.WriteLine(EncodeValue(1))

Console.WriteLine(EncodeValue(1679615))

Console.WriteLine(DecodeValue("0000"))

Console.WriteLine(DecodeValue("0001"))

Console.WriteLine(DecodeValue("ZZZZ"))

End Sub

Private Function EncodeValue(ByVal value As Integer) As String

If value < 0 OrElse value > (36 ^ 4 - 1) Then Return String.Empty

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As String = String.Empty
For _i As Integer = 0 To 3
Dim _work As Integer = value \ CType(36 ^ _i, Integer) Mod 36
_result = _result.Insert(0, _chars(_work))
value -= _work * CType(36 ^ _i, Integer)
Next
Return _result
Catch
Return String.Empty
End Try

End Function

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return -1

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As Integer = 0
For _i As Integer = 0 To 3
_result += Array.IndexOf(_chars, value.Chars(_i)) * CType(36 ^
(3 -
_i), Integer)
Next
Return _result
Catch
Return -1
End Try

End Function

For 0-9, A-Z and a-z, extend the character arrays and the loop limits
accordingly.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
> Hi Randy,
>
> I am sure ID number will not reach the 1,000,000 point. But if I have a
> integer number between 1 to 999,999 then is it possible to convert
> starting
> from
> 0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have to
> start
> something like aaaa. Or I am thinking like below example
>
> Example:
> 0001
> 0002
> ...
> ...
> 9999
> A000
> A001
> A002
> ...
> ...
> Aa00
> Aa01
> Aa02
> ...
> ...
> Ab00
> Ab01
> Ab02
> ...
> ...
> Az00
> Az01
> Az02
> ...
> ...
> B000
> B001
> ...
> ...
> ...
> ...
> Ba00
> Ba01
> ...
> ...
> Bb..
>
> I am gussing this way may be I am not riching the 999,999 but at least
> I
> will get
> Id no around 300,000 and that will be okay with me.
>
> I try to implement in short time above example to your code, but I find
> I
> am
> not qualified that extend to find the answer.
>
> I am also thinking to use some kind encoding method that converts six
> digit
> Integer number into alphanumeric data that has only lentgh of 4.
>
> But again I am not sure where to start. I search the net and I couldn't
> find
> any good article or example.
>
> One article about "Random Alphanumeric String Generation" uses the
> randomize
> methot to genereate a password. But I my answer wasn't in that.
>
> Say If see a alphanumeric charecter in the report such as zza5 then I
> will
> have to convert into 6 digit integer. But my main goal is know to take
> the
> 6
> digit integer and convert to alphanumeric characters that has lenthf of
> 4
> and
> vice-versa.
>
> I hope you can help me one more time.
>
> I thank you for your kind response.
>
> Rgds,
> Niyazi
>
>
>

Apr 5 '06 #7
Hi Stephany,

Okay I did what you suggest and it worked upto 9999 but in the ID Number:
10000 shows as 07PS and
10001 shows as 07PT

But the report that I have to construct state that the
number 10000 must be shown as A000 and
number 10001 must be shown A001 and so on.

How to use the algorithm in your code so I can get after 9999 as A000 and so
on?

Thank you for your kind help.

Rgds,
Niyazi

"Stephany Young" wrote:
OK. I see where you driving at now.

The basis of the algorithm I demonstrated is still valid but will just need
some amendments to hadle the first 9999 integers.

Insert some code to check for the value of the ID. If it is < 10000 then
just return it to as value.ToString("0000"). If it is >= 10000 then apply
the rest of the algorithm.

When decoding the ID, first try to do an Integer.Parse on the 4 character
string. If it is sucessful then return the result of the Integer.Parse
otherwise continue to decode it according to the algorithm.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hi Stephany,

The encoding was good way to achive the ID that wiil goto around
1,600,000.
But the report that I have to construct has specific requirment.

In your way of encoding shows integer 10 as 000A, but I have to createa
report in below order as well as I have to consider that
The input should be from 1 to say 999,999 as integer. As you can see the
input lenght might be 1 to 6 but output must be lenght of 4 and in
specific
order as:
0001
0002
...
...
9999
A000
A001
A002
...
...
Aa00
Aa01
Aa02
...
...
Ab00
Ab01
Ab02
...
...
Az00
Az01
Az02
...
...
B000
B001
...
...
...
...
Ba00
Ba01
...
...

As you can see the number 9999 will have to show as 9999 but only 10000
will

I guess it is way over me to achive it. I might still searching the right
Or might use Randy's suggestion and stuck with ID upto 61999.

I thank you for your kind response and trying to help me out. I wish I can
get better answer but I am too new to this kind of coding as well as the
report I have to create is very specific.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
If you are talking about alpha-numeric codes comprising any combination
of
0-9 and A-Z then you can encode values from 0 to 1,679,615 inclusive
(thats
1,679,616 combinations or 36 ^ 4 - 1). If you need more then you can add
a-z
to your character set and you can then have 62 ^ 4 - 1 or 14,776,336
combinations from 0 to 14,776,335 inclusive.

For 0-9 and A-Z try:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Console.WriteLine(EncodeValue(0))

Console.WriteLine(EncodeValue(1))

Console.WriteLine(EncodeValue(1679615))

Console.WriteLine(DecodeValue("0000"))

Console.WriteLine(DecodeValue("0001"))

Console.WriteLine(DecodeValue("ZZZZ"))

End Sub

Private Function EncodeValue(ByVal value As Integer) As String

If value < 0 OrElse value > (36 ^ 4 - 1) Then Return String.Empty

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As String = String.Empty
For _i As Integer = 0 To 3
Dim _work As Integer = value \ CType(36 ^ _i, Integer) Mod 36
_result = _result.Insert(0, _chars(_work))
value -= _work * CType(36 ^ _i, Integer)
Next
Return _result
Catch
Return String.Empty
End Try

End Function

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return -1

Try
Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c,
"H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c, "S"c,
"T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
Dim _result As Integer = 0
For _i As Integer = 0 To 3
_result += Array.IndexOf(_chars, value.Chars(_i)) * CType(36 ^
(3 -
_i), Integer)
Next
Return _result
Catch
Return -1
End Try

End Function

For 0-9, A-Z and a-z, extend the character arrays and the loop limits
accordingly.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
> Hi Randy,
>
> I am sure ID number will not reach the 1,000,000 point. But if I have a
> integer number between 1 to 999,999 then is it possible to convert
> starting
> from
> 0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have to
> start
> something like aaaa. Or I am thinking like below example
>
> Example:
> 0001
> 0002
> ...
> ...
> 9999
> A000
> A001
> A002
> ...
> ...
> Aa00
> Aa01
> Aa02
> ...
> ...
> Ab00
> Ab01
> Ab02
> ...
> ...
> Az00
> Az01
> Az02
> ...
> ...
> B000
> B001
> ...
> ...
> ...
> ...
> Ba00
> Ba01
> ...
> ...
> Bb..
>
> I am gussing this way may be I am not riching the 999,999 but at least
> I
> will get
> Id no around 300,000 and that will be okay with me.
>
> I try to implement in short time above example to your code, but I find
> I
> am
> not qualified that extend to find the answer.
>
> I am also thinking to use some kind encoding method that converts six
> digit
> Integer number into alphanumeric data that has only lentgh of 4.
>
> But again I am not sure where to start. I search the net and I couldn't
> find
> any good article or example.
>
> One article about "Random Alphanumeric String Generation" uses the
> randomize
> methot to genereate a password. But I my answer wasn't in that.
>
> Say If see a alphanumeric charecter in the report such as zza5 then I
> will
> have to convert into 6 digit integer. But my main goal is know to take
> the
> 6
> digit integer and convert to alphanumeric characters that has lenthf of
> 4
> and
> vice-versa.
>
> I hope you can help me one more time.
>
> I thank you for your kind response.
>
> Rgds,
> Niyazi
>
>
>

Apr 5 '06 #8
I think that we might be able to help you better if you were tell us why the
ID needs to be encoded in this way.

Is it because it must fit in with some immutable legacy system that has a
limitation of 4 characters for an ID of some description?

Is it because someone somewhere thought that would look nice.

Is it because someone wrote some code once that never took into account that
more than 9999 ID's would be required someday?

Is it because some 'boss' somewhere is fklexing his/her muscles?

In addition, it would be helpful if you were to share the actual rules. We
know the rules for when the value is 1 to 9999 and 10000 and 10001. What is
the rule for 0 - is 0 allowed? What is the rule for 10999 - is it A999? What
is the rule for 11000 - is it B000 or even AA00 perhaps? When should a lower
case alpha character be used? What value do you expect ZZZZ to represent?

When and only when you defined the rules then the actual coding should be
relatively easy.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Hi Stephany,

Okay I did what you suggest and it worked upto 9999 but in the ID Number:
10000 shows as 07PS and
10001 shows as 07PT

But the report that I have to construct state that the
number 10000 must be shown as A000 and
number 10001 must be shown A001 and so on.

How to use the algorithm in your code so I can get after 9999 as A000 and
so
on?

Thank you for your kind help.

Rgds,
Niyazi

"Stephany Young" wrote:
OK. I see where you driving at now.

The basis of the algorithm I demonstrated is still valid but will just
need
some amendments to hadle the first 9999 integers.

Insert some code to check for the value of the ID. If it is < 10000 then
just return it to as value.ToString("0000"). If it is >= 10000 then apply
the rest of the algorithm.

When decoding the ID, first try to do an Integer.Parse on the 4 character
string. If it is sucessful then return the result of the Integer.Parse
otherwise continue to decode it according to the algorithm.
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> Hi Stephany,
>
> The encoding was good way to achive the ID that wiil goto around
> 1,600,000.
> But the report that I have to construct has specific requirment.
>
> In your way of encoding shows integer 10 as 000A, but I have to createa
> report in below order as well as I have to consider that
> The input should be from 1 to say 999,999 as integer. As you can see
> the
> input lenght might be 1 to 6 but output must be lenght of 4 and in
> specific
> order as:
>
>
> 0001
> 0002
> ...
> ...
> 9999
> A000
> A001
> A002
> ...
> ...
> Aa00
> Aa01
> Aa02
> ...
> ...
> Ab00
> Ab01
> Ab02
> ...
> ...
> Az00
> Az01
> Az02
> ...
> ...
> B000
> B001
> ...
> ...
> ...
> ...
> Ba00
> Ba01
> ...
> ...
>
> As you can see the number 9999 will have to show as 9999 but only 10000
> will
>
> I guess it is way over me to achive it. I might still searching the
> right
> Or might use Randy's suggestion and stuck with ID upto 61999.
>
> I thank you for your kind response and trying to help me out. I wish I
> can
> get better answer but I am too new to this kind of coding as well as
> the
> report I have to create is very specific.
>
> Thank you very much.
>
> Rgds,
> Niyazi
>
>
>
> "Stephany Young" wrote:
>
>> If you are talking about alpha-numeric codes comprising any
>> combination
>> of
>> 0-9 and A-Z then you can encode values from 0 to 1,679,615 inclusive
>> (thats
>> 1,679,616 combinations or 36 ^ 4 - 1). If you need more then you can
>> a-z
>> to your character set and you can then have 62 ^ 4 - 1 or 14,776,336
>> combinations from 0 to 14,776,335 inclusive.
>>
>> For 0-9 and A-Z try:
>>
>> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button2.Click
>>
>> Console.WriteLine(EncodeValue(0))
>>
>> Console.WriteLine(EncodeValue(1))
>>
>> Console.WriteLine(EncodeValue(1679615))
>>
>> Console.WriteLine(DecodeValue("0000"))
>>
>> Console.WriteLine(DecodeValue("0001"))
>>
>> Console.WriteLine(DecodeValue("ZZZZ"))
>>
>> End Sub
>>
>> Private Function EncodeValue(ByVal value As Integer) As String
>>
>> If value < 0 OrElse value > (36 ^ 4 - 1) Then Return String.Empty
>>
>> Try
>> Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c,
>> "4"c,
>> "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c,
>> "G"c,
>> "H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c,
>> "S"c,
>> "T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
>> Dim _result As String = String.Empty
>> For _i As Integer = 0 To 3
>> Dim _work As Integer = value \ CType(36 ^ _i, Integer) Mod 36
>> _result = _result.Insert(0, _chars(_work))
>> value -= _work * CType(36 ^ _i, Integer)
>> Next
>> Return _result
>> Catch
>> Return String.Empty
>> End Try
>>
>> End Function
>>
>> Private Function DecodeValue(ByVal value As String) As Integer
>>
>> If value Is Nothing OrElse value.Length <> 4 Then Return -1
>>
>> Try
>> Dim _chars() As Char = New Char(35) {"0"c, "1"c, "2"c, "3"c,
>> "4"c,
>> "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c,
>> "G"c,
>> "H"c, "I"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, "R"c,
>> "S"c,
>> "T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c}
>> Dim _result As Integer = 0
>> For _i As Integer = 0 To 3
>> _result += Array.IndexOf(_chars, value.Chars(_i)) * CType(36 ^
>> (3 -
>> _i), Integer)
>> Next
>> Return _result
>> Catch
>> Return -1
>> End Try
>>
>> End Function
>>
>> For 0-9, A-Z and a-z, extend the character arrays and the loop limits
>> accordingly.
>>
>>
>> "Niyazi" <Ni****@discussions.microsoft.com> wrote in message
>> news:70**********************************@microsof t.com...
>> > Hi Randy,
>> >
>> > I am sure ID number will not reach the 1,000,000 point. But if I
>> > have a
>> > integer number between 1 to 999,999 then is it possible to convert
>> > starting
>> > from
>> > 0001 (zero, zero, zero one) up to zzzz. After riches ZZZZ than have
>> > to
>> > start
>> > something like aaaa. Or I am thinking like below example
>> >
>> > Example:
>> > 0001
>> > 0002
>> > ...
>> > ...
>> > 9999
>> > A000
>> > A001
>> > A002
>> > ...
>> > ...
>> > Aa00
>> > Aa01
>> > Aa02
>> > ...
>> > ...
>> > Ab00
>> > Ab01
>> > Ab02
>> > ...
>> > ...
>> > Az00
>> > Az01
>> > Az02
>> > ...
>> > ...
>> > B000
>> > B001
>> > ...
>> > ...
>> > ...
>> > ...
>> > Ba00
>> > Ba01
>> > ...
>> > ...
>> > Bb..
>> >
>> > I am gussing this way may be I am not riching the 999,999 but at
>> > least
>> > I
>> > will get
>> > Id no around 300,000 and that will be okay with me.
>> >
>> > I try to implement in short time above example to your code, but I
>> > find
>> > I
>> > am
>> > not qualified that extend to find the answer.
>> >
>> > I am also thinking to use some kind encoding method that converts
>> > six
>> > digit
>> > Integer number into alphanumeric data that has only lentgh of 4.
>> >
>> > But again I am not sure where to start. I search the net and I
>> > couldn't
>> > find
>> > any good article or example.
>> >
>> > One article about "Random Alphanumeric String Generation" uses the
>> > randomize
>> > methot to genereate a password. But I my answer wasn't in that.
>> >
>> > Say If see a alphanumeric charecter in the report such as zza5 then
>> > I
>> > will
>> > have to convert into 6 digit integer. But my main goal is know to
>> > take
>> > the
>> > 6
>> > digit integer and convert to alphanumeric characters that has lenthf
>> > of
>> > 4
>> > and
>> > vice-versa.
>> >
>> > I hope you can help me one more time.
>> >
>> > I thank you for your kind response.
>> >
>> > Rgds,
>> > Niyazi
>> >
>> >
>> >
>>
>>
>>

Apr 5 '06 #9
Hi Stephany,

I thank you for kind understanding reagarding to my post.

The report I have to create have to be in Excel sheet as well as in notepad.

Problem is this:
The accountan frim doesn't have legacy system but they thought customer Id
will never rich 10000 because we are local company and population in here is
around 50000. Plus we have another 7 company who sells construction Goods.

The accountan firm already arrange a programmer (they used delphi) and they
already got other 6 companies. There is only 1 accountan firm in our local
area.

Rule is very simple (but not for me):
ID Number Output String
--------------------------------------------------------------------

10000 have to be shown as A000
10001 " A001
..... ... ...
10999 " A999
11000 " B000
11001 " B001
.... " ...
than output should be follow as shown below:

Z000
Z001
Z999

AA00
AA01
AA02
....
AA99
AB00
AB01
AB02
....
AB99
AC00
AC01
AC02
....
AC99
....
AE00
....
....
...
ZZ00
ZZ01
ZZ02
....
ZZ99
ZZA0
ZZA1
ZZA2
....
ZZB0
....
....
....
ZZZ0
ZZZ1
ZZZ2
....
ZZZ9
ZZZZ

then goes back to lower case:

a000
a001
a002
....
....
a999
b000
b001
b002
....
....
b999
ba00
ba01
ba02
....
....
bb00
.....
.....
.....

and the last ID out would be:
....
....
zzzz

But I am not sure what will be longest ID will be. But if it is around
300,000 or 500,000 then thats more than enough for me.

Thank you very much.

Rgds
Niyazi

Apr 5 '06 #10
The rules are not simple at all.

Who is making the rules?

Is it the accounting firm?

Are they saying that YOU must have the codes as 4 characters because that is
all THEIR system can handle? If so, maybe it's time you reminded them just
who is paying their fees!

And, who has decided that 9999 = 9999 and 10000 = A000 etc., is it you or is
it them?

If it is just your own way of identifying your customer then why does it
have to be this way? There are much simpler ways of representing relatively
large numbers in just 4 characters.

Does the progression continue as the following?:

11999 = B999
12000 = C000
12000 = C001
12999 = C999
13000 = D000
13999 = D999
35000 = Z000
35001 = Z001
35999 = Z999

If so, then does it continue as?:

36000 = AA00
36001 = AA01
36099 = AA99
36100 = AB01
36199 = AB99

If so, then ZZZZ will be the code for 103795. Is this what you expect? If
not, what would you expect ZZZZ to represent?

Progressing as above a000 will represent 103796 and zzzz will represent
199591 which is not quite two-thirds of your minimum target of 300,000.

Where do you get your target of 300,000 to 500,000 from. Is it just a guess?
Are they just nice round numbers?

I can understand that someone made an initial guess that your Customer ID
would never reach 10000, and I can certainly understand that you want to
allow a big enough range that it won't 'blow out' again, but is your
estimate of 300,000 to 500,000 realistic? That would mean that your number
of customers is going to grow to 30 or 50 times the number you now have. The
sort of things that you need to take into account (amongst others) are the
expected useful life of this software etc. and remember that you don't have
to worry about the maintenance of it after you died.

As an example, I have a customer who, a few years ago, was absolutely
paranoid about running out of customer numbers. We were using an Integer
column in a database for this purpose and it took me some time to convince
him that if he issued 1 new Customer ID every second of every minute of
every hour etc. (24/7 365 days a year) that it would take about 68 years to
run out of numbers and that the average number of new Customer ID's issued
historically was about 1000 per year.

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
Hi Stephany,

I thank you for kind understanding reagarding to my post.

The report I have to create have to be in Excel sheet as well as in

Problem is this:
The accountan frim doesn't have legacy system but they thought customer Id
will never rich 10000 because we are local company and population in here
is
around 50000. Plus we have another 7 company who sells construction Goods.

The accountan firm already arrange a programmer (they used delphi) and
they
already got other 6 companies. There is only 1 accountan firm in our local
area.

Rule is very simple (but not for me):
ID Number Output String
--------------------------------------------------------------------

10000 have to be shown as A000
10001 " A001
.... ... ...
10999 " A999
11000 " B000
11001 " B001
... " ...
than output should be follow as shown below:

Z000
Z001
Z999

AA00
AA01
AA02
...
AA99
AB00
AB01
AB02
...
AB99
AC00
AC01
AC02
...
AC99
...
AE00
...
...
..
ZZ00
ZZ01
ZZ02
...
ZZ99
ZZA0
ZZA1
ZZA2
...
ZZB0
...
...
...
ZZZ0
ZZZ1
ZZZ2
...
ZZZ9
ZZZZ

then goes back to lower case:

a000
a001
a002
...
...
a999
b000
b001
b002
...
...
b999
ba00
ba01
ba02
...
...
bb00
....
....
....

and the last ID out would be:
...
...
zzzz

But I am not sure what will be longest ID will be. But if it is around
300,000 or 500,000 then thats more than enough for me.

Thank you very much.

Rgds
Niyazi

Apr 5 '06 #11
Hi Stephany,
Who is making the rules?
The accountant firm making rule because there isn't any othe accountant in
this area.
I guess their system design that ID number never riches 10000.
9999 = 9999 and 10000 = A000 rules came from accountant firm, and their reason
was its readability. They already knows that when they see say ID No C101 it
means

Yes you are very right the progression continue as the following:

11999 = B999
12000 = C000
12000 = C001
12999 = C999
13000 = D000
13999 = D999
35000 = Z000
35001 = Z001
35999 = Z999
....
36000 = AA00
36001 = AA01
36099 = AA99
36100 = AB01
36199 = AB99
....
103795 = ZZZZ
....
103796 = a000
....
....
....
199591 = zzzz

My target of 300,000 to 500,000 was just an example.
As you mention if the zzzz represents 199591 then that is more than enough
for me.
It will take 1000 years to rich the population over 200,000 in this area so
I guess you are very right about
"you don't have to worry about the maintenance of it after you died."

How should I work with your code and re-arrange the Letters for

10000 = A000
....
199591 = zzzz

After I red your post I worked and an hour with your code, and it feels
someting that I missed, I never be able to mange to re-arrange the leeters so
they can come As after 9999 -> 10000 = A000 and the last 199591 = zzzz. Well
my brain is not mature like yours.

I realy thank you for your kind understanding and giving me a lesson that I
Thank you very much.

Rgds,
Niyazi
Apr 6 '06 #12
Niyazi,

I agree with Stephany, I have as well that experience that some accountants
things that the client is there for them and not in the opposite way. Time
cost no money, in opposite the client pays for that.

However probably has he/she started by making a long table that he/she uses
now and is very proud on that.

You can do the same as him/her, but a little bit more intelligent.
You know that you can go on from 10.001 until x. At 35.999 and so on.
Therefore you can make the same table in a simple arraylist.

If you have made the rules for this table, than you can use this table.
However easier is it than to use the rules, with what you made the table to
make the conversion.

You can as well than make a nice printing program for the accountant in a
way that he can check the table (mostly this type of accountants wont
believe that it can be so easy). He/she will probably say nothing but you
see him/her when you are gone.

Just my thought,

Cor

"Niyazi" <Ni****@discussions.microsoft.com> schreef in bericht
news:7A**********************************@microsof t.com...
Hi Stephany,
Who is making the rules?
The accountant firm making rule because there isn't any othe accountant in
this area.
I guess their system design that ID number never riches 10000.
9999 = 9999 and 10000 = A000 rules came from accountant firm, and their
reason
was its readability. They already knows that when they see say ID No C101
it
means

Yes you are very right the progression continue as the following:

11999 = B999
12000 = C000
12000 = C001
12999 = C999
13000 = D000
13999 = D999
35000 = Z000
35001 = Z001
35999 = Z999
....
36000 = AA00
36001 = AA01
36099 = AA99
36100 = AB01
36199 = AB99
...
103795 = ZZZZ
...
103796 = a000
...
...
...
199591 = zzzz

My target of 300,000 to 500,000 was just an example.
As you mention if the zzzz represents 199591 then that is more than enough
for me.
It will take 1000 years to rich the population over 200,000 in this area
so
I guess you are very right about
"you don't have to worry about the maintenance of it after you died."

How should I work with your code and re-arrange the Letters for

10000 = A000
...
199591 = zzzz

After I red your post I worked and an hour with your code, and it feels
someting that I missed, I never be able to mange to re-arrange the leeters
so
they can come As after 9999 -> 10000 = A000 and the last 199591 = zzzz.
Well
guess
my brain is not mature like yours.

I realy thank you for your kind understanding and giving me a lesson that
I
Thank you very much.

Rgds,
Niyazi

Apr 6 '06 #13
OK. Here we go.

What makes the maths a lot more complicated that one might think it should
be is that the first 9999 ID's are treated as is with no character encoding
required. This means taht we only have to start doing maths for values of
10000 and higher.

The 2nd complicating factor is that, intuitvely, the progression should go
A998, A999, AA00 ... AA99, AAA0 ... AAA9, AAAA ... AAAZ and then the B's
etc. all the way up to ZZZZ. However, the requirement is that the
progression goes A998, A999, B000 ... B999, C000 ... C999, D000 ... Z999,
AA00 ... ZZ99, AAA0 ... ZZZ0, AAAA ... ZZZZ. This means that the computation
of the encoding has to be in blocks of values as a single formula cannot be
applied to handles all values above 9999.

I did miscalculate the number of ID's that can be represented in this
fashion, but the actual number is 736336, but seeing as how 0 (0000) is
excluded then the actual range is 1 to 736,335 inclusive. Because the upper
limit is far in excess of the number that you realistically require then
there is no need to extend the alogrithm further (into lower-case letters).

Please attempt to dissect the code (shown below) so that you understand what
it is doing. I won't explain the maths here (because the explanation would
be very long) except to say that it involves careful use of multiples and
powers of 26.

Let us know how you get on.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Console.WriteLine(EncodeValue(1))
Console.WriteLine(EncodeValue(9999))
Console.WriteLine(EncodeValue(10000))
Console.WriteLine(EncodeValue(35999))
Console.WriteLine(EncodeValue(36000))
Console.WriteLine(EncodeValue(103599))
Console.WriteLine(EncodeValue(103600))
Console.WriteLine(EncodeValue(279359))
Console.WriteLine(EncodeValue(279360))
Console.WriteLine(EncodeValue(736335))
Console.WriteLine(DecodeValue("0001"))
Console.WriteLine(DecodeValue("9999"))
Console.WriteLine(DecodeValue("A000"))
Console.WriteLine(DecodeValue("Z999"))
Console.WriteLine(DecodeValue("AA00"))
Console.WriteLine(DecodeValue("ZZ99"))
Console.WriteLine(DecodeValue("AAA0"))
Console.WriteLine(DecodeValue("ZZZ9"))
Console.WriteLine(DecodeValue("AAAA"))
Console.WriteLine(DecodeValue("ZZZZ"))

End Sub

Private Function EncodeValue(ByVal value As Integer) As String

If value < 1 OrElse value > 736335 Then Return String.Empty

' ID = 1 to 999
' 9999 combinations from 0001 to 9999
If value <= 9999 Then Return value.ToString("0000")

Dim _chars As Char() =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharA rray

Dim _result As String = String.Empty

Select Case value
Case 10000 To 35999
' ID = 10000 to 25999
' 26000 combinations from A000 to Z999
value -= 10000
_result &= _chars(Fix(value \ 1000))
_result &= (value Mod 1000).ToString("000")
Case 36000 To 103599
' ID = 36000 to 103599
' 67600 combinations from AA00 to ZZ99
value -= 36000
_result &= _chars(Fix(value \ 2600))
value -= Fix(value \ 2600) * 2600
_result &= _chars(Fix(value \ 100))
_result &= (value Mod 100).ToString("00")
Case 103600 To 279359
' ID = 103600 to 279359
' 175760 combinations from AAA0 to ZZZ9
value -= 103600
_result &= _chars(Fix(value \ 6760))
value -= Fix(value \ 6760) * 6760
_result &= _chars(Fix(value \ 260))
value -= Fix(value \ 260) * 260
_result &= _chars(Fix(value \ 10))
value -= Fix(value \ 10) * 10
_result &= value.ToString("0")
Case Else
' ID = 279360 to 736335
' 456976 combinations from AAAA to ZZZZ
value -= 279360
_result &= _chars(Fix(value \ 17576))
value -= Fix(value \ 17576) * 17576
_result &= _chars(Fix(value \ 676))
value -= Fix(value \ 676) * 676
_result &= _chars(Fix(value \ 26))
value -= Fix(value \ 26) * 26
_result &= _chars(value)
End Select

Return _result

End Function

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return 0

Dim _result As Integer = -1

If Not Integer.TryParse(value, _result) Then
Dim _validchars As Char() =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharA rray
_result = -1
For _i As Integer = 0 To 3
If Array.IndexOf(_validchars, value.Chars(_i)) = -1 Then
_result = 0
Exit For
End If
Next
If _result = -1 Then
Dim _work As Integer
If Integer.TryParse(value.Chars(1), _work) Then
_result = 10000 + Array.IndexOf(_validchars, value.Chars(0)) *
1000 + Integer.Parse(value.Substring(1))
ElseIf Integer.TryParse(value.Chars(2), _work) Then
_result = 36000 + Array.IndexOf(_validchars, value.Chars(0)) *
2600 + Array.IndexOf(_validchars, value.Chars(1)) * 100 +
Integer.Parse(value.Substring(2))
ElseIf Integer.TryParse(value.Chars(3), _work) Then
_result = 103600 + Array.IndexOf(_validchars, value.Chars(0)) *
6760 + Array.IndexOf(_validchars, value.Chars(1)) * 260 +
Array.IndexOf(_validchars, value.Chars(2)) * 10 +
Integer.Parse(value.Substring(3))
Else
_result = 279360 + Array.IndexOf(_validchars, value.Chars(0)) *
17576 + Array.IndexOf(_validchars, value.Chars(1)) * 676 +
Array.IndexOf(_validchars, value.Chars(2)) * 26 + Array.IndexOf(_validchars,
value.Chars(3))
End If
End If
End If

Return _result

End Function

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
Hi Stephany,
Who is making the rules?
The accountant firm making rule because there isn't any othe accountant in
this area.
I guess their system design that ID number never riches 10000.
9999 = 9999 and 10000 = A000 rules came from accountant firm, and their
reason
was its readability. They already knows that when they see say ID No C101
it
means

Yes you are very right the progression continue as the following:

11999 = B999
12000 = C000
12000 = C001
12999 = C999
13000 = D000
13999 = D999
35000 = Z000
35001 = Z001
35999 = Z999
....
36000 = AA00
36001 = AA01
36099 = AA99
36100 = AB01
36199 = AB99
...
103795 = ZZZZ
...
103796 = a000
...
...
...
199591 = zzzz

My target of 300,000 to 500,000 was just an example.
As you mention if the zzzz represents 199591 then that is more than enough
for me.
It will take 1000 years to rich the population over 200,000 in this area
so
I guess you are very right about
"you don't have to worry about the maintenance of it after you died."

How should I work with your code and re-arrange the Letters for

10000 = A000
...
199591 = zzzz

After I red your post I worked and an hour with your code, and it feels
someting that I missed, I never be able to mange to re-arrange the leeters
so
they can come As after 9999 -> 10000 = A000 and the last 199591 = zzzz.
Well
guess
my brain is not mature like yours.

I realy thank you for your kind understanding and giving me a lesson that
I
Thank you very much.

Rgds,
Niyazi

Apr 6 '06 #14
Hi Stephany,

It was very good job that it satisfy my boss and I realy wish to see the
accountan guys. The another programmer who did the similar job used the
Delphi and he convince the accutant firm that Delphi can solve every puzzle
they can have.

But I always know this wasn't a problem of the language that we programmed
it was quality of the maths, exprience as well as the analytic thinking.
Sorry to say that my math wasn't good enough so I post my problem here to get

Now I love to programme more one using VS.NET. And I am realy greatful to
you that you just didn't show me the answer but I realy appricate the way you
come up to solution.

Thank you so much for beign here for us. You thought me a lot today. As in
the proverb says "show me your exprience, and thought me 10 years of life."

Thank you very very very much.
God Bless you.

Rgds,
Niyazi

PS: Hi Cor,
Your suggestion also was good but I didn't want to use very long array
list to check it. I also wanted to learn using encoding and decoding. I thank
you very much for beeign here to helping us.

Thank you and God Bless you as well.

I love you guys.

Apr 6 '06 #15
Hi Stephany,

In the DECODING section you use:
Integer.TryParse

I belive that was in VS.NET 2005. I am using VS.NET 2003 and it gave me an
error when I try to use the Integer.Parse (Integer.TryParse is not exist in
VS.NET 2003).

I cannot efford to buy VS.NET 2005 yet. So is there any work around for
Integer.TryParse in VS.NET 2003. Or how should I use IsNumeric keyword in

Thank you.

Rgds,
Niyazi
Apr 6 '06 #16
Replace the line:

If Not Integer.TryParse(value, _result) Then

with:

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
Hi Stephany,

In the DECODING section you use:
Integer.TryParse

I belive that was in VS.NET 2005. I am using VS.NET 2003 and it gave me an
error when I try to use the Integer.Parse (Integer.TryParse is not exist
in
VS.NET 2003).

I cannot efford to buy VS.NET 2005 yet. So is there any work around for
Integer.TryParse in VS.NET 2003. Or how should I use IsNumeric keyword in

Thank you.

Rgds,
Niyazi

Apr 6 '06 #17
Hi Stephany,

I already done that. The error I am getting ios in below lines:

1) I change the keyword Integer.TryParse to 'Integer.Parse
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1), _work) Then

2) I change the keyword Integer.TryParse to 'Integer.Parse and remove the
word _work
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1)) Then

and I am still getting an error that says:

"Input String was not in a correct format"

I lost my brain trying to re-construct the decoding section. I was refering
to use IsNumeric keyword in below line but I am not sure if I am the right
track.

If IsNumeric(value.Chars(1))

I hope this post is more clearly then previous one.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
Replace the line:

If Not Integer.TryParse(value, _result) Then

with:

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
Hi Stephany,

In the DECODING section you use:
Integer.TryParse

I belive that was in VS.NET 2005. I am using VS.NET 2003 and it gave me an
error when I try to use the Integer.Parse (Integer.TryParse is not exist
in
VS.NET 2003).

I cannot efford to buy VS.NET 2005 yet. So is there any work around for
Integer.TryParse in VS.NET 2003. Or how should I use IsNumeric keyword in

Thank you.

Rgds,
Niyazi

Apr 6 '06 #18
Forget about IsNumeric. It will get you nowhwere.

The whole idea of Integer.Parse is that it throws an exception if the the
input value cannot be converted to an integer. You have to wrap the
Integer.Parse statements in a Try...Catch...End Try like I showed you.

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return 0

Dim _result As Integer = -1

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then
Dim _validchars As Char() =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789".ToCharArray
_result = -1
For _i As Integer = 0 To 3
If Array.IndexOf(_validchars, value.Chars(_i)) = -1 Then
_result = 0
Exit For
End If
Next
If _result = -1 Then
Dim _work As Integer
Try
_work = Integer.Parse(value.Chars(1))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 10000 + Array.IndexOf(_validchars, value.Chars(0)) *
1000 + Integer.Parse(value.Substring(1))
Else
Try
_work = Integer.Parse(value.Chars(2))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 36000 + Array.IndexOf(_validchars, value.Chars(0)) *
2600 + Array.IndexOf(_validchars, value.Chars(1)) * 100 +
Integer.Parse(value.Substring(2))
Else
Try
_work = Integer.Parse(value.Chars(3))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 103600 + Array.IndexOf(_validchars, value.Chars(0))
* 6760 + Array.IndexOf(_validchars, value.Chars(1)) * 260 +
Array.IndexOf(_validchars, value.Chars(2)) * 10 +
Integer.Parse(value.Substring(3))
Else
_result = 279360 + Array.IndexOf(_validchars, value.Chars(0))
* 17576 + Array.IndexOf(_validchars, value.Chars(1)) * 676 +
Array.IndexOf(_validchars, value.Chars(2)) * 26 + Array.IndexOf(_validchars,
value.Chars(3))
End If
End If
End If
End If
End If

Return _result

End Function
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
Hi Stephany,

I already done that. The error I am getting ios in below lines:

1) I change the keyword Integer.TryParse to 'Integer.Parse
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1), _work) Then

2) I change the keyword Integer.TryParse to 'Integer.Parse and remove the
word _work
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1)) Then

and I am still getting an error that says:

"Input String was not in a correct format"

I lost my brain trying to re-construct the decoding section. I was
refering
to use IsNumeric keyword in below line but I am not sure if I am the right
track.

If IsNumeric(value.Chars(1))

I hope this post is more clearly then previous one.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
Replace the line:

If Not Integer.TryParse(value, _result) Then

with:

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
> Hi Stephany,
>
> In the DECODING section you use:
> Integer.TryParse
>
> I belive that was in VS.NET 2005. I am using VS.NET 2003 and it gave me
> an
> error when I try to use the Integer.Parse (Integer.TryParse is not
> exist
> in
> VS.NET 2003).
>
> I cannot efford to buy VS.NET 2005 yet. So is there any work around for
> Integer.TryParse in VS.NET 2003. Or how should I use IsNumeric keyword
> in
>
> Thank you.
>
> Rgds,
> Niyazi

Apr 6 '06 #19

If _work = -1 Then

If _work <> -1 Then
"Stephany Young" <noone@localhost> wrote in message
news:uY**************@TK2MSFTNGP04.phx.gbl...
Forget about IsNumeric. It will get you nowhwere.

The whole idea of Integer.Parse is that it throws an exception if the the
input value cannot be converted to an integer. You have to wrap the
Integer.Parse statements in a Try...Catch...End Try like I showed you.

Private Function DecodeValue(ByVal value As String) As Integer

If value Is Nothing OrElse value.Length <> 4 Then Return 0

Dim _result As Integer = -1

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then
Dim _validchars As Char() =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789".ToCharArray
_result = -1
For _i As Integer = 0 To 3
If Array.IndexOf(_validchars, value.Chars(_i)) = -1 Then
_result = 0
Exit For
End If
Next
If _result = -1 Then
Dim _work As Integer
Try
_work = Integer.Parse(value.Chars(1))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 10000 + Array.IndexOf(_validchars, value.Chars(0)) *
1000 + Integer.Parse(value.Substring(1))
Else
Try
_work = Integer.Parse(value.Chars(2))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 36000 + Array.IndexOf(_validchars, value.Chars(0)) *
2600 + Array.IndexOf(_validchars, value.Chars(1)) * 100 +
Integer.Parse(value.Substring(2))
Else
Try
_work = Integer.Parse(value.Chars(3))
Catch
_work = -1
End Try
If _work = -1 Then
_result = 103600 + Array.IndexOf(_validchars, value.Chars(0))
* 6760 + Array.IndexOf(_validchars, value.Chars(1)) * 260 +
Array.IndexOf(_validchars, value.Chars(2)) * 10 +
Integer.Parse(value.Substring(3))
Else
_result = 279360 + Array.IndexOf(_validchars, value.Chars(0))
* 17576 + Array.IndexOf(_validchars, value.Chars(1)) * 676 +
Array.IndexOf(_validchars, value.Chars(2)) * 26 +
Array.IndexOf(_validchars, value.Chars(3))
End If
End If
End If
End If
End If

Return _result

End Function
"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
Hi Stephany,

I already done that. The error I am getting ios in below lines:

1) I change the keyword Integer.TryParse to 'Integer.Parse
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1), _work) Then

2) I change the keyword Integer.TryParse to 'Integer.Parse and remove the
word _work
Dim _work As Integer
'Integer.TryParse
If Integer.Parse(value.Chars(1)) Then

and I am still getting an error that says:

"Input String was not in a correct format"

I lost my brain trying to re-construct the decoding section. I was
refering
to use IsNumeric keyword in below line but I am not sure if I am the
right
track.

If IsNumeric(value.Chars(1))

I hope this post is more clearly then previous one.

Thank you very much.

Rgds,
Niyazi

"Stephany Young" wrote:
Replace the line:

If Not Integer.TryParse(value, _result) Then

with:

Try
_result = Integer.Parse(value)
Catch
_result = -1
End Try

If _result = -1 Then

"Niyazi" <Ni****@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
> Hi Stephany,
>
> In the DECODING section you use:
> Integer.TryParse
>
> I belive that was in VS.NET 2005. I am using VS.NET 2003 and it gave
> me an
> error when I try to use the Integer.Parse (Integer.TryParse is not
> exist
> in
> VS.NET 2003).
>
> I cannot efford to buy VS.NET 2005 yet. So is there any work around
> for
> Integer.TryParse in VS.NET 2003. Or how should I use IsNumeric keyword
> in
>
> Thank you.
>
> Rgds,
> Niyazi

Apr 6 '06 #20
Hi Stephany,
Evrything worked fine.
I realize a significant differences between Integer.Prase and Integer.TryPrase
The Integer.Prase is too slow. I red post about Integer.TryPrase that is
much better then the older version.

I thank you very much. Today was my last day to give the report.
I really appreciated your help and the insight you just show.

Thank you very much.
Rgds,
GC

Apr 7 '06 #21

### This discussion thread is closed

Replies have been disabled for this discussion.