Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert a long string to integer

Newbie
 
Join Date: Dec 2007
Posts: 5
#1: Dec 6 '07
Hi,

I'm reading in a string of about 420 characters, the string is in binary. How do I either:
- convert a string of this length into an integer variable without getting a runtime error 6 (overflow error) which so far I have got from using CInt and Val commands.
- or read the file into an integer variable so that I can perform operations on it.

I've been searching for a while for this and can't find it anywhere, any help would be much appreciated. =)

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#2: Dec 6 '07

re: Convert a long string to integer


Since the string is in binary format you need to convert that to decimal first. still i doubt you can store the output decimal into an integer variable. Try using Long variable for the purpose.
Newbie
 
Join Date: Dec 2007
Posts: 5
#3: Dec 6 '07

re: Convert a long string to integer


The binary is simply 1's and 0's in a text file.

I've tried declaring the integer as long and still recieve an overflow error. I'll have to try something else I suppose.
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#4: Dec 6 '07

re: Convert a long string to integer


Hi,

For 420 Chars, you will definately Receive an "OverFlow Error", You need to declare a String Variable and Read it.
So what kind of Operations are you trying to perform on that data...?

Regards
Veena
Newbie
 
Join Date: Dec 2007
Posts: 5
#5: Dec 6 '07

re: Convert a long string to integer


Yes so far I've read it into a string, its just slightly too long for an integer lol.

I need to split it up into groups of 7 bits and convert to decimal then convert to ASCII etc etc.

The problem is I can't perform maths on a string.

The only way I can think of so far is to split up the file into its 7 bits as a string, then convert that to an integer. I gave it a quick try and I still get an overflow error.
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#6: Dec 6 '07

re: Convert a long string to integer


Hi,

Though 7 Chars is Still a Higher value for Integer(32k Max)
To be safer, You need to split to 4 Chars and try..

Regards
Veena
Newbie
 
Join Date: Dec 2007
Posts: 5
#7: Dec 6 '07

re: Convert a long string to integer


Oh right, I'll give that a go.

What about a long type?
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#8: Dec 6 '07

re: Convert a long string to integer


Hi,

Long Datatype in VB6 has this Range:
-2,147,483,648 to 2,147,483,647

You can try, But You have to Split the Data to a Lesser number of Groups..
9 Chars in one Variable..

Regards
Veena
Reply