Announcement

Collapse
No announcement yet.

Multi use of String Constants

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

  • Multi use of String Constants

    Is there a way to define global string constants in DOS 3.50 power Basic for re-use from various places in the program?

    I am writing a program with a lot of repetitively used text, each phrase of which I hoped would be stored once in the executable. It is pointless and creates many problems to read each phrase as a variable that will never be modified. There is so much that storing each occasion of a re-used phrase makes the executable grossly and unnecessarily inflated. I used to be under the impression that if the same string constant was repetitively quoted in the source, it was only stored once, and was multi-referenced. However, this appears not to be happening. I cannot work out any syntax to make this happen.

    Richard Kemp of Kemputa Systems, Ysbyty Ystwyth, Wales, UK

  • #2
    Richard --

    I think you'll find that if you use the exact same string two or more times in a PB/DOS program, the compiler will embed only one copy of the string in the EXE. The PB compilers have always done that.

    Even if they didn't, you could design a simple function called MessageString (or something similar):

    Code:
    %HELLO_WORLD = 1
    %GODDBYE_WORLD = 2
     
    FUNCTION MessageString(BYVAL lNumber AS LONG) AS STRING
     
         IF lNumber = %HELLO_WORLD THEN
              FUNCTION = "Hello world"
         ELSEIF lNumber = %HELLO_WORLD THEN
              FUNCTION = "Goodbye world"
         ELSE...
     
    END FUNCTION
     
    PRINT MessageString(%HELLO_WORLD)
    A function like that is a good way to "centralize" your strings, so you can edit them all in one place.

    -- Eric

    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited May 05, 2002).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      Here's another alternative:

      ' obviously, more descriptive names should be used
      shared string1$, string2$
      string1$="Hello world"
      string2$="Goodbye world"


      print string1$
      print string2$

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

      Comment

      Working...
      X