Announcement

Collapse
No announcement yet.

Need help on Data Type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help on Data Type

    Hi,

    I planed to buy PB Windows after I have PBCC 4.0, however, I am having problem using Data Type for PBCC 4.0.

    MY problem is:
    My calculation will yield an integer number Num from 4 to 12 digits,
    First, assuming number Num will be 4 digits long such as 1234:

    If I used AS SINGLE:

    LOCAL Num AS SINGLE

    Num=1234

    I will have under flow value for

    Num= 357402.

    I checked help Index from PBCC:

    Single-precision 32 bits (4 bytes) 8.43x10^-37 to 3.40x10^38
    Long-integer 32 bits (4 bytes), signed -2,147,483,648 to 2,147,483,647

    I tried AS LONG but it did not work for 4 digit value.

    It is only accept AS WORD for 4 digits:

    LOCAL Num AS WORD

    'Program will print Num : 1234

    My question:
    How to define Data Type for Num to be used from both 4 digits to a 12 digits long ?

    Will PB Windows version has problem with under flow and over flow too ? If yes, I may say good bye to PB Windows and go back to PB DOS as Data Type for Perl, I think Perl is having the best Data Type!

    Thank you for your help

    Can Le
    http://www.lecan.net

  • #2
    Hi,

    if you want use such a huge numbers, then you could pick QUAD for integer class variables, and EXTENDED for floating point.

    I do not have PB/CC by hand, but following should store and display the numbers correctly:
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
      DIM Num AS QUAD
      
      Num = 1234 ' -- 4 digits
      PRINT Num
      
      Num = 999999999999 ' -- 12 digits
      PRINT Num
    
      WAITKEY$
    
    END FUNCTION
    I do not understand why do you think LONG cannot store 4 digit number? What result it gave to you?
    Could you post code which makes problem?


    Petr

    EDIT: I just found the same question was posted ... and answered here
    Last edited by Petr Schreiber jr; 20 Jul 2008, 03:06 PM.
    [email protected]

    Comment


    • #3
      Some code that shows the problem would help us help you.

      A QUAD will hold the range you want.

      It would also help if you didn't edit the question after answers are posted, and jump to a different thread.

      Cheers,
      Dale

      Comment


      • #4
        Originally posted by Petr Schreiber jr View Post
        EDIT: I just found the same question was posted ... and answered here
        That's an interesting history of Rodney Hicks there Petr, thanks for the bio.

        Comment


        • #5
          Originally posted by John Gleason View Post
          That's an interesting history of Rodney Hicks there Petr, thanks for the bio.
          I apologize, I thought it is link to his post.
          I corrected it now.


          Petr
          [email protected]

          Comment


          • #6
            I corrected it now.
            Darn, I thought I was gonna become famous.

            Rod
            Rod
            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

            Comment


            • #7
              Thank you all for your helps

              I used Num AS LONG for Num=1234 with error -38411,
              but
              DIM or LOCAL Num AS QUAD
              will work for Num=1234 and Num= 123456789112

              I checked PBCC 4.01 it works, but PBCC 4.0 will not work for Data Type:
              LOCAL Num AS LONG

              So the answer is: QUAD works for both short and long numbers!

              Thank you!

              Can Le
              http://www.lecan.net

              Comment


              • #8
                If you compile and run this
                Code:
                #COMPILE EXE
                #DIM ALL
                
                FUNCTION PBMAIN () AS LONG
                 LOCAL num AS LONG
                 LOCAL bignum AS QUAD
                 CONSOLE SET LOC 50,50
                 num=1234
                 PRINT num,"<<<This is a LONG data type"
                 PRINT
                 num=-38411
                 PRINT num,"<<<This is a LONG data type"
                 PRINT
                 bignum=123456789012
                 PRINT bignum,"<<<This is a QUAD data type"
                 WAITKEY$
                
                END FUNCTION
                you will find that there is no error because of the size of the LONG data type. Therefore the error(# not shown) must be related to some other issue in your code which you have not shown us.

                Rod
                Rod
                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                Comment

                Working...
                X