Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Programming question... :)

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

  • Programming question... :)

    What is the most efficient way to check for multiple statuses of a particular variable? I thought of:

    DIM N%(1,5)

    or something like that

    i.e.

    IF N%(1,1)=-1 THEN PRINT" That isn't valid here.":GOTO Beginning_Loop
    IF N%(1,2)=-1 THEN PRINT" There is a magic spell blocking this object's effect.":GOTO Beginning_Loop

    The reason I ask all this is I want to cut down on the size of many of my programs, which have some hardcoded routines, i.e.:

    IF LOC%(N)=105 then ?"That object is wielded."
    IF LOC%(N)=205 then ?"That object is worn."

    I seem to be repeating similar lines of code. I want to cut down on that by at least a third or 1/4.

    Thanks in advance for any replies. Finally, how to I circumvent the 64KB limit for strings in PB for DOS? I was thinking of using XMS and EMS, but I'm not too knowledgable about those two areas of MS-DOS programming.
    I'm trying to convert Westfront PC into something GW-BASIC or QBASIC could handle. I'm using PBDOS to code it in.

    Regards,

    Dunric
    [email protected]
    ICQ#12234336

    ------------------
    Few cats act their age, while
    most just cough up furballs.
    Few cats act their age, while
    most just cough up furballs.

  • #2
    Hi Paul,

    a good way to check multiple statuses is:

    select case N%

    case 1:Rem kill cat
    case 0,-1: rem end
    case else: rem not good

    end select

    Your "IF then else" are a little complicated but very save.


    Stings over 64k You can get with the latest version of PB:

    Dim Virtual BigArray%(1:500000)
    or
    Dim Virtual bigstring(1:50000) as string*10

    over the hole ems space; but they are
    as slowly as a quick file-access.

    One program to translate Quickbasic code in PB should be
    in Your tools folder of PB.

    Regards

    Matthias Kuhn




    ------------------

    Comment


    • #3
      You can also use DIM HUGE, but arrays are still confined to conventional memory. DIM VIRTUAL will create arrays up to 32Mb each, limited by the amount of EMS your memory manager can provide.

      DIM VIRTUAL requires PB/DOS 3.5. In PB/DOS 3.2, DIM HUGE limits subscript values to the integer range, but PB/DOS 3.5 does not have this limitation.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Hey Lance,

        Is version 3.5 still available for sale?

        Paul


        ------------------
        Few cats act their age, while
        most just cough up furballs.
        Few cats act their age, while
        most just cough up furballs.

        Comment


        • #5
          Absolutely.

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Paul

            A cat that wants its breakfast has no snooze button.

            ------------------

            Comment


            • #7
              Yes, but a cat that snoozes gets no breakfast. =)

              Paul


              ------------------
              Few cats act their age, while
              most just cough up furballs.
              Few cats act their age, while
              most just cough up furballs.

              Comment


              • #8
                Code:
                IF N%(1,1)=-1 THEN PRINT" That isn't valid here.":GOTO Beginning_Loop
                IF N%(1,2)=-1 THEN PRINT" There is a magic spell blocking this object's effect.":GOTO Beginning_Loop
                'The reason I ask all this is I want to cut down on the size of many of my programs, which have some hardcoded routines, i.e.:
                IF LOC%(N)=105 then ?"That object is wielded."
                IF LOC%(N)=205 then ?"That object is worn."
                I seem to be repeating similar lines of code.
                This is a fairly common problem, especially when developing a new piece of software.

                What I usually do is start out by creating arrays which match the code with the message; I also set up equates for the numeric values
                Example:

                Code:
                %LOC_NewYork = 1
                %LOC_Boston  = 2
                %LOC_Philadelphia = 3
                ...
                
                DIM CityName (100) AS STRING
                CityName (%LOC_NewYork) = "New York"
                CityName (%LOC_Boston) = "Boston"
                CityName (%LOC_Philadelphia) = "Philadelphia"
                ...
                
                  ' yadda, yadda, yadda
                  ' code to get the city number from data...
                    
                    PRINT CityName (loc%)
                You can do the same kind if thing above with your message. When the variable ou are testing is an array, you just use the array value as the subscript for the text message array.
                [code]
                PRINT TextMessage (N%(Ghost%, Goblin%))
                or
                PRINT TextMessage (N%(Widget%))
                [code]

                This is a lot more work to set up, but I find it more than pays for itself in ease of maintenance and readability.

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

                Comment


                • #9
                  Yup, I like and often use an array that way too... dead easy.

                  Of course, if you are using PB/CC or PBDLL (Paul uses at least one of these) you can also use DATA and READ$ in the same manner, and since DATA is local to the sub/function, you can use separate sets of text/data across your app.

                  Using a string table in a resource file can also be useful, but there is greater overhead (string tables are stored in Unicode and converted to ANSI on the fly), however, if you want to support multiple languages, this method has distinct advantages.


                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Question for Lance:

                    Is the PB/CC IDE 16-bit or 32-bit? What's the main difference between 16 and 32 bit besides memory capacity per address space?
                    Or did I totally botch that description? =)

                    Paul


                    ------------------
                    Few cats act their age, while
                    most just cough up furballs.
                    Few cats act their age, while
                    most just cough up furballs.

                    Comment


                    • #11
                      Unless my memory really IS going, the IDE is 32-bit.

                      BUT... the compiler itself (PBCC,EXE) is a 16-bit application (which produces 32-bit code).WHICH IS WHY WE CAN'T USE LFNs FOR #INCLUDE or #COMPILE

                      MCM

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

                      Comment


                      • #12
                        Michael is correct - CCEDIT and PBEDIT are 32-bit, but the compilers themselves are 16-bit apps. However, being a 16-bit app does not mean the compiler *cannot* support LFN's in metastatements, etc. It just means that it will have to jump through a couple of small hoops to implement it.

                        Technically speaking, whether the compiler is 16-bit or 32-bit has almost no relevence to what can be achieved, be it compile-time memory limits or LFN's, etc.

                        Basically speaking (pun intended) R&D are constantly working at making significant improvements to our compilers... I think you may be impressed with what the future holds!

                        ------------------
                        Lance
                        PowerBASIC Support
                        mailto:[email protected][email protected]</A>
                        Lance
                        mailto:[email protected]

                        Comment

                        Working...
                        X