A possible trick for files with fixed length records

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

A possible trick for files with fixed length records

Postby lrcvs » Mar 26, 2017 16:07

Hi!

Code: Select all

DIM AS INTEGER a0i, a1i, a2i, a3i, a4i, a5i, a6i, a7i, a8i, a9i, b0i, b1i, b2i, b3i, b4i, b5i, b6i, b7i, b8i, b9i, e0i,e1i
DIM AS STRING a0s, a1s, a2s, a3s, a4s, a5s, a6s, a7s, a8s, a9s, b0s, b1s, b2s, b3s, b4s, b5s, b6s, b7s, b8s, b9s, c0s, c1s, c2s, c3s, c4s, c5s, c6s, c7s, c8s, c9s, d0s, d1s, d2s, d3s, d4s, d5s, d6s, d7s, d8s, d9s

CLS
'test file "structure of dbase"
'fields: ord num, name of field, initial position, long
OPEN "aaa" FOR OUTPUT AS #1
WRITE #1, "1", " dia","1","3"
WRITE #1, "2", " mes","5","7"
WRITE #1, "3", " con","13","9"
CLOSE (1)

'test file "data base"
'mar el ok   asia     <<< special test
OPEN "bbb" FOR OUTPUT AS #2
PRINT #2, "lun enero   europa   "
PRINT #2, "mar el ok   asia     "
PRINT #2, "mie marzo   africa   "
PRINT #2, "jue abril   america  "
PRINT #2, "vie mayo    oceania  "
PRINT #2, "sab junio   artico   "
PRINT #2, "dom febrero antartico"
CLOSE (2)

OPEN "aaa" FOR INPUT AS #1
WHILE NOT EOF(1)
    INPUT #1, a0s,a1s,a2s,a3s
    PRINT a0s;a1s
WEND
CLOSE (1)
PRINT

INPUT "option number (1,2,3) = ";b0s
PRINT

OPEN "aaa" FOR INPUT AS #1
WHILE NOT EOF(1)
    INPUT #1, a0s,a1s,a2s,a3s
    IF a0s = b0s THEN
        a0i = VAL(a2s):a1i = VAL(a3s)
        OPEN "bbb" FOR INPUT AS #2
        WHILE NOT EOF(2)
            INPUT #2, c0s
            PRINT MID(c0s,a0i,a1i)
        WEND
        CLOSE (2)
    END IF
WEND
CLOSE (1)
PRINT

INPUT "Write a word of the list = ";d1s
d1s = LCASE(d1s)
PRINT

OPEN "aaa" FOR INPUT AS #1
WHILE NOT EOF(1)
    INPUT #1, a0s,a1s,a2s,a3s
    IF a0s = b0s THEN
        a0i = VAL(a2s)
        a1i = VAL(a3s)
        OPEN "bbb" FOR INPUT AS #2
        WHILE NOT EOF(2)
            INPUT #2, c0s
            IF MID(c0s,a0i,a1i) = d1s THEN PRINT "ok" ELSE PRINT "error!"
        WEND
        CLOSE (2)
    END IF
WEND
CLOSE (1)

'===============================================================================
'a possible solution of the problem
'===============================================================================
print
print "========================================================================="
PRINT
'INPUT "Now write a word of the list = ";d1s
PRINT

b1i = LEN(d1s)
d2s = ""
FOR e1i = 1 TO b1i
    IF MID(d1s,e1i,1) <> " " THEN d2s = d2s +  MID(d1s,e1i,1)
NEXT e1i

OPEN "aaa" FOR INPUT AS #1
WHILE NOT EOF(1)
    INPUT #1, a0s,a1s,a2s,a3s
    IF a0s = b0s THEN
        a0i = VAL(a2s)
        a1i = VAL(a3s)
        OPEN "bbb" FOR INPUT AS #2
        WHILE NOT EOF(2)
            INPUT #2, c0s
            d3s = ""
            FOR e0i = a0i TO a0i+a1i
                IF MID(c0s,e0i,1) <> " " THEN d3s = d3s +  MID(c0s,e0i,1)
            NEXT e0i
            IF d2s = d3s THEN PRINT "ok" ELSE PRINT "error!"
        WEND
        CLOSE (2)
    END IF
