Convert a long string to integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dan w01
    New Member
    • Dec 2007
    • 5

    Convert a long string to integer

    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
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    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.

    Comment

    • dan w01
      New Member
      • Dec 2007
      • 5

      #3
      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.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        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

        Comment

        • dan w01
          New Member
          • Dec 2007
          • 5

          #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.

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            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

            Comment

            • dan w01
              New Member
              • Dec 2007
              • 5

              #7
              Oh right, I'll give that a go.

              What about a long type?

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                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

                Comment

                Working...