Announcement

Collapse
No announcement yet.

Help on 'RESET DATA' or alternative?

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

  • Jules Verschueren
    Guest replied
    Phil, thanks for the nice example

    Lance, your statement
    <the key is the index value use by the READ$() function...
    there is no "data pointer" so to re-read the same data simply
    requires using the same index value again>

    opened my eyes and pointed me to my stupid programming error:
    I did use an index, but because the DATA READs appear inside of a
    double FOR-NEXT loop I forgot to "reset" my index within the
    right loop... Because the data is used to create some graphics
    and as nothing appeared on my screen anymore I thought this was due
    to an impossibility to read the data more than once - mea culpa!

    I now also agree that this DATA handling is indeed powerful.

    Thanks again for your help.


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

    Leave a comment:

  • Lance Edmonds
    Member

  • Lance Edmonds
    replied
    Jules, the key is the index value use by the READ$() function... there is no "data pointer" so to re-read the same data simply requires using the same index value again.

    For example:
    Code:
    #COMPILE EXE
    FUNCTION PBMAIN
      a$ =      READ$(1) + READ$(2) + READ$(3)
      a$ = a$ + READ$(3) + READ$(2) + READ$(1)
      a$ = a$ + READ$(2) + READ$(1) + READ$(3)
      a$ = a$ + READ$(3) + READ$(1) + READ$(1)
      ' ... etc
      MSGBOX a$
      DATA "1st field", 2nd Field, 3rd Field
    END FUNCTION
    Personally, I find PB/DLL's local DATA to be much more usable than the DOS-basic "global" data strategy. The addition of DATACOUNT to query the number of local data items makes ir easier to write code that is independent of the number of data items, rather than resorting to an extra data item to signal the end of the data, or hard-coding the number of data items into the code. In short and IMO, PB/DLL's DATA handling is vastly superior to DOS-basic.



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

    Leave a comment:

  • Phil Tippit
    Member

  • Phil Tippit
    replied
    Jules,

    Here is a small example DLL that should get you started.

    Phil
    Code:
    #COMPILE DLL
    #REGISTER NONE
     GLOBAL element&
    DECLARE FUNCTION GetData(WhatType AS STRING, BYVAL element AS LONG) AS STRING
    DECLARE FUNCTION Animals(BYVAL element AS LONG) AS STRING
    DECLARE FUNCTION Books(BYVAL element AS LONG) AS STRING
    DECLARE FUNCTION software(BYVAL element AS LONG) AS STRING
    
            ' this master function can retrieve from any
            ' of the other functions
            ' example: stringdata$=GetData$("A",3)
            '          would return "Dog"
    DECLARE FUNCTION GetData(WhatType AS STRING, BYVAL element AS LONG) EXPORT AS STRING
           SELECT CASE whattype$
             CASE "A"
               FUNCTION = animals$(element&)
             CASE "B"
               FUNCTION = Books$(element&)
             CASE "S"
               FUNCTION = Software$(element&)
             CASE ELSE
               FUNCTION = "Wrong Type Data Passed"
    END FUNCTION
           ' the functions below could also be exported
           ' for direct calls
           ' example stringdata$=Books$(3)
           ' would return  "Windows 95"
           ' DECLARE FUNCTION Animals(BYVAL element AS LONG) EXPORT AS STRING
    DECLARE FUNCTION Animals(BYVAL element AS LONG) AS STRING
           IF element& => 1 AND element&=<DATACOUNT THEN
              FUNCTION = READ$(element&)
           ELSE
              FUNCTION = "Bad Element Number"
           END IF
           DATA "Cow", "Horse", "Dog", "Cat", "Goat"
    END FUNCTION
    
    DECLARE FUNCTION Books(BYVAL element AS LONG) AS STRING
           IF element& => 1 AND element&=<DATACOUNT THEN
              FUNCTION = READ$(element&)
           ELSE
              FUNCTION = "Bad Element Number"
           END IF
           DATA "War of Wars", "Bible", "Math 101"
    END FUNCTION
    DECLARE FUNCTION software(BYVAL element AS LONG) AS STRING
           IF element& => 1 AND element&=<DATACOUNT THEN
              FUNCTION = READ$(element&)
           ELSE
              FUNCTION = "Bad Element Number"
           END IF
           DATA "PBCC20", "PBDLL60", "Windows 95"
    
    END FUNCTION


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

    Leave a comment:

  • Guest
    Guest

  • Jules Verschueren
    Guest started a topic Help on 'RESET DATA' or alternative?

    Help on 'RESET DATA' or alternative?

    The PB DATA handling has changed quite a bit from DOS to Windows
    (PBDLL6.0). I can cope with the rather restricted READ$(i) but I have
    a lot of data of which some need to be used and read more than once.

    Reading previously used/read data is apparently not possible and the
    Help files don't mention any of this.
    Also the RESET or RESET DATA seem to cause either a syntax error or
    have no effect or makes that the data is apparently all zero...
    I also tried to have the DATA read section in a separate SUB (hoping that
    there would be a kind of refresh each time that SUB is called) but that
    didn't work out either.

    Can anybody tell me how I can correctly read and use the same DATA
    more than once?:

    Alternatively, can anybody describe a method to 'store' data in a
    repetitive retrievable way, but not as a separate file and (preferably)
    also not in memory (because its a relative large amount of data which
    are to be used throughout the duration of the whole programme).


    Any solutions will be much appreciated.
    Thanks, Jules
    email [email protected] or [email protected]


    ------------------
Working...
X