Montag, 9. April 2018

BBjVector from ResultSet column

BBjVector from ResultSet column using a version above BBj 17.13.

use com.basiscomponents.db.ResultSet
use com.basiscomponents.db.util.ResultSetValuesListProvider
declare BBjVector v!
declare ResultSet rs!
REM ... filling rs! using the column name "MyColumnOfRs" ....
v! = ResultSetValuesListProvider.getFieldValuesAsList(rs!,"MyColumnOfRs")


Donnerstag, 31. August 2017

date calendar functions / adding number of month to a date

use java.util.Calendar
declare Calendar endCal!

xyear=2017
xmonth=8
xday=31

endCal! = Calendar.getInstance()
endCal!.set(xyear,xmonth-1,xday)
?str(endCal!.getTime())

endCal!.add(Calendar.MONTH,2)
?str(endCal!.getTime())

?endCal!.get(Calendar.YEAR)
?endCal!.get(Calendar.MONTH) + 1
?endCal!.get(Calendar.DATE)

---------------------------------------------------

declare Calendar endCal!
DATE_STA=-1
DATE_END=-1
num_of_month_to_add = 6
tmp$="2017-08-30T20:02:46.000+02:00"
if len(tmp$)>9 then
if tmp$(5,1)="-" and tmp$(8,1)="-" then
DATE_STA=jul(tmp$(1,10),"%Yl-%Mz-%Dz",err=*endif)
endCal! = Calendar.getInstance()
endCal!.set( num(date(DATE_STA:"%Yl")) , num(date(DATE_STA:"%Mz")) -1 , num(date(DATE_STA:"%Dz")))
endCal!.add(Calendar.MONTH, num_of_month_to_add )
endYear=int(endCal!.get(Calendar.YEAR))
endMonth=int(endCal!.get(Calendar.MONTH) + 1)
endDay=int(endCal!.get(Calendar.DATE))
DATE_END = jul(endYear, endMonth, endDay)
fi
fi
?DATE_STA
?DATE_END
?DATE_END-FIN_DATE_STA

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Mittwoch, 12. Oktober 2016

getting Files and Directories of a Folder in BBj

showcase demonstrates how to get the used jasper version of BBj by using a complete scan of the lib directory files:
        jasperVersion$="?.?.?"
        declare java.io.File f!
        declare BBjString path!
        path! = cast(BBjString,System.getProperty("basis.BBjHome")+"\lib\").replaceAll("/\\","\").replace("\\","\")
        f! = new java.io.File( path! )
        if (f!<>null()) then
          javaList! = java.util.Arrays.asList( f!.listFiles() )
          for i=0 to javaList!.size()-1
            f! = cast(java.io.File,javaList!.get(i))
            if (!f!.isDirectory()) then
                if (f!.getName().contains("jasperreports-javaflow-")) then
                  jasperVersion$ = f!.getName().replaceAll("jasperreports-javaflow-|.jar","")
                endif
            endif
          next i
        endif
Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Samstag, 24. September 2016

iterating through the keySet (of a HashMap)


declare java.util.HashMap hm!
hm! = new java.util.HashMap()
hm!.put("myKey1",100)
hm!.put("myKey2",200)


declare BBjVector v!
v!=new BBjVector(java.util.Arrays.asList(hm!.keySet().toArray()))
v!=new BBjVector(java.util.Arrays.asList(hm!.values().toArray()))
java.util.Collections.sort(v!); REM sorting vector 
x = v!.contains(IdOrValue$)
i = v!.indexOf(IdOrValue$)

declare java.util.Set ks!
ks! = hm!.keySet()
i! = ks!.iterator()
while i!.hasNext()
    key!=i!.next()
    value=hm!.get(key!)
    ?">>"+key!+"="+str(value)+"<<"
wend


Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Dienstag, 30. August 2016

info function sample and more system information

REM /**
REM  * infoFunction.bbj
REM  * @author VANDEN
REM  */
tc! = bbjapi().getThinClient()
tc!=BBjAPI().getThinClient()
        txt$=txt$+tc!.toString()
        txt$=txt$+""+
:       "+++BBx Betriebssystem (0,0):           "+info(0,0)+
:       "+++BBx Betriebssystem Version (0,1):   "+info(0,1)+
:       "+++Server Basis Port ID (0,2):         "+info(0,2)+
:       "+++Client Basis Port ID ( tc!.getClientPortID() ): "+tc!.getClientPortID()+
:       "+++CPU ID (1,0):                       "+info(1,0)+
:       "+++server JVM unque ID (1,5) :         "+hta(info(1,5))+
:       "+++client JVM unque ID (1,6) :         "+hta(info(1,6))+
:       "+++Current User Slot Number (2,4):     "+str(dec(info(2,4)))+
:       "+++license Version (2,7):              "+str(dec(info(2,7)))+
:       "+++unique Task ID 4byte (3,0):         "+str(dec(info(3,0)))+
:       "+++unique Task ID 8byte (3,1):         "+str(dec(info(3,1)))+
:       "+++Username (3,2):                     "+info(3,2)+
:       "+++Login Beschreibung (3,3):           "+info(3,3)+
:       "+++Hostname (3,4):                     "+info(3,4)+""+
:       "+++Aktivierungsschlüssel (3,5):        "+info(3,5)+
:       "+++GUI System (6,0):                   "+info(6,0)
        x=msgbox( cast(BBjString,txt$).replace("+++",$0d0a$) )
     
for i=0 to 99999
    if (i>0 and mod(i,20)=0) input "press enter to continue",a$
    ?"INFO(7,"+str(i)+") = "+info(7,i,err=*break)
next i
   
end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Regular Expression in BBj / Java

replace line breaks with html line breaks :

declare BBjString test!
test!="HELLO\r\nWORLD\n\rAGAIN"
foo$=test!.replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?foo$

test$="HELLO\r\nWORLD\n\rAGAIN"
test$=cast(BBjString,test$).replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?test$

replace multiple chars by char :

src! = "ABC___(hellop)_myQuotesAreHere"+$2222$+"12345_ /&%"
ListOfDislikedChars$ ="[\/^\*\$\(\)\&\=\?\'\*\+\-\.\:\,\;\""\%]"; REM [^/....]*/$
firstMatchAtPos=mask(src!,ListOfDislikedChars$) ; ?"pattern matched first at position "+str(firstMatchAtPos)
?src!
des! = src!.replaceAll(ListOfDislikedChars$,java.util.regex.Matcher.quoteReplacement("X"))
?des!

remove path from filename : x! = programName!.replaceAll(".*(\\|/)","")
remove extension from filename : x! = programName!.replaceAll("\.\w+$","")
keep path only from filename : x! = programName!.replaceAll("(\\|/).*","")

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Sonntag, 28. August 2016

append one PDF to another PDF

Based on the library http://itextpdf.com/.
Usecase: Add for instance common terms of condition to an invoice.

REM /**
REM  * pdf_append.bbj
REM  * @author VANDEN
REM  *
REM  */

use java.util.ArrayList
use java.io.FileOutputStream
use com.itextpdf.text.Document
use com.itextpdf.text.DocumentException
use com.itextpdf.text.pdf.PdfCopy
use com.itextpdf.text.pdf.PdfReader

declare Document document!
declare PdfCopy copy!
declare ArrayList files!
declare PdfReader reader!

outputFile$ = "c:/0/pdf3.pdf"
inputFile1$ = "c:/0/pdf1.pdf"
inputFile2$ = "c:/0/pdf2.pdf"

document! = new Document()
copy! = new PdfCopy(document!, new FileOutputStream(outputFile$))
document!.open()
files! = new ArrayList()
files!.add(inputFile1$)
files!.add(inputFile2$)
For i = 0 to files!.size() - 1
    reader! = new PdfReader(Str(files!.get(i)))
    n = reader!.getNumberOfPages()
    For page = 1 to n
        copy!.addPage(copy!.getImportedPage(reader!, page))
    Next page
    copy!.freeReader(reader!)
    reader!.close()
Next i
document!.close()

end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!