Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Argument starter - The roots of all evil
Message
From
03/09/2004 14:05:34
 
 
To
03/09/2004 03:04:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00938079
Message ID:
00939253
Views:
29
In FPW2.6, if you selected MSlinedraw or FoxFont and beautify with action diagram symbols, it would format the code connecting logical blocks with line characters and shows each exit point with line characters out of the block. Very handy for reading a long chunk of unfamiliar code. Unfortunately, I think the action diagram option has been dropped in later versions. If not, I would appreciate someone pointing out where it is located. I still use 2.6 for this feature on occasion when writing or modifying code if I have a very long procedure, especially if I get distracted and miss or misplace an endif. If you have FPW2.6, check it out next time you have some spagetti code to read. It has saved me many hours many times over. A word of caution though, I don't modify the code there as it doesn't always do well for some of the newer stuff.

The ability to collapse or expand logical blocks would be very cool indeed. That sounds like a great wish list item or utility.


>I've often thought I good editor would let you collapse logical blocks a bit like viewing XML.
>
>You could choose to open up a IF ENDIF block or DO ENDDO
>
>I never used beautify. Perhaps I should have tried it.
>
>Nick Mason
>
>>When I encounter code like that, I drop it into a prg in FPW2.6 and use beautify with "action diagram symbols" to easily connect all if/endif, do case/endcase, for/next, do while/enddo and other constructs. It connects the dots so to speak. It also helps to highlight all exit points, loops and returns. I have been unable to find the "beautify with action diagram symbols" option in later versions and really miss it.
>>
>>
>>
>>
>>>It looks like FPD26 code that I have to read through everyday. Guess I've gotten used to it, but that doesn't mean I like it one bit.
>>>
>>>
>>>>Dear all
>>>>
>>>>They say that every picture speaks a 1000 words. Well here's several thousand words that might paint a picture for you. To save having to make several points, I hope you don't mind, but I enclose the prog I've been trying to debug. Maybe this will give more insight to my "state of mind", and help make my point. I think it says it all. Please note the liberal coating of loops, exits, returns and skips. Personally I'd prefer to have control constructs in one place only (including the skips), usually at the bottom of the loop. I've deleted several feet of the code including the sparse comments, some instantiations and some white space, to save space here.
>>>>
>>>>Read it and weep.
>>>>
>>>>Terry
>>>>
>>>>
>>>>create table mustread (;
>>>> driver c(50),;
>>>> path c(50),;
>>>> short c(12))
>>>>index on driver tag driver
>>>>sele 0
>>>>use datadirs order 2 exclu
>>>>pack
>>>>dtest=""
>>>>
>>>>do toread2      && prog
>>>>
>>>>sele tempread
>>>>use
>>>>set defa to (opdir)
>>>>sele 0
>>>>use infmread
>>>>copy stru to thisread cdx
>>>>use
>>>>sele 0
>>>>use thisread exclu
>>>>if !file('badmods.dbf')
>>>>   copy stru to badmods cdx
>>>>endif
>>>>if reccount()>0
>>>>   ?? chr(7)
>>>>   do choose with 'Recovering from previous crashed run. Press space'
>>>>   goto bott
>>>>   scatter memvar
>>>>   sele 0
>>>>   use badmods
>>>>   append blank
>>>>   gather memvar
>>>>   use
>>>>endif
>>>>
>>>>sele thisread
>>>>set order to 1
>>>>zap
>>>>
>>>>sele 0
>>>>use infmread
>>>>set order to 1
>>>>
>>>>sele mustread
>>>>pack
>>>>
>>>>pcount=reccount()
>>>>@ 10,20 say "Files to read "+str(pcount,6,0)
>>>>if pcount=0
>>>>   ?? chr(7)
>>>>   do choose with "No data to read. Press space"
>>>>   close data
>>>>   erase mustread.dbf
>>>>   return
>>>>endif
>>>>goto top
>>>>do prompt with "Browse. <escape> to exit"
>>>>defi wind view from 3,2 to 20,78 color sche 10
>>>>brow  fields short :H='Module',path noapp noedit nodele wind view ;
>>>>   title "To read"
>>>>
>>>>do while .T.
>>>>   do choose with "(C)ontinue to read    (A)bandon"
>>>>   if cs$"CA"
>>>>      exit
>>>>   endif
>>>>enddo
>>>>if cs="A"
>>>>   close data
>>>>   erase mustread.dbf
>>>>   set defa to (opdir)
>>>>   return
>>>>endif
>>>>
>>>>close data
>>>>
>>>>xbytes=o_tickbyte
>>>>cc=0
>>>>xop=1
>>>>empty=0
>>>>xdriver=''
>>>>xbus=0
>>>>xduty=0
>>>>
>>>>if !file('dumpfile.dbf')
>>>>   sele 0
>>>>   use waymcl
>>>>   copy stru to dumpfile
>>>>   use
>>>>endif
>>>>
>>>>sele 25
>>>>use dumpfile
>>>>
>>>>sele 24
>>>>use infmread order 1
>>>>
>>>>sele 22
>>>>use thisread order 1
>>>>
>>>>sele 21
>>>>use badmods order 1
>>>>
>>>>sele 23
>>>>use mustread alias willread
>>>>goto top
>>>>
>>>>do while !eof()          && willread
>>>>   sele 7
>>>>   use transid order 1
>>>>
>>>>   sele 6
>>>>   use waymcl      && file storing extracted data
>>>>   copy stru to mcltemp    && temp file
>>>>   copy stru to wayfare    && holds all extracted records
>>>>   use mcltemp              && hold selected records
>>>>
>>>>   sele 5
>>>>   use emptymod order 1       && do not empty
>>>>
>>>>   do heading with "Read and convert ETM data"
>>>>
>>>>   sele 2
>>>>   use wayfare excl     && hold extracted records
>>>>   zap
>>>>
>>>>   sele 1
>>>>   use dec2hex order 1
>>>>
>>>>   sele willread
>>>>   goto top
>>>>
>>>>   ff=0
>>>>   @ 14,0 clear to 20,79
>>>>   set esca on
>>>>   isesca=.F.
>>>>   on escape isesca=.T.
>>>>   @ 7,10 say "Once processing is under way press <Esc> to pause / abandon"
>>>>   @ 8,10 say "after the modules detailed below"
>>>>   do choose with "Note message above. Press space to start processing"
>>>>   if lastkey()=27
>>>>      close data
>>>>      set esca off
>>>>      return
>>>>   endif
>>>>
>>>>   do while !eof()    && willread
>>>>
>>>>      ff=ff+1
>>>>      @ 11,20 say "   Files read "+str(ff,6,0)
>>>>
>>>>      tshort=alltrim(short)
>>>>      tlong=alltrim(driver)
>>>>      tpath=alltrim(path)
>>>>
>>>>      tfile=tpath+tshort
>>>>      tread=padr(tlong,50)
>>>>
>>>>      do prompt with "Reading "+tread
>>>>
>>>>   if isesca
>>>>      acti wind alert
>>>>      @ 4,7 say "  Process interrupted"
>>>>      @ 5,7 say "Read action options below"
>>>>      acti scree
>>>>      ?? chr(7)
>>>>      do while .t.
>>>>         do choose with "Process interrupted. (R)esume  (A)bandon "
>>>>         if cs$"RA"
>>>>            exit
>>>>         endif
>>>>      enddo
>>>>      deac wind alert
>>>>      if cs="A"
>>>>         set esca off
>>>>         exit
>>>>      endif
>>>>   endif
>>>>   isesca=.F.
>>>>
>>>>      store fopen(tfile) to f_handle       && file num
>>>>      store fseek(f_handle,0,2) to eofile    && eof
>>>>      store fseek(f_handle,0) to bofile      && bof
>>>>
>>>>
>>>>      if eofile<=0      && file is empty
>>>>         * wait wind tfile+" is empty" nowait
>>>>         empty=empty+1
>>>>         sele emptymod
>>>>         seek tread
>>>>         if !found()
>>>>            append blank
>>>>            repla file with tread,event with "EM"
>>>>         endif
>>>>         =fclose(f_handle)
>>>>
>>>>         sele infmread
>>>>         seek tread+dtos(nuldate)
>>>>         if !found()
>>>>           append blank
>>>>           repla driver with tread
>>>>         endif
>>>>         sele willread
>>>>         skip
>>>>
>>>>         loop
>>>>      endif
>>>>
>>>>      xdriver=''
>>>>     for xx=7 to 9
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xdriver=xdriver+b
>>>>      endfor
>>>>      xdate=""
>>>>      for xx=10 to 12
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xdate=xdate+b
>>>>      endfor
>>>>      yy=right(xdate,2)
>>>>      if val(yy)<90
>>>>         yy="20"+yy
>>>>      else
>>>>         yy="19"+yy
>>>>      endif
>>>>      tickdate=ctod(left(xdate,2)+"/"+substr(xdate,3,2)+"/"+yy)
>>>>      xontime=''
>>>>     for xx=13 to 14
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xontime=xontime+b
>>>>      endfor
>>>>      xofftime=''
>>>>     for xx=19 to 20
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xofftime=xofftime+b
>>>>      endfor
>>>>      if !between(tickdate,xfrom,xto)
>>>>         =fclose(f_handle)
>>>>         sele willread
>>>>         skip
>>>>
>>>>         loop
>>>>      endif
>>>>      sele badmods
>>>>      seek tread+dtos(tickdate)
>>>>      if found()
>>>>         =fclose(f_handle)
>>>>         sele willread
>>>>         skip
>>>>
>>>>         loop
>>>>      endif
>>>>      sele infmread
>>>>      seek xdriver+dtos(tickdate)+xontime+xofftime
>>>>      if found()
>>>>         =fclose(f_handle)
>>>>         sele willread
>>>>         skip
>>>>
>>>>         loop
>>>>      endif
>>>>      sele thisread
>>>>      seek xdriver+dtos(tickdate)+xontime+xofftime
>>>>      if found()
>>>>         =fclose(f_handle)
>>>>         sele willread
>>>>         skip
>>>>         loop
>>>>      else
>>>>         append blank
>>>>         repla driver with xdriver,;
>>>>           ondate with tickdate,;
>>>>           ontime with xontime,;
>>>>           offtime with xofftime
>>>>      endif
>>>>      xcash=""
>>>>      for xx=64 to 67
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xcash=xcash+b
>>>>      endfor
>>>>      totfare=totfare+val(xcash)
>>>>      xtickets=""
>>>>      for xx=76 to 79
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xtickets=xtickets+b
>>>>      endfor
>>>>      tottick=tottick+val(xtickets)
>>>>      xpasses=""
>>>>      for xx=80 to 83
>>>>         =fseek(f_handle,xx,0)
>>>>         a=asc(fread(f_handle,1))
>>>>         sele dec2hex
>>>>         seek a
>>>>         b=hex
>>>>         xpasses=xpasses+b
>>>>      endfor
>>>>      tottick=tottick+val(xpasses)
>>>>      =fseek(f_handle,256,0)
>>>>      do while !feof(f_handle)
>>>>          if !is02()
>>>>             exit
>>>>          endif
>>>>          do lentrans
>>>>          sele transid
>>>>          seek xtrans
>>>>          isticket=iif(found('transid'),.t.,.f.)
>>>>         do case
>>>>            case xtrans$'0002,001F,0030'      && start of duty
>>>>              * get date,driver no,bus no,dutyno
>>>>              do getduty with xtrans
>>>>            case xtrans$'0020,0003,0025'      && start of route
>>>>              * route no,journey no,start time
>>>>              do getroute with xtrans
>>>>            case xtrans$'0021,0004,0071'      && stage record
>>>>              * get ostage
>>>>              do getstage with xtrans
>>>>            case xtrans$'0008,0023'            && stop time
>>>>              do getstop with xtrans
>>>>            case xtrans$'0073,0039,003B,'      && annul ticket
>>>>               isannul=.t.
>>>>            case isticket
>>>>              do maketick
>>>>              if isannul
>>>>                 xfare=xfare*-1
>>>>              endif
>>>>             * add a record to the database - split up bytes
>>>>             do addtick
>>>>            otherwise
>>>>              * skip over len of record minus read up to the trans.
>>>>              =fseek(f_handle,xlen-3,1)
>>>>         endcase
>>>>
>>>>      if feof(f_handle)
>>>>         exit
>>>>      endif
>>>>
>>>>   enddo               && !eof()
>>>>      =fclose(f_handle)
>>>>      sele willread
>>>>      skip
>>>>enddo               && willread
>>>>   sele wayfare
>>>>   rcount=reccount()
>>>>   ecount=empty
>>>>   if o_opanal="Y"
>>>>      * see if file op_fare exists
>>>>      do prompt with "Please wait ..saving analysis files."
>>>>      opfile=o_analdir+"opanal.dbf"
>>>>      if file((opfile))
>>>>         sele 0
>>>>         use (opfile)
>>>>         append from wayfare
>>>>         use
>>>>      else
>>>>         sele wayfare
>>>>         copy to (opfile)
>>>>      endif
>>>>   endif
>>>>* select and close 1 - 10
>>>>   erase &cfile
>>>>   erase &dfile
>>>>   do stxweed      && prog - extract required records to mcltemp and
>>>>   *               build up stats1 file with adult fares
>>>>   * appweed calls upvalue.prg to insert values
>>>>   if isesca
>>>>      close data
>>>>      exit
>>>>   endif
>>>>   sele willread
>>>>   if !eof()
>>>>      skip
>>>>   endif
>>>>enddo               && will read loop
>>>>close data
>>>>* update infmread
>>>>sele 0
>>>>use thisread exclu
>>>>sele 0
>>>>use infmread
>>>>append from thisread
>>>>sele thisread
>>>>zap
>>>>close data
>>>>
>>>>@ 3,0 clear to 20,79
>>>>@ 12,20 say alltrim(str(rcount,6,0))+" records have been read"
>>>>@ 13,10 say alltrim(str(ecount,6,0));
>>>> +" files were empty. See control files for details"
>>>>do choose with "Press space to continue"
>>>>return
>>>>
Previous
Reply
Map
View

Click here to load this message in the networking platform