WEND
CLOSE (1)

SLEEP
END

lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: A possible application for "input"

Postby lrcvs » Mar 27, 2017 19:36

Hi:

Code: Select all

declare function ctrim (t as string,d as string) as string

dim as string a,b,c,d,r
dim as integer z,y,x,w
a = "a b c d"
b = "a b c                d"
print "a = ";a
print "b = ";b
print
input "You print b = ";c
d = ctrim (b," ")
r = ctrim (c," ")
if d = r then print "ok" else print "error"
sleep
end

'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function ctrim (t as string, d as string) as string
'Function: "CenterTrim"
'T: Text to be cleaned
'D: Character to be deleted
dim a as string
dim as integer b,c
a = ""
b = len(t)
for c = 1 to b
if mid(t,c,1) <> d then a = a +  mid(t,c,1)
next c
return a
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



Regards
integer
Posts: 378
Joined: Feb 01, 2007 16:54
Location: usa

Re: A possible application for "input"

Postby integer » Mar 27, 2017 21:28

That is one AMAZING trick.
I thought I was selecting & getting this:

Code: Select all

DIM AS STRING a,b,c,d,r
DIM AS INTEGER z,y,x,w

a = "OSCAR"
b = "OSC                AR"

PRINT "a = ";a
PRINT "b = ";b
PRINT
INPUT "You print b = ";c
PRINT

z = LEN(c)
d = ""
FOR x = 1 TO z
    IF MID(c,x,1) <> " " THEN d = d +  MID(c,x,1)
NEXT x

w = LEN(b)
r = ""
FOR y = 1 TO w
    IF MID(b,y,1) <> " " THEN r = r +  MID(b,y,1)
NEXT y

IF d = r THEN PRINT "ok, A = B" ELSE PRINT "error, A <> B"
SLEEP
END


However, when I pasted it into FreeBasic, I got the following:
[quote="lrcvs"]Hi:

Code: Select all

declare function ctrim (t as string,d as string) as string

dim as string a,b,c,d,r
dim as integer z,y,x,w
a = "a b c d"
b = "a b c                d"
print "a = ";a
print "b = ";b
print
input "You print b = ";c
d = ctrim (b," ")
r = ctrim (c," ")
if d = r then print "ok" else print "error"
sleep
end

'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function ctrim (t as string, d as string) as string
'Function: "CenterTrim"
'T: Text to be cleaned
'D: Character to be deleted
dim a as string
dim as integer b,c
a = ""
b = len(t)
for c = 1 to b
if mid(t,c,1) <> d then a = a +  mid(t,c,1)
next c
return a
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Would you please explain how that was done?
That is .... is .... is -- I don't know what it is but it is a really neat trick.
I thought I was able to copy a snippet, but got something totally unexpected.
wow
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: A possible trick for files with fixed length records

Postby lrcvs » Mar 28, 2017 12:30

Hi:

Code: Select all

Thank you for your interest in the program.

Well, as you can see, it's a very simple program, but it solves a problem for me.

My data files are of limited length and all fields are well aligned.

Until a week ago, I used the command: "instr", well, no problem.

But now I want to use a structure file to make the searches simpler, with less code.

What I am trying to do is to use a search program where I can use the options: "=", "<", ">", "<>", "<=", "> =" .... and that These options serve me for any field of search.

When doing a test with an indeterminate field, for example: "month" (months), I wrote: "May", ... but gave me "error".

I asked myself: "Is not this possible?"

Both words are "apparently" the same.

The length of the search field is greater than the search word, so I am also reading characters / spaces in blanks/white.

Use "Trim", but only removes the lateral spaces of the word or phrase to search.

