Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Locate to record and replacement very slow
Message
From
03/06/2004 13:44:35
John Baird
Coatesville, Pennsylvania, United States
 
 
To
03/06/2004 11:54:35
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00909275
Message ID:
00909641
Views:
13
Why bother with the scan for the replace near the bottom. UPdate table will work just as well



>First, you should always indent code between IF and ENDIF, between DO WHILE and ENDDO, etc. That is, press a TAB, so that you can clearly see, for example in an IF, which is the code that executes conditionally.
>
>It doesn't matter for Visual FoxPro, but it makes the program much more readable for the programmer, and that is extremely important.
>
>To show the code in the Universal Thread, use < pre > at the beginning, and < /pre > at the end (without the spaces), so that the indentation (tabs or spaces) is respected.
>
>Now, let me suggest some improvements to your code.
>
>
>IF EMPTY(THISFORM.SHIFT.VALUE) .OR. EMPTY(THISFORM.LEVEL.VALUE) .OR. EMPTY(THISFORM.SECTION.VALUE) .OR. EMPTY(THISFORM.MONTH.VALUE).or.EMPTY(THISFORM.tsyear1.VALUE)
>
>  * First, as mentioned, the indentation: everything after IF and before ENDIF
>  * should be indented.
>  = MESSAGEBOX('Please Check... Some options are blank', 32, PRODUCT)
>  THISFORM.SHIFT.SETFOCUS
>  RETURN .T.
>ENDIF
>SHCODE = THISFORM.SHIFT.VALUE
>DIS = THISFORM.TSYEAR1.VALUE
>SHNAME = THISFORM.SHIFT.DISPLAYVALUE
>LECODE = THISFORM.LEVEL.VALUE
>LENAME = THISFORM.LEVEL.DISPLAYVALUE
>SE = THISFORM.SECTION.VALUE
>MONAME = THISFORM.MONTH.VALUE
>
>SELECT 19
>* Instead of select 19, give the name (alias) of the table,
>* to make your program more readable.
>* I do not know what table is #19!
>* And probably, you will forget this yourself, soon.
>
>* SET FILTER TO
>SET FILTER TO SHIFT=THISFORM.SHIFT.VALUE .AND. LEVEL=THISFORM.LEVEL.VALUE .AND. SECTION=THISFORM.SECTION.VALUE .AND. MONTH=THISFORM.MONTH.VALUE .AND. YEAR=DIS
>
>* It is not necessary to use SET FILTER TO before setting a filter.
>* Only use SET FILTER TO at the end, to reset your filter expression
>* to no filter.
>
>SET ORDER TO code
>* GOTO TOP
>COUNT TO C
>* GOTO TOP is not required in this case.
>* COUNT will go to the top anyway.
>
>IF C=0
>SET FILTER TO
>SET ORDER TO refno
>GOTO BOTTOM
>LREFNO = REFNO+1
>SET FILTER TO SHIFT=THISFORM.SHIFT.VALUE .AND. LEVEL=THISFORM.LEVEL.VALUE .AND. SECTION=THISFORM.SECTION.VALUE .AND. MONTH=THISFORM.MONTH.VALUE .AND. YEAR=DIS
>SET ORDER TO code
>GOTO TOP
>ENDIF
>IF C>0
>GOTO TOP
>LREFNO = REFNO
>ENDIF
>SELECT 6
>SET FILTER TO
>SET FILTER TO SCODE=SHCODE .AND. LCODE=LECODE .AND. SEC=SE .AND. ADMTD=1
>SET ORDER TO code
>
>* Here, I will show how to use SCAN:
>* GOTO TOP
>* DO WHILE  .NOT. EOF()
>SCAN
>* The SCAN replaces the two statements I commented.
>
>TCODE = CODE
>TROLL = ROLL
>IF SEX=1
>TNAME = ALLTRIM(DESCR)+" S/o "+ALLTRIM(FNAME)
>ENDIF
>IF SEX=2
>TNAME = ALLTRIM(DESCR)+" D/o "+ALLTRIM(FNAME)
>ENDIF
>SELECT 19
>SET FILTER TO
>SET FILTER TO SHIFT=THISFORM.SHIFT.VALUE .AND. LEVEL=THISFORM.LEVEL.VALUE .AND. SECTION=THISFORM.SECTION.VALUE .AND. MONTH=THISFORM.MONTH.VALUE .AND. YEAR=DIS
>SET ORDER TO code
>GOTO TOP
>SEEK TCODE
>IF FOUND()
>REPLACE NAME WITH TNAME
>REPLACE ROLL WITH TROLL
>ENDIF
>IF  .NOT. FOUND()
>APPEND BLANK
>REPLACE SHIFT WITH THISFORM.SHIFT.VALUE
>REPLACE LEVEL WITH THISFORM.LEVEL.VALUE
>REPLACE SECTION WITH THISFORM.SECTION.VALUE
>REPLACE MONTH WITH THISFORM.MONTH.VALUE
>REPLACE CODE WITH TCODE
>REPLACE NAME WITH TNAME
>
>*REPLACE ADDM WITH 0
>*REPLACE MONT WITH 0
>*REPLACE TUTI WITH 0
>*REPLACE EXAM WITH 0
>*REPLACE COMP WITH 0
>*REPLACE LABO WITH 0
>*REPLACE OTHE WITH 0
>* You can use a single comand here:
>BLANK FIELDS ADDM, MONT, TUTI, ...
>
>REPLACE ROLL WITH TROLL
>REPLACE REFNO WITH LREFNO
>REPLACE YEAR WITH DIS
>ENDIF
>SELECT 6
>SKIP
>ENDDO
>SHCODE = THISFORM.SHIFT.VALUE
>SHNAME = THISFORM.SHIFT.DISPLAYVALUE
>LECODE = THISFORM.LEVEL.VALUE
>LENAME = THISFORM.LEVEL.DISPLAYVALUE
>SE = THISFORM.SECTION.VALUE
>MONAME = THISFORM.MONTH.VALUE
>
>* Change the separate IF commands to a DO CASE. Better yet, put this
>* into a UDF, since you may need it in several places.
>
>*IF THISFORM.MONTH.VALUE="January"
>*MOCODE = 1
>*ENDIF
>*IF THISFORM.MONTH.VALUE="February"
>*MOCODE = 2
>*ENDIF
>
>do case
>case ThisForm.Month.Value = "January"
>  moCode = 1
>case ThisForm.Monty.Value = "February"
>  moCode = 2
>endcase
>
>* Also, name your objects so that you know whether you are using textboxes, etc.
>* If Month is a TextBox, name it TxtMonth, etc.
>
>IF THISFORM.MONTH.VALUE="March"
>MOCODE = 3
>ENDIF
>IF THISFORM.MONTH.VALUE="April"
>MOCODE = 4
>ENDIF
>IF THISFORM.MONTH.VALUE="May"
>MOCODE = 5
>ENDIF
>IF THISFORM.MONTH.VALUE="June"
>MOCODE = 6
>ENDIF
>IF THISFORM.MONTH.VALUE="July"
>MOCODE = 7
>ENDIF
>IF THISFORM.MONTH.VALUE="August"
>MOCODE = 8
>ENDIF
>IF THISFORM.MONTH.VALUE="September"
>MOCODE = 9
>ENDIF
>IF THISFORM.MONTH.VALUE="October"
>MOCODE = 10
>ENDIF
>IF THISFORM.MONTH.VALUE="November"
>MOCODE = 11
>ENDIF
>IF THISFORM.MONTH.VALUE="December"
>MOCODE = 12
>ENDIF
>SELECT 19
>SET FILTER TO
>SET FILTER TO SHIFT=SHCODE .AND. LEVEL=LECODE .AND. SECTION=SE .AND. MONTH=MONAME .AND. YEAR=DIS
>SET ORDER TO roll
>
>* GOTO TOP
>* DO WHILE  .NOT. EOF()
>* REPLACE TOTAL WITH ADDM+MONT+TUTI+EXAM+COMP+LABO+OTHE
>* SKIP
>* ENDDO
>
>* This could be done with a SCAN:
>SCAN
>  replace total with ...
>ENDSCAN
>
>* But this is not required for a REPLACE. Just use:
>REPLACE ALL TOTAL WITH ...
>
>* THISFORM.RELEASE
>DO FORM feesnew
>
>
>I suggest you do the suggested corrections, your code, and then perhaps I have a few more suggestions.
>
>Greetings,
>
>Hilmar.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform