Paradox Community

Items in pnews.paradox-programming

Subject:Solution: Tidying up query in code
Date:24 Jul 2019 04:09:56 -0400
From:"Jostein Bakke" <bakkeb@online.no>
Newsgroups:pnews.paradox-programming

When I read Peters response to Kevins question («Sort: command») a few days
ago, I came to think of a thing I wrote that might be of interest to others.

When creating a query interactively, it is visually easy to understand in
the query-builder. Problem: When pasting this into your code, Paradox breaks
it up to several unnecessary short lines (because of the small screen-sizes
in the days Paradox was created).  I used to do a lot of cutting and pasting
in the code, to make it clearer.

Here's my solution: Create a form with two fields (called Felt1 and Felt2
in the code below).  In the first field you paste in the query-text, the
way Paradox has imported it into the code.  Push the button with the code
below, and a version where the lines is not broken ut will appear in the
second field.

Jostein Bakke



Here's the code:


method pushButton(var eventInfo Event)
var
vLtTeller  longInt
vTxtLeggTillA, vTxtLeggTillB, vTxtTabTxt, vTxt  string
vTxtArr Array[]  string
vSmtKarPos, vSmtArrStrl  smallint
endVar

vTxt = Felt1.Value
vTxt.breakApart(vTxtArr, "\r")
vSmtArrStrl = vTxtArr.size()

	for vLtTeller from 1 to vSmtArrStrl
		if vLtTeller >= vSmtArrStrl-4
      then quitLoop
      endIf

		if advMatch(vTxtArr[vLtTeller], ".DB \\| ")
      then
		vSmtKarPos = vTxtArr[vLtTeller].search(".DB | ")
      vTxtTabTxt = vTxtArr[vLtTeller].subStr(1, vSmtKarPos+3)
			if vTxtArr[vLtTeller+3].subStr(1, vSmtKarPos+3) = vTxtTabTxt
         then
			vTxtLeggTillA = vTxtArr[vLtTeller+3].subStr(vSmtKarPos+5, 100)
			vTxtArr[vLtTeller] = vTxtArr[vLtTeller] + vTxtLeggTillA
			vTxtLeggTillB = vTxtArr[vLtTeller+4].subStr(vSmtKarPos+5, 100)
			vTxtArr[vLtTeller+1] = vTxtArr[vLtTeller+1] + vTxtLeggTillB
			vTxtArr.remove(vLtTeller+3)
			vTxtArr.remove(vLtTeller+3)
			vTxtArr.remove(vLtTeller+3)
         	vSmtArrStrl = vTxtArr.size()
				vLtTeller = vLtTeller-1
         endIf
      endIf
   endFor

vLtTeller = 0
vTxt = blank()
	for vLtTeller from 1 to vSmtArrStrl
	vTxt = vTxt + vTxtArr[vLtTeller] + "\r"
	endFor
vTxt = rTrim(vTxt)
Felt2.Value = vTxt

endMethod


Copyright © 2004 thedbcommunity.com