Hello! I'm new here, can someone help me?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 1
Reputation: jessieminimo12 is an unknown quantity at this point 
Solved Threads: 0
jessieminimo12 jessieminimo12 is offline Offline
Newbie Poster

Hello! I'm new here, can someone help me?

 
0
  #1
Aug 23rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 10
Reputation: GaryOC is an unknown quantity at this point 
Solved Threads: 2
GaryOC GaryOC is offline Offline
Newbie Poster

Re: Hello! I'm new here, can someone help me?

 
0
  #2
Sep 11th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC