Visual Basic Sample Program

Following is a sample program with Visual Basic®:
Note:
This sample program is simplified and differs from the actual sample file provided.
'/*************************************************/
'/*                                               */
'/*     System conversation                       */
'/*                                               */
'/*************************************************/
 
'***************************************************
'***                                             ***
'***    Initiate System Conversation             ***
'***                                             ***
'***************************************************
'
'  Start DDE Conversation with system
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim COLD As Integer
   COLD = 2
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|System"
   Text1.LinkMode  = COLD
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Get System Format                        ***
'***                                             ***
'***************************************************
'
'   Request a list of Personal Communications'   Clipboard Format
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "Formats"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get System Status                        ***
'***                                             ***
'***************************************************
'
'   Requests each Personal Communications'   Session Status
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "Status"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get System Configuration                 ***
'***                                             ***
'***************************************************
'
'   Requests Personal Communications'   System Configuration Values
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "SysCon"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get System SysItems                      ***
'***                                             ***
'***************************************************
'
'   Requests a list of Data Items for
'   Personal Communications System Conversation
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "SysItems"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get System Topics                        ***
'***                                             ***
'***************************************************
'
'   Requests a list of Personal Communications'   Topics
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "Topics"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Terminate System Conversation            ***
'***                                             ***
'***************************************************
'
'  Terminates DDE Conversation with system
'
Sub Command3_Click ()
On Error GoTo ErrHandler
   Dim NONE As IntegerTerm
   NONE = 0
   FunctionComp& = True
 
   Text1.LinkMode = NONE
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerTerm:
   FunctionComp& = False
   Resume Next
End Sub
 
'/*************************************************/
'/*                                               */
'/*     Session conversation                      */
'/*                                               */
'/*************************************************/
 
'***************************************************
'***                                             ***
'***    Initiate Session Conversation            ***
'***                                             ***
'***************************************************
'
'  Initiate DDE Conversation with system
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim COLD As Integer
   COLD = 2
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessionA"
   Text1.LinkMode = COLD
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Find Field                               ***
'***                                             ***
'***************************************************
'
'   Requests 100 Field Information of PS Position
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "FILED(100,""  "")"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get Operator Information Area            ***
'***                                             ***
'***************************************************
'
'   Requests OIA Data
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "OIA"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
'***************************************************
'***                                             ***
'***    Get Partial Presentation Space           ***
'***                                             ***
'***************************************************
'
'   Requests PS Data Bytes from PS Position from 100 to 1000
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "EPS(100,1000,1)"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get Presentation Space                   ***
'***                                             ***
'***************************************************
'
'   Requests PS Data
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "PS"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Get Session Status                       ***
'***                                             ***
'***************************************************
'
'   Requests Session Connection Status
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "SSTAT"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
'***************************************************
'***                                             ***
'***    Get Trim Rectangle                       ***
'***                                             ***
'***************************************************
'
'   Requests PS Data in Current Specified Trim Rectangle
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem = "TRIMRECT"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Put Data to Presentation Space           ***
'***                                             ***
'***************************************************
'
'   Writes string "Hello, World!" from PS Position 200
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.Text     = "Hello, World!"
   Text1.LinkItem = "EPS(200,1)"
   Text1.LinkPoke
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Search for String                        ***
'***                                             ***
'***************************************************
 
'
'   Search forward for string "Hello!" from PS Position 1
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkItem  = "STRING(1,1,""Hello!"")"
   Text1.LinkRequest
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Session Execute Macro                    ***
'***                                             ***
'***************************************************
'
'   Maximize the Session
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.LinkExecute "[WINDOW(MAXIMIZE)]"
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Set Cursor Position                      ***
'***                                             ***
'***************************************************
'
'   Set Cursor Position (Row,Column) = (1,1)
'
Sub Command2_Click ()
On Error GoTo ErrHandler
   FunctionComp& = True
 
   Text1.Text     = "R1C1"
   Text1.LinkItem = "SETCURSOR"
   Text1.LinkPoke
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandler:
   FunctionComp& = False
   Resume Next
End Sub
 
'***************************************************
'***                                             ***
'***    Terminate Session Conversation           ***
'***                                             ***
'***************************************************
'
'  Terminate DDE Conversation with session
'
Sub Command3_Click ()
On Error GoTo ErrHandlerTerm
   Dim NONE As Integer
   NONE = 0
   FunctionComp& = True
 
   Text1.LinkMode = NONE
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerTerm:
   FunctionComp& = False
   Resume Next
End Sub
 
'/*************************************************/
'/*                                               */
'/*     Session conversation(Hot Link)            */
'/*                                               */
'/*************************************************/
 
'***************************************************
'***                                             ***
'***    Start Close Intercept                    ***
'***                                             ***
'***************************************************
'
'  Start Intercepting Close request
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim HOT As Integer
   HOT = 1
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessionA"
   Text1.LinkItem  = "CLOSE"
   Text1.LinkMode  = HOT
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Start Keystroke Intercept                ***
'***                                             ***
'***************************************************
'
'  Start Intercepting Keystrokes
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim HOT As Integer
   HOT = 1
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessionA"
   Text1.LinkItem  = "KEYS"
   Text1.LinkMode  = HOT
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Start Session Advise(PS)                 ***
'***                                             ***
'***************************************************
'
'  Receives PS Data when updated
'  (only when "Hello!" is displayed from PS Position 1)
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim HOT As Integer
   HOT = 1
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessA_PS"
   Text1.LinkItem  = "PS(1,6,1,""Hello!"")"
   Text1.LinkMode  = HOT
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
 
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Start Session Advise(TRIMRECT)           ***
'***                                             ***
'***************************************************
'
'  Receives PS Data in Trim Rectangle when PS Data in Trim Rectangle
'  specified by R1C1:R20C40 is changed
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim HOT As Integer
   HOT = 1
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessA_TRIMRECT"
   Text1.LinkItem  = "TRIMRECT(1,1,20,40)"
   Text1.LinkMode  = HOT
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Start Session Advise(OIA)                ***
'***                                             ***
'***************************************************
'
'  Receives OIA Data when changed
'
Sub Command1_Click ()
On Error GoTo ErrHandlerInit
   Dim HOT As Integer
   HOT = 1
   FunctionComp& = True
 
   DoEvents
   Text1.LinkTopic = "IBM5250|SessA_OIA"
   Text1.LinkItem  = "OIA"
   Text1.LinkMode  = HOT
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerInit:
   FunctionComp& = False
   Resume Next
End Sub
 
'-- note -------------------------------------------
'
' If you use VisualBasic Version2.0, use "DoEvents"
' function before starting DDE conversation by
' calling "LinkMode" function.
'
'---------------------------------------------------
'***************************************************
'***                                             ***
'***    Terminate Session Conversation(Hot Link) ***
'***                                             ***
'***************************************************
'
'  Terminate DDE Conversation with session (Hot Link)
'
Sub Command3_Click ()
On Error GoTo ErrHandlerTerm
   Dim NONE As Integer
   NONE = 0
   FunctionComp& = True
 
   Text1.LinkMode = NONE
 
   If FunctionComp&= False Then
      MsgBox "Error has occurred", 48, "DDE sample"
   End If
   Exit Sub
 
ErrHandlerTerm:
   FunctionComp& = False
   Resume Next
End Sub