Announcement

Collapse
No announcement yet.

Need help on Data Type and long line formula

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

  • Need help on Data Type and long line formula

    Hi
    I need help on data type for a long line formula

    I had my program worked OK on PB DOS 3.5, but I have wrong number when I changed to PBCC 4.0.
    I have problem of data type, because I have a long line formula, so I have to break it into 2 lines.

    When I run in PBCC 4.0 I had error in data type sine new value=-32768, in PBDOS the real value was about 20.
    My break line the old variable N is now treated as a NEW DEFINITION

    I have my program now in PBCC 4.0 susch as

    FUNCTION PBMAIN AS LONG

    LOCAL a1, a2, b1, b2,.....AS INTEGER
    LOCAL c1, c2, d1, d2,....., N, b12 AS LONG

    ''''' N was not defined in PBDOS 3.5, and N is treated as (a NEW DEFINITION) AS INTEGER in PBCC 4.0

    ' examle of my 1 formula in 2 lines

    a1=10: c1=22: d2=30.......

    N = a1+c1+......................................................................................................a3+a4
    b12= (c1+d2+..................................................................................................a4)/N

    print b12

    END FUNCTION


    ====================
    I have now number N exceed limit, I checked new number in PBCC 4.0 with N = -32768.
    So my new result is a wrong number for b12! which is b12 = -2123456789 or so

    One formula should read as:
    b12= (c1+d2 +.................................................................................................................................a4)/(a1+c1 +...................................................................................................................................a3+a4)


    My questions are:

    1. Do I have the continue line for formmula entry such as _ for continue as in print ?
    2. Do I have to change to another new data type for longer than 12 digits, so what is the Data Type should be used ??

    Thank you for your help

    Can Le
    Last edited by Can Le; 14 Jul 2008, 06:20 PM.
    http://www.lecan.net

  • #2
    1. Do I have the continue line for formmula entry such as _ for continue as in print ?
    Sure. You could have tried it and it would have worked for you.

    2. Do I have to change to another new data type for longer than 12 digits, so what is the Data Type should be used ??
    Yes you do, and for 12 significant digits you may pick any legal type which supports 12 or more. In help file, hit the index entry under 'Data Types'

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Michael Mattias,

      Thank you for helps.

      Can Le
      http://www.lecan.net

      Comment


      • #4
        I just had a thought on this. Well, two thoughts...
        One formula should read as:
        b12= (c1+d2 +................................................. .................................................. ..............................a4)/(a1+c1 +................................................. .................................................. ................................a3+a4)
        Thought One: instead of a formula that long, is it possible to use arrays instead of all those discrete variables? Possibly using the MAT() functions?

        Thought Two: you are in this deep anyway; why not use some temp variables so you can hold all the source code in field of view?

        Eg instead of a line so long, use something like

        Code:
         Temp1 = A1 + B2 + ...........    
         Temp2 = C1 + C2 + ....
         ...
          Answer = Temp1 + Temp2 [ +Tempn]...
        With the use of the line continuation character that's probably overkill, but it's a thought, especially if "TempN" is meaningful enough to be a 'trace or debugging value.'

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Another good reason to break up the formula in parts is that many times partial values change less often or remain constant. These intermediate values can be placed in outer for/next or do/loops.

          Comment


          • #6
            Thank you all for your helps,

            I tried your lines and it works, my errors were Data Type.

            Now I have another problem: I counted a number for numbers of digits, I was working OK in PBCC 4.0 but when I changed data type, I can't count a number any more

            Example

            Local Num1, Num2 AS EXT
            local LenNum1, LenNum2 as BYTE

            Num1=123.25
            Num2=1.75

            LenNum1=LEN(Num1)
            LenNum2=LEN(Num2)

            PRINT LenNum1, LenNum2

            My new problem are: All the answers equal =10, I checked SIZEOF(Num1)=10!

            10 10

            It should be 6 and 4. I can't count the total number of digits or characters of a number or a string !

            Please help

            Can Le
            http://www.lecan.net

            Comment


            • #7
              LEN() is for use with dynamic strings, not scalar variables.

              Frankly I don't know why LEN() is even allowed with non-string variables; IMNSHO it should be a compile-time error to do so. SIZEOF() is the correct function to use for scalar variables.

              However, the SIZEOF() a numeric variable is unrelated to its magnitude.

              To count decimal digits of the value of a numeric variable, you can use LEN(FORMAT$(Numbervar))
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Thank Michael Mattias for your good help on LEN(FORMAT$(Numbervar))

                Can Le
                http://www.lecan.net

                Comment


                • #9
                  I am still thining about the use of LEN.

                  Yes, it handles more than "length of a dynamic string"... specifically PB documents it to support scalar variables, types and unions as an equivalent to SIZEOF(), and ASCIIZ variables as "Number of bytes of data up to but not including the first $NUL" (that's my wording, which is better than that in the help file).

                  But if I recall correctly, LEN() had to do all that, because SIZEOF() was not added to the compiler line until sometime later.

                  That is, the introduction of the SIZEOF() function made certain capabilities of LEN() redundant, but since no publisher likes to 'deprecate' any feature, PowerBASIC didn't.

                  Well, maybe others will join me in considering it 'good programming practice" to use LEN() only to get the length of a dynamic string, and SIZEOF() to get the size of any variable.

                  I suppose it would be OK to use LEN() against an ASCIIZ string variable, although personally I'd suggest the lstrlen() WinAPI function.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X