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
12345
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"
mhash=chr(val(mid(a,2,1))+96)

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....

mhash=chr(val(mid(a,2,1))+64)

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)
mhash(x)=chr(val(mid(a,x,1))+96)
next x

that would give you this result..

mhash(1)="a"
mhash(2)="b"
mhash(3)="c"
mhash(4)="d"
mhash(5)="e"

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

mhash(1)="a"
mhash(2)="d"
mhash(3)="c"
mhash(4)="b"
mhash(5)="e"

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

Dim a as string, unhash as string
a = "12345"
unhash=""
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
unhash="abcde"
mhash=""
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.