Skip to main content
Doug Averch
Inspiring
Feb 20, 2023 5:16 PM UTC

Old UniBasic techniques

I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

* Using COUNT instead of DCOUNT
     MY.ARRAY = 5:@FM:7:@FM:8
     MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
* Should be 
     MAX.FM = DCOUNT(MY.ARRAY,@FM)

* Not knowing about WHILE in a LOOP statement
     EXECUTE 'SELECT VOC'
     EOF = 0
     LOOP READNEXT ID ELSE EOF = 1
        IF EOF THEN EXIT
     REPEAT
* Should be
     LOOP WHILE READNEXT ID
     REPEAT

* Parsing though data instead of CHANGE command
     MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
     MY.LEN = LEN(MY.DATA)
     FOR X = 1 TO MY.LEN
        IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
     NEXT X
* Should be
     MY.DATA = CHANGE(MY.DATA,";",@FM)

* Not using case
     MY.METHOD = 'CreateReport'
     IF MY.METHOD = 'UpdateRecord' THEN
     END
     IF MY.METHOD = 'CreateReport' THEN
     END
* Should be
     BEGIN CASE
        CASE MY.METHOD = 'UpdateRecord'
        CASE MY.METHOD = 'CreateReport'
     END CASE

* Testing for Universe or Unidata
     UNIVERSE = @FALSE
     OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
* Should be
     IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE

