付録1-2 Visual Basic

VisualBasicを使用している場合のプログラム例は、次のとおりです。

'*****  関数宣言部  *****
'*****  [module svfrclient.dll]  *****
'*****  [class vfreport.client]  *****
Function VrConnect(host As String) As Object
End Function
Function VrConnectEx(host As String, port As Long) As Object
End Function

'*****  [class vfreport.connection]  *****
Function VrSetSpoolFileName2(fileName As String) As Long
End Function
Function VrInit() As Long
End Function
Function VrQuit() As Long
End Function
Function VrSetForm(formName As String, mode As Long) As Long
End Function
Function VrEndPage() As Long
End Function
Function VrsOut(fieldName As String, data As String) As Long
End Function
Function VriOut(fieldName As String, data As Long) As Long
End Function
Function VrlOut(fieldName As String, data As Long) As Long
End Function
Function VrrOut(fieldName As String, data As Double) As Long
End Function
Function VrsOutn(fieldName As String, index As Long, data As String) As Long
End Function
Function VriOutn(fieldName As String, index As Long, data As Long) As Long
End Function
Function VrlOutn(fieldName As String, index As Long, data As Long) As Long
End Function
Function VrrOutn(fieldName As String, index As Long, data As Double) As Long
End Function
Function VrTest() As Long
End Function
Function VrCopy(copies As Long) As Long
End Function
Function VrPage(flags As String) As Long
End Function
Function VrSetPrinter(printerName As String, portName As String) As Long
End Function
Function VrAdjustd(formName As String, x As Long, y As Long) As Long
End Function
Function VrAdjustm(formName As String, x As Long, y As Long) As Long
End Function
Function VrEnablePreview(enable As Long, inputable As Long) As Long
End Function
Function VrPreviewStartPage() As Long
End Function
Function VrPreviewEndPage() As Long
End Function
Function VrSetSpoolMode(mode As Long) As Long
End Function
Function VrSetPageCount(pageNo As Long, incValue As Long) As Long
End Function
Function VrAttribute(fieldName As String, data As String) As Long
End Function
Function VrAttributen(fieldName As String, index As Long, data As String) As Long
End Function
Function VrGetAttribute(fieldName As String, attrName As String, buffer As String) As Long
End Function
Function VrEndRecord() As Long
End Function
Function VrSetQuery(connectStr As String, queryName As String, mode As Long) As Long
End Function
Function VrCondition(condition As String, mode As Long) As Long
End Function
Function VrReport() As Long
End Function
Function VrPrint() As Long
End Function
Function VrSetDocName2(docName As String) As Long
End Function
Function VrSetUseReportDirector(fUse As Long) As Long
End Function
Function VrSetServerName(serverName As String) As Long
End Function
Function VrSetOutputVPrinter(printerName As String) As Long
End Function
Function VrSetOutputVPrinter2(groupName As String) As Long
End Function
Function VrSetUserName(userName As String) As Long
End Function
Function VrSetComputerName(computerName As String) As Long
End Function
Function VrSetDuplex(nMode As Long, nMargin As Long) As Long
End Function
Function VrSetTray(nTray As Long) As Long
End Function


Private Sub Main()
             Dim svf As Object
             ReDim aMeisai(4, 4)
             Dim GYONO, nPDATA As Long
             Dim ret, hvr As Long

'**************** オブジェクト生成 ****************************
  Set svf = CreateObject("vfreport.client").VrConnect("localhost")
'**************** 伝票データ       ****************************
' フォーム
             PFORM = "SAMPLE_vb.XML"
' PDFファイル名
             PFILE = "SAMPLE.PDF"
' ヘッダー
             TCD = "123456789012"
             TNAME = "XX電気販売株式会社"
             DNO = "000123"
             YNO = "111-1111"
             ADRS1 = "東京都品川区小川町1-1-1"
             ADRS2 = "小川ビル1F"
             JNAME = "ZZコンピューター株式会社"
             TEL = "03-1234-5678"
             ZEI = "5.0"
' 明細
             aMeisai(1, 1) = "26型カラーテレビ"
             aMeisai(1, 2) = "3"
             aMeisai(1, 3) = "台"
             aMeisai(1, 4) = "125000"

'********************************************************
'*     印刷実行
'********************************************************
    If (svf.VrInit() >= 0) Then
'****** PDFファイル作成  ********************************
        Call svf.VrSetPrinter("PDF", "PDF")
        Call svf.VrSetSpoolFileName2(PFILE)
'****** フォーム選択     ********************************
        If (svf.VrSetForm(PFORM, 1) = 0) Then
'****** ヘッダー印刷      ******************
             ret = svf.VrsOut("伝票番号", DNO)
             ret = svf.VrsOut("得意先名", TNAME)
             ret = svf.VrsOut("得意先コード", TCD)
             ret = svf.VrsOut("自社名", JNAME)
             ret = svf.VrsOut("郵便番号", YNO)
             ret = svf.VrsOut("住所1", ADRS1)
             ret = svf.VrsOut("住所2", ADRS2)
             ret = svf.VrsOut("電話番号", TEL)
'******** 明細行印刷  **********************
             GYONO = 0
             Do While GYONO < 4
                 GYONO = GYONO + 1

                 nPDATA = Val(aMeisai(GYONO, 2))
                 If nPDATA = 0 Then
                        Exit Do
                 End If
                 ret = svf.VrrOutn("数量", GYONO, nPDATA)

                 PDATA = aMeisai(GYONO, 1)
                 ret = svf.VrsOutn("品名", GYONO, PDATA)

                 PDATA = aMeisai(GYONO, 3)
                 ret = svf.VrsOutn("単位", GYONO, PDATA)

                 nPDATA = Val(aMeisai(GYONO, 4))
                 ret = svf.VrrOutn("単価", GYONO, nPDATA)

             Loop
'******** フッター印刷  ********
             ret = svf.VrsOut("税率", ZEI)
             ret = svf.VrsOut("備考1", "この伝票は VFR で印刷しました。")
'******** 頁の終了 *************
             ret = svf.VrEndPage()
'******** ライブラリ解放********
        End If
        Call svf.VrQuit
    End If
    Set svf = Nothing
End Sub
参考

Super Visual Formade実行部(C版)との違い

  • 関数宣言部分に「svfrclient.dll」の宣言を加えます。
  • 関数宣言部分はAPI関数使用時においてハンドルがなくなります。
  • CreateObject句を使用してCOMオブジェクトインスタンスを作成し、VrConnect関数でHOSTを指定します。
  • API関数をcallする際に、COMオブジェクトインスタンスをSETした変数を使用します。
  • 最後にCOMオブジェクトインスタンスをNothingで開放します。
  • .NET版SVF実行部の場合は「SvfrServer.exe」を、Java版SVF実行部を使用している場合は「svf.jar」をあらかじめ起動しておく必要があります。