Announcement

Collapse
No announcement yet.

how to create a "Shared Array"

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

  • how to create a "Shared Array"


    Good evening (here is 18.30) I'm tryng to understand how to declare an array (in the main body of the program) shared with procedures and functions. I think I'm not good at understanding the manual If I want to declare a shared variable I use the statement "SHARED" before variable's name, so I can modify the variable without passing it to a procedure.. ..I don't know how an equivalent procedure functions with the arrays. There Is here a good soul, willing to tell me how this detail works? My compiler is PBDOS version 3.5 (no, I'm not using PBCC O Thanks!

  • #2
    removed
    Dale

    Comment


    • #3
      OK, solved:

      DIM name(1024) as SHARED string

      Comment


      • #4
        How about using GLOBAL statement ?
        the following program uses GLOBAL Arr() as Long

        whereby Arr() is now shared through out the program ?

        Note the program is written in PB WIN 10 , I'm not sure whether it works in PB DOS?

        Code:
        #COMPILE EXE
        #DIM ALL
                   ' written in PB WIN 10
        
        ' Global array whose data can be shared through out the program
          GLOBAL Arr() AS LONG
        
        
        '===================================
        FUNCTION PBMAIN () AS LONG
            LOCAL AnyElem AS LONG
        
                ' Array data list
                REDIM Arr(1 TO 100)
        
                Arr(1) = 5
                Arr(2) = 15
                Arr(3) = 25
                Arr(4) = 35
                Arr(5) = 45
                Arr(6) = 55
                Arr(12) = 105
                Arr(16) = 155
                Arr(26) = 515
        
        
              ' Search for the array sequence # which has a value of 15
               AnyElem = FindElemArray(15)
        
               MSGBOX " The array sequence # is" + STR$(AnyElem) + $CRLF + _
                      " which has the value of 15 "
        
        END FUNCTION
        
        
        
        '===========================
        ' Find an element in array
        ' matching the wanted number wnum
        FUNCTION FindElemArray(wnum AS LONG) AS LONG
          ' Give some rest to the CPU -- otherwise Array scan can produce unpreditable results
           SLEEP(2)
           LOCAL I&
           I& = 0
        
              ARRAY SCAN Arr(),= wnum , TO I&
        
           FUNCTION = I&
          END FUNCTION

        Comment


        • #5
          Marcello.
          I understand on using PBDOS.
          I still have to use it. Specially for writing a TSR that helps some our 16 bit software we use daily.
          I think the rounding of numbers is treated different too.
          If you don't use PBCC then ok. But get your hands on PBCC versions 6 and 5 both.
          They are worth every penny you spend on them in later date.
          p purvis

          Comment


          • #6
            Thanks a lot Anne for your advice, I solved with that code:

            DIM glp(1024) as SHARED string

            The marbellous "PowerBasic DOS" Compiler have big differences with the uindoze counterpart..
            ..I'm plaing with a "simple" compiler after 20 years!, so really I don't remember how to use the byke,
            in the meantime .. I'm becoming old, that's all :-D

            thanks again! O:-)


            Comment


            • #7
              Thanks for the answer Paul,

              Few time ago I buyed licenses 4 PBdos, PBCC and PBWin.
              Now I'm studyng, after a lot of years, the simplest one of them . . . also mine "english" is to be trained, sorry for my mistakes :-)

              I decided for restart with this flavour of "Basic", instead of "C" and "Pascal", and ..really, I don't like the O.O.P. ...
              ... I'm not a professional, and I prefer to start from what I better remember, instead starting from scratch with a uindoze compiler (even if I've seen the other 32bit PowerBasic Windows compilers are really magic! )

              It's more simple for me to test my work within the DosBOX (witch function under a lot of platform and, with the effort of the 'V86 option', all 32bit O.S. have the possibility to run the code with a good performance (there are DosBOX versions for every OS! ) ).

              A question : Is there a BNF Grammar-Schema for PBdos ?
              ..It could be very useful for me to have a Schema that exactly describe the Syntax of the language.

              It's late, now, I must wake up early tomorrow morning..

              Thanks Paul and Anna
              ..have a good night.
              marcello

              Comment


              • #8
                I don't understand the unidoze counterpart.
                I mentioned PBCC 5 because it does not use UNICODE by default like PBCC 6.
                Today, I find myself writing another TSR using Powerbasic for Dos and like most all TSR programs, the memory usuage needs to be low. So I will be using as few variables as I can get by on and try to not have much memory fragmentation on those variables. Shared variables will help or should help.
                p purvis

                Comment

                Working...
                X