EPOC   SDK Home Glossary   Previous Next Up

Label — Inserts a new label into a database

If you insert a new label in a database, the entries will no longer match up with the labels. Rather than using the ‘Update’ option on every entry, to insert a suitable blank line in each one, you can use this program to do this for the entire data file.

The Data application allows you to use as many lines (fields) as you want in an entry (record); OPL can only access 32 fields. This program only lets you insert a new field in the first 16 fields, although you can adapt the program simply to check up to 31 fields.

If, in Data, you enter a line longer than 255 characters, it is stored as two fields, with a character of code 20 at the start of the second field. This program correctly handles any such fields.

The program checks that the 17th field is blank, as it will be overwritten by what was the 16th field. If a long entry has a 17th field, and it contains text, the program skips this entry. The rest of longer entries - even if there are more than 32 fields will be unchanged.

If you insert a new field at a position below the last label, Data will not show it, even when using ‘Update’.

The maximum record length in OPL is 1022 characters. The OPEN command will display a ‘Record too large’ error if the file contains a record longer than this.

    PROC label:
          LOCAL a%,b%,c%,d%,s$(128),s&,i$(17,255)
          s$="\dat\*.dbf"
          dINIT "Insert new field"
          dFILE s$,"Data file",0
          dLONG s&,"Break at line (1-16)",1,16
          IF DIALOG
                OPEN s$,A,a$,b$,c$,d$,e$,f$,g$,h$,i$,j$,k$,l$,m$,n$,o$,p$,q$
                c%=COUNT :a%=1
                WHILE a%<=c%
                      AT 1,1 :PRINT "Entry",a%,"of",c%,
                      IF A.q$=""      REM Entry (hopefully) not too long   
                            i$(1)=A.a$ :i$(2)=A.b$ :i$(3)=A.c$
                            i$(4)=A.d$ :i$(5)=A.e$ :i$(6)=A.f$
                            i$(7)=A.g$ :i$(8)=A.h$ :i$(9)=A.i$
                            i$(10)=A.j$ :i$(11)=A.k$ :i$(12)=A.l$ 
                            i$(13)=A.m$ :i$(14)=A.n$ :i$(15)=A.o$
                            i$(16)=A.p$   
                            d%=0 :b%=0
                            WHILE d%<s&+b%        REM find field to break at
                                  d%=d%+1
                                  IF LEFT$(i$(d%),1)=CHR$(20)
                                        REM line>255...
                                        b%=b%+1  REM ...so it’s 2 fields
                                  ENDIF
                            ENDWH
                            b%=17
                            WHILE b%>d%      REM copy the fields down
                                  i$(b%)=i$(b%-1) :b%=b%-1
                            ENDWH
                            i$(d%)=""            REM and make an empty field
                            A.a$=i$(1) :A.b$=i$(2) :A.c$=i$(3)
                            A.d$=i$(4) :A.e$=i$(5) :A.f$=i$(6)
                            A.g$=i$(7) :A.h$=i$(8) :A.i$=i$(9)
                            A.j$=i$(10) :A.k$=i$(11) :A.l$=i$(12)
                            A.m$=i$(13) :A.n$=i$(14) :A.o$=i$(15)
                            A.p$=i$(16) :A.q$=i$(17)
                      ELSE
                            PRINT "has too many fields"
                            PRINT "Press a key..." :GET
                      ENDIF
                UPDATE :FIRST
                a%=a%+1
                ENDWH :CLOSE
          ENDIF
    ENDP
EPOC       SDK Home Glossary   Previous Next Up