| | |
Hello! I'm new here, can someone help me?
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Posts: 10
Reputation:
Solved Threads: 2
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.
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.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Shading in Picturebox
- Next Thread: Can any body help me with my project
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