Well, to find a solution to the problem, I had to delete the blanks, for this I did this little utility / program.

If you look at the program, it simply removes any characters (in this case whites), joins  all the letters of a word or phrase in a single word.

Example:

"abc de fg h" = "abcdefgh"

As we see, if I write: "a b c def gh", and one all the letters I get the same word: "abcdefgh", then both words are the same and I have no error reading the blanks.

Also, when using it with the "inputs", if I write two or more spaces enter letters, I have no error.

Note:

"CTRIM" ("CENTER" + TRIM),  is simply a function that solves the problem and saves code!




regards
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Re: A possible trick for files with fixed length records

Postby Cherry » Mar 29, 2017 14:27

What are you guys talking about? I don't get it :-/

First I thought it's about a programming trick (which I didn't really understand either), then it sounded like a forum trick, but I don't see which one because when I copy the snippets here I get what I expected to get!
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: A possible trick for files with fixed length records

Postby lrcvs » Mar 30, 2017 16:45

Hi, Cherry:

Sorry, I do not understand your comment.
What is your question or doubt?

Regards
dodicat
Posts: 5773
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: A possible trick for files with fixed length records

Postby dodicat » Mar 31, 2017 1:01

Hi lrcvs
I did this years ago, it strips your .bas file of all unnecessary leading/lagging characters , empty lines, comments.
Block comments are saved as are comments on code lines.
It is a .bas file de-beautifier.
You can choose the severity.

Code: Select all


declare function getfile(file as string) as string
declare sub arraydeletestring(a() as string,index as integer)
declare Sub string_split(byval s_in As String,char As String,result() As String)
#include "file.bi"
dim as string s,path
Redim As String answer()
      'Get your file by drag and drop -- use pah=command(1)
      'OR
     
path=  "   .bas" '<<----------   YOUR FILE


redim as string temp()

if fileexists(path)=0 then
    print "no input file"
    sleep
    end
end if

