Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How to convert a big value from string to data?


How to convert a big value from string to data?

Author
Message
Michael_qq
Michael_qq
Forum God
Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)

Group: Forum Members
Posts: 11, Visits: 20

Hi, I am trying to convert a big value data (4 bytes unsigned) from a string to a data, and store it in 4 byte in order. e.g.:

            dim s as string

            dim i(3) as byte

            s = "2271560481"      ' is &H87654321

how can I convert it to a data, and store it in i(3), so that:

           i(0) = &H21

           i(1) = &H43

           i(2) = &H65

           i(3) = &H87

Thanks in advance.

 



Michael_qq
jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
I guess a cheap way of doing it, is first using Hex$ to convert that number into hexidecimal. Then you do somthing like this:

S=Hex$(Number)

L=len(S)

N=Number of entries you want in the array.

A() as string

M=L/N  the step

dim A(1 to N)

For I=1 to N

     A(I)=Mid$(S,((I-1)*M)+1,I*M)

Next I

Hope this helps.

  

    

    

Jabstract: Don't just imagine, make it happen!

Michael_qq
Michael_qq
Forum God
Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)

Group: Forum Members
Posts: 11, Visits: 20
Thank you, Jviper.

Your slution can be used for the data that in the range of Long variable.

In my question above, the original data "s" is presented as a string, "2271560481", but not a number. and, please note that the value that the string represent is exceed the rang of the Long variable. This is the main problem.

Michael_qq

jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
What if you tried a double?

Oh wait: The Hex$ value only excepts Long. Crap. Well that kind of stops it.

Well I guess what would have to happen is, that huge string would have to be split up into several Long's. Then you would have a HiLong part of the number, and a LowLong part of it. The technique is similar to what you had to do on an Atari system, where a big number sitting in memory woud take up 2 spots in memory, a hi byte, and a low byte, so Number would equal LowByte+(256*HiByte).

Jabstract: Don't just imagine, make it happen!

Edited
9/20/2005 by jviper
Michael_qq
Michael_qq
Forum God
Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)Forum God (2K reputation)

Group: Forum Members
Posts: 11, Visits: 20
Thanks, jviper.

The data is acturally in the range of Unsigned Long, and the data could only be input as string. It seems that no existing function to split the string into 2 long variables.

Perhaps there is no simple way, I have to write a function to process it.

Michael_qq

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search