By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,986 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,986 IT Pros & Developers. It's quick & easy.

Convert a long string to integer

P: 5
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. =)
Dec 6 '07 #1
Share this Question
Share on Google+
7 Replies


debasisdas
Expert 5K+
P: 8,127
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.
Dec 6 '07 #2

P: 5
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.
Dec 6 '07 #3

QVeen72
Expert 100+
P: 1,445
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
Dec 6 '07 #4

P: 5
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.
Dec 6 '07 #5

QVeen72
Expert 100+
P: 1,445
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
Dec 6 '07 #6

P: 5
Oh right, I'll give that a go.

What about a long type?
Dec 6 '07 #7

QVeen72
Expert 100+
P: 1,445
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
Dec 6 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.