string_split(path,"\",temp())

dim as string file=mid(temp(ubound(temp)),len(ubound(temp))-3)
print file
Print "Please wait"
print
'GET FILE AND SPLIT IT INTO LINES
s= getfile(path)
string_split(s,chr(10),answer())
print "Original number of lines ";ubound(answer)

'GET RID OF LEADING SPACES
#macro delete_leading_blanks()
for z as integer=1 to ubound(answer)
    answer(z)=ltrim(answer(z))
next z
#endmacro

'GET RID OF LAGGING SPACES
#macro delete_lagging_blanks()
for z as integer=1 to ubound(answer)
    answer(z)=rtrim(answer(z))
next z
#endmacro


'GET RID OF EMPTY LINES
dim z as integer
#macro delete_empty_lines()
    do
        z=z+1
    if len(answer(z))=0 then
        arraydeletestring(answer(),z)
        z=z-1
    end if
loop until z=ubound(answer)
z=0
#endmacro
'GET RID OF LINE COMMENTS
#macro delete_line_comments()
    do
        z=z+1
    if left(answer(z),1)="'" then
        arraydeletestring(answer(),z)
        z=z-1
    end if
loop until z=ubound(answer)
z=0
#endmacro
'WRITE TO NEW FILE
dim as long f
#macro write_to_new_file()
f=1
open "Compact"+file for output as #3
for z as integer=1 to ubound(answer)
    print #3,answer(z)
next z
close #3
#endmacro


' *************  CHOOSE FROM THESE, OR USE ALL OF THEM  **************************

delete_leading_blanks()
delete_lagging_blanks()
delete_empty_lines()
delete_line_comments()
write_to_new_file()


print "Number of lines now =    ";ubound(answer)
print
dim as integer counter
for z as integer=lbound(answer) to ubound(answer)
   counter=counter+len(answer(z))
next z

print "Number of characters before = ";len(s)
print "Number of characters now =    ";counter
print
if f then print "File saved as ";"Compact"+file
sleep



function getfile(file as string) as string
Dim As Integer F = Freefile
Dim intxt As String
Dim text As String

open file For Input As #F
Line Input #F, text

While Not Eof(f)
        Line Input  #F, intxt
        text = text +(Chr(10)) + intxt
Wend
return text

end function

Sub string_split(byval s As String,chars As String,result() As String)
    redim result(0)
    Dim As String var1,var2
Dim As long pst
      #macro split(stri)
    pst=Instr(stri,chars)
    var1="":var2=""
    If pst<>0 Then
    var1=Mid(stri,1,pst-1)
    var2=Mid(stri,pst+1)
    Else
    var1=stri
End if
    if len(var1) then
    redim preserve result(1 to ubound(result)+1)
    result(ubound(result))=var1
    end if
    #endmacro
   Do
   split(s):s=var2
Loop Until var2=""
End Sub
' ******************************************************
sub arraydeletestring(a() as string,index as integer)
    if index>=lbound(a) and index<=ubound(a) then
    dim x as integer
    for x=index to ubound(a)-1
         a(x)=a(x+1)
    next x
    redim preserve a(lbound(a) to ubound(a)-1)
    endif
    end sub


 
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: A possible trick for files with fixed length records

Postby lrcvs » Mar 31, 2017 15:31

Hi, dodicat:

Firstly, thank you as always for your interest and comments.

As far as I see your program, clean a text file of empty lines, unnecessary spaces and lines of comments, and leave a clean file of useless things.

It is a great program and very useful!

Well, I have a similar one, but mine removes "rare" text characters (signs, vowels and consonants chr $ (> 122)).

Code: Select all

#LANG "QB"
DECLARE FUNCTION LIMPIAR$(A1$)
CLS
OPEN "CONSUMIBLES.TXT" FOR INPUT AS #3
OPEN "CONSUMIBLES3.TXT" FOR APPEND AS #4

WHILE NOT EOF (3)
INPUT #3, A1$
IF INSTR(LIMPIAR$ (A1$),"*") = 0 THEN PRINT #4, A1$
WEND
CLOSE #3
CLOSE #4
PRINT "FIN"
SLEEP
END
 

FUNCTION LIMPIAR$ (A1$)
a2$ = ""
FOR z = 1 TO LEN (a1$)
    c$ = MID$(a1$,z,1)
   
        IF c$ = CHR$(131) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(132) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(133) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(134) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(160) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(166) THEN c$ = "a" : goto vuelta
        IF c$ = CHR$(142) THEN c$ = "A" : goto vuelta
        IF c$ = CHR$(143) THEN c$ = "A" : goto vuelta
       
        IF c$ = CHR$(136) THEN c$ = "e" : goto vuelta
        IF c$ = CHR$(137) THEN c$ = "e" : goto vuelta
        IF c$ = CHR$(138) THEN c$ = "e" : goto vuelta
        IF c$ = CHR$(145) THEN c$ = "e" : goto vuelta
        IF c$ = CHR$(144) THEN c$ = "E" : goto vuelta
        IF c$ = CHR$(146) THEN c$ = "E" : goto vuelta
       
        IF c$ = CHR$(139) THEN c$ = "i" : goto vuelta
        IF c$ = CHR$(140) THEN c$ = "i" : goto vuelta
        IF c$ = CHR$(141) THEN c$ = "i" : goto vuelta
        IF c$ = CHR$(161) THEN c$ = "i" : goto vuelta
       
        IF c$ = CHR$(147) THEN c$ = "o" : goto vuelta
        IF c$ = CHR$(148) THEN c$ = "o" : goto vuelta
        IF c$ = CHR$(149) THEN c$ = "o" : goto vuelta
        IF c$ = CHR$(162) THEN c$ = "o" : goto vuelta
        IF c$ = CHR$(153) THEN c$ = "O" : goto vuelta

        IF c$ = CHR$(129) THEN c$ = "u" : goto vuelta
        IF c$ = CHR$(150) THEN c$ = "u" : goto vuelta
        IF c$ = CHR$(151) THEN c$ = "u" : goto vuelta
        IF c$ = CHR$(163) THEN c$ = "u" : goto vuelta
        IF c$ = CHR$(154) THEN c$ = "U" : goto vuelta
       
   
    IF c$ = CHR$(32) THEN a2$ = a2$ + c$ : goto vuelta
   
    FOR n = 48 TO 57
        IF c$ = CHR$(n) THEN a2$ = a2$ + c$ : goto vuelta       
    NEXT n   
    FOR n = 65 TO 90
        IF c$ = CHR$(n) THEN a2$ = a2$ + c$ : goto vuelta
    NEXT n   
    FOR n = 97 TO 122
        IF c$ = CHR$(n) THEN a2$ = a2$ + c$ : goto vuelta
    NEXT n   
    FOR n = 0 TO 31
        IF c$ = CHR$(n) THEN a2$ = a2$ + "*"  : goto vuelta     
    NEXT n   
    FOR n = 33 TO 47
        IF c$ = CHR$(n) THEN a2$ = a2$ + "*" : goto vuelta
    NEXT n   
    FOR n = 92 TO 96
        IF c$ = CHR$(n) THEN a2$ = a2$ + "*" : goto vuelta
    NEXT n   
    FOR n = 123 TO 255
        IF c$ = CHR$(n) THEN a2$ = a2$ + "*" : goto vuelta
    NEXT n
    vuelta:
NEXT z
LIMPIAR$ = A2$
END FUNCTION


Now, my work database is composed of 22 fields and each field has a length of 700 characters, I currently have 2193 records.

Here is a sample:

Code: Select all


2184 0000 1 1 00 XXX N XLXCTRXCXDXD PXVXDX  S L                       M4 X  VXLLXNX             XXXXXXXXXXXXXXXXXXXXXXXXX                  XLXCTRXCXDXD XN GXNXRXL              999999999 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2185 0000 1 1 00 XXX N XLXCTRXXNFX  S L L                             M4 X  VXLLXNX             XXXXXXXXXXXXXXXXXXXXXXXXX                  XLXCTRXCXDXD XN GXNXRXL              999999999 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
218X 0000 1 1 00 XXX N FCX  XNTXNXX JXSX XSTXVXN XYXLX CB             M4 X  VXLLXNX             XNTXNXX XSTXVXN                            XLXCTRXCXDXD XN GXNXRXL              555951872 999999999 999999999 XSTXVXNXXCTRxxx@GMXXL.CXM                                  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2187 0000 0 1 00 XXX N FXRRX                                          M4 X  VXLLXNX             LXXS FXRNXNDX / GXSPXR JXRDXN              FXRRXT  XNDXST Y XGRXCXLX            555753534 555807327 999999999 XNxx@FXRRX XS                                              XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2188 0000 0 3 00 XXX N GXNDXX                                         M4 X  VXLLXNX             JXXN GXRCXX NXVXRRX                        XNST  Y MXNT  XLXCTRXCX              555814932 555801593 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2189 0000 1 1 00 XXX N XLXCTRXDXD RXMXN RXJXS                         M4 X  VXLLXNX             XXXXXXXXXX                                 XLXCTRXCXDXD XN GXNXRXL              999999999 999999999 X3010587X XXXXXXXXXX                                                 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2190 0000 1 1 00 XXX N XLXY MXTXX MXRX  S X                           M4 X  VXLLXNX             XXXXXXXXXXXXXXXXXXXXXXXXX                  XLXCTRXCXDXD XN GXNXRXL              999999999 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2191 0000 1 1 00 XXX N XCXMXRCX XG0009                                XX 99 XXXXXXXXXX          XXXXXXXXXX                                 XXXXXXXXXXX                          999999999 999999999 999999999 XXXXXXXXXX                                                 XXXXXXXXXX                                                                                                                                           ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2192 0000 0 2 00 XXX N XCXSX                                          V2 MX YXCLX               FRXNCXSCX XRTXNX                           XNST  Y MXNT  XLXCTRXCX              9X9990378 999999999 5555559X3 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2193 0000 0 1 00 XXX N XNDXSTRXXS DXVXD                               V2 MX YXCLX               FRXNC                                      CXNST  DX MXQXXNXRXX                 999999999 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2194 0000 0 3 00 XXX N JXXN HXRMXNXS                                  V2 MX YXCLX               JXXN XBXNXZ                                XNST  Y MXNT  XLXCTRXCX              555791184 555795117 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2195 0000 0 3 00 XXX N SXNTX                                          V2 MX YXCLX               XNTXNXX                                    XNST  Y MXNT  XLXCTRXCX              999999999 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
219X 0000 0 2 00 XXX N SXNTXXGX CXSTXLLX                              V2 MX YXCLX               SXNTXXGX CXSTXLLX                          XNST  Y MXNT  XLXCTRXCX              55579XX31 999999999 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////
2197 0000 0 1 00 XXX N XLXCTRXCXDXD CXRVXRX                           V2 MX YXCLX               XNTXNXX                                    XNST  Y MXNT  XLXCTRXCX              55579043X 55579X353 999999999 X_MXXL                                                     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------------------------------------------------------------------------------------------- **************************************************************************************************** ////////////////////////////////////////////////////////////////////////////////////




 This is my "log structure" file:


Code: Select all

"C_L 4   1   4   CODIGO LRCVS                    "
"C_E 4   6   9   CODIGO ELECTROXXXXX             "
"INT 1   11  11  INTERES COMERCIAL 0..5          "
"POT 1   13  13  POTENCIAL DE COMPRA 0..5        "
"VEN 2   15  16  VENTAS AÑO ANTERIOR             "
"XXX 3   18  20  ESPACIO DEJADO EN PREVISION     "
"VIS 1   22  22  VISITAR LA EMPRESA S/N          "
"EMP 47  24  70  NOMBRE DE LA EMPRESA / CLIENTE  "
"DIA 1   71  71  DIA DE VISITA LMXJV             "
"SEM 1   72  72  NUMERO DE SEMANA DEL MES 1..4   "
"PRV 2   74  75  MATRICULA DE LA PROVINCIA       "
"POB 20  77  96  NOMBRE DE LA POBLACION          "
"ENC 43  97  139 NOMBRE DEL ENCARGADO DE COMPRAS "
"ACT 36  140 176 ACTIVIDAD DE LA EMPRESA         "
"TLF 9   177 185 NUMERO DE TELEFONO              "
"FAX 9   187 195 NUMERO DE FAX                   "
"MOV 9   197 205 NUMERO DE MOVIL                 "
"MAI 55  207 265 DIRECCION CORREO ELECTRONICO    "
"OBS 147 266 413 OBSERVACIONES DE TODO TIPO      "
"CON 100 415 514 CONSUMIBLES                     "
"MAR 100 516 615 MARCAS CON LAS QUE TRABAJA       "
"PRO 84  617 700 PROVEEDORES DEL CLIENTE         "





As you can see is a limited log file in longitdud (all records have the same length)

Equally, each field has a certain length.
All fields are separated by spaces / blanks.

When I used "instr", I had no problem, but now I had it when I read a field, then read the text and the targets and gave me error.

With this simple program / simple routine / simple function, from this post, I have solved this "small" detail.

Also this function can be valid for readings of "inputs" and bla, bla, bla ...


Note:
If you use a text editor, you will see my database better.
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: A possible trick for files with fixed length records

Postby lrcvs » Mar 31, 2017 16:26

Hi:

'The advantage of a file structure with this format is that it is very easy to sort a file, simply indecate the initial position of the field that we want to sort and do:


'p$ = position initial of field
'file1.txt file initial
'file2.txt file sort

input "Position to sort = ";p$
cls
shell "sort /+"+p$+ " file1.txt > file2.txt"
print "fin"
sleep
end

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests