Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

spaces & characters 1

Status
Not open for further replies.

reinaldo

Programmer
Mar 29, 2001
31
0
0
US
I have a field on a report "CompanyName", the name of the company may be A & B, Inc. Is there a way that I can get this to show on my report as ABIN displaying the first 4 characters, no commas dashes or periods.

PDOX9 WIN

Thanks All!


 
I don't know how to do that in a calculated field on a report.

I suggest that you add a field to your table to hold the new value and then run a script to generate the new value.

Consider the following:

Code:
method run(var eventInfo Event)

var
   tc TCursor
   oldString, newString String
   ar Array[] String
   r Report
   n ReportPrintInfo
   p PrinterOptionInfo
endVar

if not tc.open("test.db") then errorShow() return endIf
tc.edit()
scan tc :
   message(strVal(tc.recNo() + " of " + strVal(tc.nRecords())))
   oldString = tc.CompanyName
   oldString.breakApart(ar)          ; by default, breaks string on spaces
   newString.blank()
   for i from 1 to ar.size()            ; combine the parts to make a new string w/o spaces
      newString = newString + ar[i]
   endFor
   oldString = newString              ; oldString does not contain any spaces
   oldString.breakApart(ar, &quot;!@#$%^&()_+-={}|[]:;',./<>?&quot;) ;break on special chars
   newString.blank()
   for i from 1 to ar.size()  ; combine the parts to make a new string w/o special chars
      newString = newString + ar[i]
   endFor
   tc.newCompanyName.blank()
   tc.newCompanyName = upper(subStr(newString,1,4)) ;truncate and convert value
   tc.newCompanyName.view(&quot;newCompanyName&quot;)
endScan
tc.endEdit()
tc.close()

p.orientation = prnLandscape
p.paperSize = prnLetter
printerSetOptions(p)

n.name = &quot;myreport.rsl&quot;
n.masterTable = &quot;test.db&quot;
n.orient = prnLandscape

if not r.print(n) then errorShow() endIf

endMethod
[\code]
 
A simpler approach might be to rebuild the string the old fashioned way and skip the bad chars in the first pass.

Look at each char and if it is white space or not wanted, ignore it. If not, add it to the new string.

Not sure of PDX9 syntax, but in the above example, instead of always adding ar to newString, test if ar is in the list of &quot;ignored&quot; characters (using a LIKE or INSTR type operation) . If it IS NOT, do the newstring concatenation. You can also test when newString has four characters and then jump out of the loop.

Nathan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top