Remote Features of Visual Basic


"Remote" refers to the process of passing parameters between two different processes, usually across a network. For example, suppose there is a three-tier system. On the client, the application makes the data call, passing several parameters as criteria. On the middle-tier machine, an ActiveX EXE accepts the call and fetches the data using the specified criteria.

For example, the code on a middle-tier application might look like the following:

Option Explicit

' The code is in a code module.
Public Type udtMyType ' public  UDT definition
   birthDate As Date
   lastName As String
   firstName As String
   address As String
End Type

Public Function passUDT(myrec As udtMyType) As udtMyType   
   ' change the data.
   passUDT = myrec ' return  UDT .
End Function

The code to call this function on the client might be:

Option Explicit
Private myrec As udtMyType

Private Sub Command1_Click()
   Dim x As udtMyType
   x = passUDT(myrec)
   ' Use  UDT data.
End Sub

Pass UDT as parameter of public Sub

While passing parameters has always been possible in previous versions of Visual Basic, passing user-defined types (UDTs) as parameters of a public Sub is not. This is now also possible, as shown in the example above.

For performance reasons

The cost of passing parameters outside the process is much higher than passing them within the process. When passing parameters, the data must be sanitized before being passed to an external process. The code to do this can have significant overhead, but Visual Basic hides this overhead. However, the advantage of remote data is to create code that is easy to understand. Depending on the size of the UDT, it may be easier to maintain than an ADO recordset object.

Remote ADO Recordset

ADO Recordset objects can also be remote. With this capability, the use of ADO recordsets on intranet and Internet client-server applications will be particularly appropriate. For example, you can create HTML or DHTML pages that access data on a web server application over the Internet. When creating HTML pages, you can include the Microsoft ActiveX Data Access Recordset 2.0 library, whose only feature is the Recordset object. Because the library does not include Command, Connection, and Parameter objects, possible relics in the application are minimized while preserving ADO recordset functionality. The following code is an example of a remote ADO Recordset:

' The code is in a code module.
' Set  Microsoft ActiveX Data Objects 2.0 a reference to the library
Private MyADORecordset As ADODB.Recordset

Public Function GetCustomer(LastName As String) As ADODB.Recordset   
   ' Inquire DB
   MyADORecordset.Open "SELECT * FROM Customers WHERE " & _
   "LastName = '" & LastName & "'", cn, adOpenForwardOnly, adLockReadOnly
   Set MyADORecordset.ActiveConnection = Nothing
   Set GetCustomer = MyADORecordset ' Return the recordset.
End Function

And the code to call the function on the client might be:

Option Explicit
Private SomeServer As Object

Private Sub Command1_Click()
   ' Customers can use  lighter ADOR the library. Set a reference to the
   ' Microsoft ActiveX Data Objects 2.0 library
    . Dim MyData As ADOR.Recordset
   Set SomeServer = CreateObject("foo.bar", myserver)
   Set MyData = SomeServer.GetCustomer("Smith")
   ' Use data.
End Sub
For the first time in the computer room charging system to share data connection with the database
 
 
Dim mrc As ADODB.Recordset
        Dim MsgText As String
        Dim txtSQL As String
        'Check if the content is empty
        If (Text1.Text = "") Then
              MsgBox "Please enter fixed user 1 hour fee!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
        If (Text2.Text = "") Then
              MsgBox "Please enter 1 hour fee for temporary users!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
        If (Text3.Text = "") Then
              MsgBox "Please enter increment time!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
        If (Text5.Text = "") Then
              MsgBox "Please enter at least computer time!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
        If (Text6.Text = "") Then
              MsgBox "Please enter preparation time!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
        If (Text7.Text = "") Then
              MsgBox "Please enter the minimum amount!", vbOKCancel + vbExclamation, "Warning"
              Text1.SetFocus
        End If
       'mrc.Delete
        txtSQL = "select*from basicdata_info"
        'Execute the query statement
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        '---------------------------------------
        'Add query history function in the window (Note on December 20, 2017: this function has not been added)
        '----------------------------------------
        If mrc.RecordCount = 0 Then
        MsgBox "Please add basic data", vbOKOnly + vbExclamation, "Warning"
        Text1.Enabled = True
         Text2.Enabled = True
         Text3.Enabled = True
         Text5.Enabled = True
         Text6.Enabled = True
         Text7.Enabled = True
         Command2.Enabled = False
         Command3.Enabled = True
         Command1.Enabled = False
        Else
        mrc.AddNew
        mrc.Fields(0) = Trim(Text1.Text)
        mrc.Fields(1) = Trim(Text2.Text)
        mrc.Fields(2) = Trim(Text3.Text)
        mrc.Fields(3) = Trim(Text5.Text)
        mrc.Fields(4) = Trim(Text6.Text)
        mrc.Fields(5) = Trim(Text7.Text)
        mrc.Fields(6) = Trim(1)
        mrc.Fields(7) = Trim(Date)
        mrc.Fields(8) = Trim(Time)
        
        mrc.Update
        MsgBox "Modification successful!", vbOKOnly + vbExclamation, "Warning"
        'mrc.Bookmark = mybookmark
        End If

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325991278&siteId=291194637