* Finding a JSON value
     JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
     JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
     JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
     JSON = CONVERT(\\{"]\\,"",JSON)
     MAX.FM = DCOUNT(JSON,@FM)
     FOR X = 1 TO MAX.FM
        IF JSON



------------------------------
Doug Averch
Owner
U2 Logic
------------------------------

    8 replies

    Participating Frequently
    Feb 22, 2023 9:31 AM UTC

    I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

    I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

    * Using COUNT instead of DCOUNT
         MY.ARRAY = 5:@FM:7:@FM:8
         MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
    * Should be 
         MAX.FM = DCOUNT(MY.ARRAY,@FM)
    
    * Not knowing about WHILE in a LOOP statement
         EXECUTE 'SELECT VOC'
         EOF = 0
         LOOP READNEXT ID ELSE EOF = 1
            IF EOF THEN EXIT
         REPEAT
    * Should be
         LOOP WHILE READNEXT ID
         REPEAT
    
    * Parsing though data instead of CHANGE command
         MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
         MY.LEN = LEN(MY.DATA)
         FOR X = 1 TO MY.LEN
            IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
         NEXT X
    * Should be
         MY.DATA = CHANGE(MY.DATA,";",@FM)
    
    * Not using case
         MY.METHOD = 'CreateReport'
         IF MY.METHOD = 'UpdateRecord' THEN
         END
         IF MY.METHOD = 'CreateReport' THEN
         END
    * Should be
         BEGIN CASE
            CASE MY.METHOD = 'UpdateRecord'
            CASE MY.METHOD = 'CreateReport'
         END CASE
    
    * Testing for Universe or Unidata
         UNIVERSE = @FALSE
         OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
    * Should be
         IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE
    
    * Finding a JSON value
         JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
         JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
         JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
         JSON = CONVERT(\\{"]\\,"",JSON)
         MAX.FM = DCOUNT(JSON,@FM)
         FOR X = 1 TO MAX.FM
            IF JSON



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    Your up-to-dates are fine, but just for giggles in testing for universe, how about

    equ isUV to (system(9010)="UV)

    if isUV then . . .



    ------------------------------
    Phillip Potter
    V.P. R&D
    Data Management Associates Inc DMA
    Cincinnati OH US
    ------------------------------
    Doug Averch
    Inspiring
    Feb 24, 2023 3:51 PM UTC

    Your up-to-dates are fine, but just for giggles in testing for universe, how about

    equ isUV to (system(9010)="UV)

    if isUV then . . .



    ------------------------------
    Phillip Potter
    V.P. R&D
    Data Management Associates Inc DMA
    Cincinnati OH US
    ------------------------------

    I had an error in this code:

    OPEN '&PH&' TO DUMMY THEN UNIVERSE = @TRUE



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    Doug Averch Owner https://www.u2logic.com/
    Will Johnson
    Participating Frequently
    Feb 25, 2023 7:13 PM UTC

    I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

    I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

    * Using COUNT instead of DCOUNT
         MY.ARRAY = 5:@FM:7:@FM:8
         MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
    * Should be 
         MAX.FM = DCOUNT(MY.ARRAY,@FM)
    
    * Not knowing about WHILE in a LOOP statement
         EXECUTE 'SELECT VOC'
         EOF = 0
         LOOP READNEXT ID ELSE EOF = 1
            IF EOF THEN EXIT
         REPEAT
    * Should be
         LOOP WHILE READNEXT ID
         REPEAT
    
    * Parsing though data instead of CHANGE command
         MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
         MY.LEN = LEN(MY.DATA)
         FOR X = 1 TO MY.LEN
            IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
         NEXT X
    * Should be
         MY.DATA = CHANGE(MY.DATA,";",@FM)
    
    * Not using case
         MY.METHOD = 'CreateReport'
         IF MY.METHOD = 'UpdateRecord' THEN
         END
         IF MY.METHOD = 'CreateReport' THEN
         END
    * Should be
         BEGIN CASE
            CASE MY.METHOD = 'UpdateRecord'
            CASE MY.METHOD = 'CreateReport'
         END CASE
    
    * Testing for Universe or Unidata
         UNIVERSE = @FALSE
         OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
    * Should be
         IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE
    
    * Finding a JSON value
         JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
         JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
         JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
         JSON = CONVERT(\\{"]\\,"",JSON)
         MAX.FM = DCOUNT(JSON,@FM)
         FOR X = 1 TO MAX.FM
            IF JSON



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    I am that old, that I remember Pick BASIC systems that did not have DCOUNT

    And I remeber when DCOUNT came out and everyone was like, finally.



    ------------------------------
    Will Johnson
    Systems Analyst
    Rocket Forum Shared Account
    ------------------------------
    John Jenkins
    Participating Frequently
    Feb 26, 2023 6:56 PM UTC

    I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

    I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

    * Using COUNT instead of DCOUNT
         MY.ARRAY = 5:@FM:7:@FM:8
         MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
    * Should be 
         MAX.FM = DCOUNT(MY.ARRAY,@FM)
    
    * Not knowing about WHILE in a LOOP statement
         EXECUTE 'SELECT VOC'
         EOF = 0
         LOOP READNEXT ID ELSE EOF = 1
            IF EOF THEN EXIT
         REPEAT
    * Should be
         LOOP WHILE READNEXT ID
         REPEAT
    
    * Parsing though data instead of CHANGE command
         MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
         MY.LEN = LEN(MY.DATA)
         FOR X = 1 TO MY.LEN
            IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
         NEXT X
    * Should be
         MY.DATA = CHANGE(MY.DATA,";",@FM)
    
    * Not using case
         MY.METHOD = 'CreateReport'
         IF MY.METHOD = 'UpdateRecord' THEN
         END
         IF MY.METHOD = 'CreateReport' THEN
         END
    * Should be
         BEGIN CASE
            CASE MY.METHOD = 'UpdateRecord'
            CASE MY.METHOD = 'CreateReport'
         END CASE
    
    * Testing for Universe or Unidata
         UNIVERSE = @FALSE
         OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
    * Should be
         IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE
    
    * Finding a JSON value
         JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
         JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
         JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
         JSON = CONVERT(\\{"]\\,"",JSON)
         MAX.FM = DCOUNT(JSON,@FM)
         FOR X = 1 TO MAX.FM
            IF JSON



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    I recall before PERFORM or EXECUTE and having to write COMMON data to a work file and re-entrant program logic before using PROCWRITE and CHAIN to a  PROC to (effectively) substitute for EXECUTE. Once the PROC had done what was needed  (typically using a SELECT or another program) it would run the original program which would use PROCREAD to pick up arguments for a re-entry point, the program would re-open files and READ and load COMMON before jumping to a different label depending upon the re-entry point provided by the PROC.

    For what ot is worth - I can remember (for Company policy reasons - don't ask), we wrote and used a fully-functional PL system using only PQN proc.

    Of the fun...

    JJ



    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------

    JJ
    Jonathan Smith
    Rocketeer
    Feb 27, 2023 4:29 AM UTC

    I am that old, that I remember Pick BASIC systems that did not have DCOUNT

    And I remeber when DCOUNT came out and everyone was like, finally.



    ------------------------------
    Will Johnson
    Systems Analyst
    Rocket Forum Shared Account
    ------------------------------

    Just a quick note, I noted in Dougs example he was using MAX.FM = COUNT(MY.ARRAY,@FM)+ 1 as a replacement for DCOUNT, this works fine if MY.ARRAY is not empty. The full logic to use COUNT as a replacement for DCOUNT is COUNT(MY.ARRAY,@FM) + (MY.ARRAY NE "")



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    John Jenkins
    Participating Frequently
    Feb 27, 2023 5:46 AM UTC

    Just a quick note, I noted in Dougs example he was using MAX.FM = COUNT(MY.ARRAY,@FM)+ 1 as a replacement for DCOUNT, this works fine if MY.ARRAY is not empty. The full logic to use COUNT as a replacement for DCOUNT is COUNT(MY.ARRAY,@FM) + (MY.ARRAY NE "")



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------

    Jonathan

    Nice: many is the time I have seen that one, though more commonly as the far less elegant 

    IF COUNT(MY.ARRAY,@FM)=0 THEN

    MAX.FM=1

    END ELSE

    MAX.FM=COUNT(MY.ARRAY,@FM)

    END

    Boolean tests can be great helpers, though z=x=y does seem to confuse some.

    JJ



    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------
    JJ
    John Jenkins
    Participating Frequently
    Feb 27, 2023 6:09 AM UTC

    I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

    I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

    * Using COUNT instead of DCOUNT
         MY.ARRAY = 5:@FM:7:@FM:8
         MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
    * Should be 
         MAX.FM = DCOUNT(MY.ARRAY,@FM)
    
    * Not knowing about WHILE in a LOOP statement
         EXECUTE 'SELECT VOC'
         EOF = 0
         LOOP READNEXT ID ELSE EOF = 1
            IF EOF THEN EXIT
         REPEAT
    * Should be
         LOOP WHILE READNEXT ID
         REPEAT
    
    * Parsing though data instead of CHANGE command
         MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
         MY.LEN = LEN(MY.DATA)
         FOR X = 1 TO MY.LEN
            IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
         NEXT X
    * Should be
         MY.DATA = CHANGE(MY.DATA,";",@FM)
    
    * Not using case
         MY.METHOD = 'CreateReport'
         IF MY.METHOD = 'UpdateRecord' THEN
         END
         IF MY.METHOD = 'CreateReport' THEN
         END
    * Should be
         BEGIN CASE
            CASE MY.METHOD = 'UpdateRecord'
            CASE MY.METHOD = 'CreateReport'
         END CASE
    
    * Testing for Universe or Unidata
         UNIVERSE = @FALSE
         OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
    * Should be
         IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE
    
    * Finding a JSON value
         JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
         JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
         JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
         JSON = CONVERT(\\{"]\\,"",JSON)
         MAX.FM = DCOUNT(JSON,@FM)
         FOR X = 1 TO MAX.FM
            IF JSON



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    Not strictly old BASIC techniques but I do have to pull PROC and NEW PROC into the fold as candidates, not least of all as I was once part of  team that wrote a full PL system in PROC for internal political reasons (if you really want to know why then feel free to PM me).

    I recall an item search procedure that looked for a specific record ID in any file on the system that was written in PROC that later appeared in one of the MV vendors SYSPROG account as supplied code (though I am sure it was independently developed, including the identical spelling mistake in the comments ;-' )

    While I don't have the original code it used PROC file buffers and also PROC subscripting. It is still heavily underrated IMO.

    Regards,

    JJ



    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------
    JJ
    Mike Rajkowski
    Rocketeer
    Feb 27, 2023 9:45 AM UTC

    I have been converting code from R83 to Prime Information, Advance Pick to Unidata, Sequoia Pick to Unidata, D3 to Universe, and even Unidata to Universe, I have seen some really awful code and very morbid. Of course, you are thinking some of the latest Basic commands that I use daily in Universe did not exist in R83 so those programmers did the best they could. While I do not disagree, I am looking at code from customers in 2023 that should have been updated sometime in the last 20 years or at least in the last 10 years.

    I have detailed below my comments with what I found and what I think it should be. I will ignore for the time being GOTO, GOSUB, and ON RESPONSE, for example. I would love to see what you have found as well because it just makes me LOL when I see it.

    * Using COUNT instead of DCOUNT
         MY.ARRAY = 5:@FM:7:@FM:8
         MAX.FM = COUNT(MY.ARRAY,@FM)+ 1
    * Should be 
         MAX.FM = DCOUNT(MY.ARRAY,@FM)
    
    * Not knowing about WHILE in a LOOP statement
         EXECUTE 'SELECT VOC'
         EOF = 0
         LOOP READNEXT ID ELSE EOF = 1
            IF EOF THEN EXIT
         REPEAT
    * Should be
         LOOP WHILE READNEXT ID
         REPEAT
    
    * Parsing though data instead of CHANGE command
         MY.DATA = "Welch, Bob;McVie John;Buckingham, Lindsey"
         MY.LEN = LEN(MY.DATA)
         FOR X = 1 TO MY.LEN
            IF MY.DATA[X,1] = ';' THEN MY.DATA[X,1] = @FM
         NEXT X
    * Should be
         MY.DATA = CHANGE(MY.DATA,";",@FM)
    
    * Not using case
         MY.METHOD = 'CreateReport'
         IF MY.METHOD = 'UpdateRecord' THEN
         END
         IF MY.METHOD = 'CreateReport' THEN
         END
    * Should be
         BEGIN CASE
            CASE MY.METHOD = 'UpdateRecord'
            CASE MY.METHOD = 'CreateReport'
         END CASE
    
    * Testing for Universe or Unidata
         UNIVERSE = @FALSE
         OPEN '&PH&' TO DUMMY ELSE UNIVERSE = @TRUE
    * Should be
         IF SYSTEM(9010) = "UV" THEN UNIVERSE = @TRUE
    
    * Finding a JSON value
         JSON = \\{"IdCode":"2","Description":"Route Not Run","DefaultValue":"0"}\\
         JSON = CHANGE(JSON,\\","\\,\\"\\:@FM:\\"\\)
         JSON = CHANGE(JSON,\\":"\\,\\"\\:@VM:\\"\\)
         JSON = CONVERT(\\{"]\\,"",JSON)
         MAX.FM = DCOUNT(JSON,@FM)
         FOR X = 1 TO MAX.FM
            IF JSON



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    I am glad all the examples in this thread are using  the @ variable and not the CHAR function ( i.e. @FM and not CHAR(254)), which I have seen a lot over the years. 

    While the CHAR(254) works, it can cause problems if/when you switch the codepage/language group to something that requires changing the marks characters.



    ------------------------------
    Mike Rajkowski
    MultiValue Product Evangelist
    Rocket Internal - All Brands
    DENVER CO US
    ------------------------------