6 Replies Latest reply: May 27, 2010 5:43 AM by rlangus RSS

    Controlling script execution using document variables


      I have a series of script tabs each of which creates a qvd. This is all fine.

      I want to be able to quickly select which parts of the script to reload and which parts not. I have been /*...*/ the bits I don't want.

      Don't like that, so I have created a variable for each script section in the document, e.g. 201011AC can be 0 or 1.

      I have tried to use IF...END IF around my script dependent upon 201011AC, e.g. :

      IF 201011AC = 1 THEN


      END IF

      But this does not work and I get a "Script line error" for the IF statement line.

      What do I need to do to get this to work?



        • Controlling script execution using document variables


          I use a folder for my fact QVD's and create a list of the available files in a list box.


          // available QVD files
          // -------------------
          For each File in filelist('$(QVDPath)\PunDay*.qvd')
          namepos = index('$(File)','_') + 1;
          LOAD mid('$(File)',$(namepos),10) as AvailableDay
          , Weekday(date#(mid('$(File)',$(namepos),10),'yyyy-mm-dd')) as AvailableWeekday
          Autogenerate 1;
          Next File; <div>
          The user selects the files to load and presses a load button. I use a macro to set a variable
          </div><div><div>Sub LoopSelections()</div><div></div><div>Control = ActiveDocument.Variables("vControl").GetContent.String </div><div>'msgbox "Control: " & Control</div><div>Set oLB = ActiveDocument.getsheetobject(Control)</div><div>sDates = ""</div><div></div><div>'msgbox GetFieldSelections("AvailableMonth")</div><div></div><div>' loop the ListBox items and create a comma separated variable with the entries</div><div>sFiles = ""</div><div>For iLoop = 0 To oLB.GetRowCount - 1</div><div></div><div> ' item selected</div><div> Set oCell = oLB.GetCell(iLoop,0)</div><div> ' MsgBox "cell: " & oCell.Text & " state: " & oCell.State</div><div> </div><div> If oCell.State < 3 Then</div><div> ' for month selections use the first day of the month</div><div> if len(oCell.Text) = 7 then</div><div> sFiles = sFiles & oCell.Text & "-01,"</div><div> else</div><div> sFiles = sFiles & oCell.Text & ","</div><div> end if </div><div> End If</div><div>Next</div><div></div><div>ActiveDocument.CreateVariable("vLoadFiles")</div><div>ActiveDocument.GetVariable("vLoadFiles").SetContent sFiles,false </div><div>ActiveDocument.Reload</div><div></div><div>End Sub</div><div>
          In the load script I loop over the selected qvd files
          </div><div><div> Let vNofFiles = substringcount('$(vLoadFiles)', ',');</div><div> </div><div> For iLoop = 1 to vNofFiles</div><div> </div><div> // build the file name in the form PunDay_YYYY-MM-DD</div><div> Let vCurrName = vType & '_' & SubField('$(vLoadFiles)', ',', iLoop) & '.QVD'; </div><div>... </div><div>
          because of the same structure the different QVD's get concatenated.


          • SV:Controlling script execution using document variables
            Goran Korsgren

            We use this technique a lot.


            Let _DoThisPart = 0;




            If _DoThisPart = 1 Then

            // code that should only be used if _DoThisPart equals 1

            End If // If _DoThisPart ...


            I don't now if the problem is that your variable name starts with a digit?