rtslink.com
Home / RTSlink DLL / Visual Basic

Visual Basic to Tally


General Points
  • The DLL function names are case sensitive.
  • The DLL is loaded into memory when you invoke any of the DLL functions for the first time.
Example 1:

To write data to Tally Server using Open() & Send() functions

STEP-BY-STEP Instructions:

Step 1:
In your VB application, add a module with the following code:

'TASK:   Create a Group master entry i.e. My  Debtors
'----------------------------------------------------------------------------
Option Explicit
Declare Function RTSOpen Lib "RTSLINK.DLL" Alias "Open" () As Long
Declare Function Send Lib "RTSLINK.DLL" (ByVal strRequestXML As String) As Long
Declare Function GetLastErrorMessage Lib "RTSLINK.DLL" () As String

Public Sub vbSend()
    Dim nResult As Integer
    Dim strErrorMsg As String * 255
    Dim strRequestXML
    Dim strResponseText
   
    strRequestXML = _
    "<ENVELOPE>" & _
    "<HEADER>" & _
    "<TALLYREQUEST>Import Data</TALLYREQUEST>" & _
    "</HEADER>" & _
    "<BODY>" & _
    "<IMPORTDATA>" & _
    "<REQUESTDESC>" & _
    "<REPORTNAME>All Masters</REPORTNAME>" & _
    "</REQUESTDESC>" & _
    "<REQUESTDATA>" & _
    "<TALLYMESSAGE xmlns:UDF='TallyUDF'>" & _
    "<GROUP NAME='My Debtors' ACTION='Create'>" & _
    "<NAME>My Debtors</NAME>" & _
    "<PARENT>Sundry Debtors</PARENT>" & _
    "<ISSUBLEDGER>No</ISSUBLEDGER>" & _
    "<ISBILLWISEON>No</ISBILLWISEON>" & _
    "<ISCOSTCENTRESON>No</ISCOSTCENTRESON>" & _
    "</GROUP>" & _
    "</TALLYMESSAGE>" & _
    "</REQUESTDATA>" & _
    "</IMPORTDATA>" & _
    "</BODY>" & _
    "</ENVELOPE>"

    'Connect to Tally server using RTSOpen(). On success, Zero is returned.
    nResult = RTSOpen()
    If nResult = 0 Then
        'Send a request message to server. Herein the request is to create
        'Group Master entry. Returns Zero on success.

        nResult = Send(strRequestXML)
        If nResult = 0 Then
            MsgBox "Group Master created successfully"
        Else
            strErrorMsg = GetLastErrorMessage()
            'You may provide an Error-handling routinue here
            MsgBox "Error: " & strErrorMsg
        End If
    Else
        'If Tally software is NOT running
        strErrorMsg = GetLastErrorMessage()
        'You may provide an Error-handling routinue here
        MsgBox "Error: " & strErrorMsg
    End If
End Sub


Step 2:
Add a Command button to the Main form (form1) and write the following code in the Click event of the Command button.

Private Sub Command1_click()
      Call vbSend()
End Sub

Step 3:
Create the Executable file using option File – Make

Notes:
  • If you declare the DLL functions in a module, they are declared as PUBLIC, whereas if you declare them in a Form, the DLL functions should be declared as PRIVATE.
  • To pass strings to C routines, the ByVal keyword is used. This tells VB to pass it as a null terminated string.
  • "Integer" data-type of C is "Long" in VB.

Trouble shooting Tips:
  • In case if you get an error message "Bad calling convention" while compiling & running the above code, try out creating the  EXE (use option File-Make) and then run the executable file.


Example 2:
To write data  to Tally Server using function SendXMLFileToServer()

To use the following example code, you must download the Group.xml file and copy it into your application directory. Click here to download the  Group.xml file.

STEP-BY-STEP Instructions:

Step:1

In your VB application, add a module with the following code:

'TASK:   Create a Group master entry using SendXMLFileToServer() 
'------------------------------------------------------------------------------------------------
Option Explicit
Declare Function RTSOpen Lib "RTSLINK.DLL" Alias "Open" () As Long
Declare Function SendXMLFileToServer  Lib "RTSLINK.DLL" (ByVal strXMLfile As String) As Long
Declare Function GetLastErrorMessage  Lib "RTSLINK.DLL" () As String

Public Sub vbSendXMLFileToServer()
    Dim strXMLfile As String
    Dim nResult As Integer
    Dim strErrorMsg as String * 255

    'Specify the XML file-name with full path if not in application directory 
    strXMLfile = "GROUP.XML"

    'Connect to the Tally software. Returns zero if  successful
    nResult=RTSOpen()
    if nResult=0 then
       'If Tally software is running
       nResult=SendXMLFileToServer (strXMLfile)
       IF nResult <> 0 then
         strErrorMsg=GetLastErrorMessage()
         'You may provide an Error-handling routinue here
         MsgBox "Error: " & strErrorMsg
       End If
   Else
       'If Tally software is NOT running
       strErrorMsg=GetLastErrorMessage()
       'You may provide an Error-handling routinue here
       MsgBox "Error: " & strErrorMsg
    End if
End Sub


Step 2:
Add a Command button to the Main form (form1) and write the following code in the Click event of the Command button.

Private Sub Command1_click()
      Call vbSendXMLFileToServer ()
End Sub


Step 3:
Create the Executable file using option File – Make


Example 3:

To Export data  from [Tally] Server (i.e. Read Data from Tally)

To use the following example code, you must download the Listcmp.xml file and copy it into the application directory. Click here to download the  Listcmp.xml file.

STEP-BY-STEP Instructions:

Step:1

In your VB application, add a module with the following code:

'TASK:   Fetch  List of companies loaded / open in Tally
'------------------------------------------------------------------------------
Option Explicit
Declare Function RTSOpen Lib "RTSLINK.DLL" Alias "Open" () As Long
Declare Function SendXMLFileToServer  Lib "RTSLINK.DLL" (ByVal strXMLfile As String) As Long
Declare Function GetLastErrorMessage  Lib "RTSLINK.DLL" () As String
Declare Function ResponseText Lib "RTSLINK.DLL" () As String

Public Sub vbSendXMLFileToServer()
    Dim strXMLfile As String,nResult As Integer,strErrorMsg as String * 255
    Dim strResponseText
    'Specify the XML file-name with full path if not in application directory 
    strXMLfile = "Listcmp.XML"

    'Connect to the Tally software. Returns zero if  successful
    nResult=RTSOpen()
    if nResult=0 then
       'If Tally software is running
       nResult=SendXMLFileToServer (strXMLfile)
       if nResult=0 then
          'Get the Server Response
          strResponseText=ResponseText()
          MsgBox "Server Response: " & strResponseText
      else
          strErrorMsg=GetLastErrorMessage()
          'You may provide an Error-handling routinue here
          MsgBox "Error: " & strErrorMsg
       End If
   Else
      'If Tally software is NOT running
      strErrorMsg=GetLastErrorMessage()
      'You may provide an Error-handling routinue here
      MsgBox "Error: " & strErrorMsg
   End if
End Sub


Step 2:
Add a Command button to the Main form (form1) and write the following code in the Click event of the Command button.

Private Sub Command1_click()
      Call vbSendXMLFileToServer ()
End Sub

Step 3:
Create the Executable file using option File – Make


Next:  Using the DLL in Visual Foxpro
Tally is a registered trademark of Tally Solutions FZ LLC.

Valid HTML 4.01 Transitional