I'm on developing a project regarding Random access(Hashing function), specifically in Folding. Now my problem is, if i enter a key values, how can i isolate each single values for me to control it.
for example:
i enter key value
i need to choose the 2nd entry which is "2"
how can i assigned that "2" is equal to variable "b"? considering that the value i enter is a single value.

I use VB 6.0 for this program... please help me! thanks in advance

Hi there,
You haven't given us much to go on.

If you want 2 to be equal to 'b' then the simple solution is to add 96 to it's value. 'b' has an ascii value of 98. Then you would get the total's character equivalent. So the code might be

Dim a as string, mhash as string
a = "12345"

In this case mhash would equal 'b'.

You just need to know your ascii values and you can make any conversion you like.

For instance the ascii value of the upper case character 'B' is 66. Therefore, to make the 2 equal to 'B' you simply change the formula to....


and that makes an ascii value of 66 which is 'B'.

To get all five values above you could go....

Dim a as string, mhash() as string
a = "12345"
redim mhash(len(a))
for x=1 to len(a)
next x

that would give you this result..


If a had been equal to "14325" then result would have been....


To go a different way you might do this...

Dim a as string, unhash as string
a = "12345"
for x=1 to len(a)
unhash=unhash & chr(val(mid(a,x,1))+96)
next x

That would give us this result..

unhash = "abcde"

To convert your letters back to numbers you simply do the reverse...

Dim mhash as string, unhash as string
for x=1 to len(unhash)
mhash=mhash & Trim(str(asc(mid(unhash,x,1))-96))
next x

And that would make mhash="12345"

Dont leave out the 'Trim' or you string will end up as " 1 2 3 4 5"

I hope this helps,

Gary O'Connor.

This article has been dead for over six months. Start a new discussion instead.