Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To iif or not to iif = .t.
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00513276
Message ID:
00514399
Views:
15
>> Thanks a lot for the suggestions, George. I already changed for next to do while and get rid of the top loop (unnecessary, as you fairy noted - this that I've done without reading this message). Now I'm going to proceed with your suggestions.
>>
>>Thanks.
>
>Nadya,
>
>You're welcome. Let me emphaize one thing. These are general guidelines. For example, my point about the inner of the two loops was based on the concept that, under the circumstances, this routine would only apply to tables connected with a DBC. My thought was, "Well, what about free tables? Why write essentially the same code twice to handle the,?" You know the answers to these questions far better than I.
>
>The rules are there for a purpose. Sometimes you have to break them in order to accomplish what needs to be done. However, before doing so, I try to make absolutely certain that the conditions of the problem require it, and there isn't a better way to accomplish the same thing.

George,

I changed the code (see bellow), but something bothers me. It seems that do while conditions are checked only when I rich the last enddo command. In other words,
do while !Stop
  if Somecondition
      Stop=.t. && instead of immediate termination, this would terminate only after enddo
  endif
edndo
May be it's only impression, but why I had to use do while lnKinstead of do while m.lnK<=m.lnCount? If I put <=, I get an error.

Anyway, this is a new code. It could be simplified further, but I stoped at this point. BTW, the table must be a part of database, this is for our DataDictionary application, which verifies structure of tables in our databases.
* support user Escapes for interrupting the main loop
lcOldOnEsc = on('escape')                    &amp;&amp; save previous Escape handler
lcOldSetEscape = set('escape')               &amp;&amp; previous Escape enablement state
set escape on                                   &amp;&amp; enable escape handling
on escape oValid.StopProcess("Are you sure you want to stop Modify Process?")     &amp;&amp; Allows for stopping of the process.
lnStartTime=datetime()
do while oValid.lContinue and m.lnI&lt;m.tnCount and !m.llStop 
     lnI=m.lnI+1 &amp;&amp; Increment count
     lcDBC=alltrim(taDBC[m.lnI])
     if not file(forceext(m.lcDBC,'DBC'))
         set message to "Database "+m.lcDBC+" is not found!"
          wait window "Database "+m.lcDBC+" is not found!" nowait &amp;&amp; ,48,"File does not exist"
          lcWholeLogStr=iif(empty(m.lcWholeLogStr),"",m.lcWholeLogStr+CR+replicate("*",65) + CR) + ;
               "Database "+m.lcDBC+" is not found..."
     else
          llDBCExist=.t. &amp;&amp; At least one DBC exists          
          if GetDBC(m.lcDBC) &amp;&amp; Open database for possible changes 
               lcDBCPath=addbs(justpath(fullpath(forceext(m.lcDBC,"DBC"))))
               lcWholeLogStr=iif(empty(m.lcWholeLogStr),;
                             upper("Starting checking "+ m.tcAction+" at ")+ ;
                          ttoc(m.lnStartTime), ;
                             m.lcWholeLogStr+CR+replicate("*",65)+CR)+ CR                          
               lcWholeLogStr= m.lcWholeLogStr+ttoc(datetime())+" Database: "+m.lcDBC
               release laTables
               lnTables=adbobjects(laTables, "TABLE")  &amp;&amp; Create list of all tables in Database
               =asort(laTables)
               lnK=0
               do while oValid.lContinue and m.lnK&lt;m.lnTables and !m.llStop &amp;&amp; Loop for all tables in DBC
                   lnK=m.lnK+1
                    lcTableName=upper(alltrim(laTables[m.lnK]))               
                    if !CheckFreeDiskSpace(m.lcTableName, m.lcDBCPath, m.llFirstTime)
                       llStop=.t. &amp;&amp; Terminate all loops since not enough free disk space
                    else 
                        llFirstTime=.f.   
                         llTableOpened=.f.
                         if m.lcTableName&lt;&gt;"NEXTID"
                              if OpenTble(m.lcTableName,'WorkFile','exclusive') &amp;&amp; Open Table excl with alias WorkFile                                   
                                   llTableOpened=.t.
                                   if m.tcAction='Structure'
                                   lcWholeLogStr= m.lcWholeLogStr+CR+"Table: "+ m.lcTableName+ ;
                                        " starting checking structure at "+ttoc(datetime())+CR
                                        if !Modify_Structure(m.lcTableName, alltrim(taDBC[m.lnI]), @lcWholeLogStr)
                                           llStop=.t. &amp;&amp; Something was wrong here
                                        endif   
                                   endif   &amp;&amp; Structure changes only
                                   lcWholeLogStr= m.lcWholeLogStr+CR+"Table: "+m.lcTableName+ ;
                                        " starting checking indexes at "+ttoc(datetime())+CR
                                   =Modify_Indexes(m.lcTableName, alltrim(taDBC[m.lnI]), @lcWholeLogStr)
                                   use     in select('WorkFile')
                                   flush
                              else &amp;&amp; Table was not opened
                                   lcWholeLogStr= m.lcWholeLogStr+  ;
                                        ttoc(datetime())+" Table "+ m.lcTableName+ ;
                                        " was opened by another user and therefore was not checked..."+ ;
                                        +CR+replicate("_",65)+CR
                              endif
                         endif
                    endif
               enddo      &amp;&amp; End loop for all tables within Database
               lcWholeLogStr= m.lcWholeLogStr+  ;
                         ttoc(datetime())+" Finished checking tables in "+m.lcDBC+CR
               close database
               erase (m.lcDBCPath+'*.bak')
               erase (m.lcDBCPath+'*.tbk')
          endif
     endif
enddo
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform