Attribute VB_Name = "VBDDE1"
Declare Function GetSystemMetrics Lib "User32" (ByVal n As Integer) As Integer
Global Const SM_CXVSCROLL = 2

Global SavedSessionInfo(26) As Boolean

Global LogData$(0 To 99)
Global TempData$(0 To 12)
Global LogTop           As Integer
Global LogEnd           As Integer
Global Loged            As Integer
Global FunctionComp     As Integer

Global Const MAXLOGNUM = 99
Global Const CHECKED = 1
Global Const UNCHECKED = 0

Global Const NONE = 0
Global Const HOT = 1
Global Const COLD = 2

Global Const ST_OK = -1
Global Const ST_ERROR = 0

Global Const APPLICATION_NAME = "IBM327032" ' or "IBM525032"

Global MSG_SAMPLE_PROG As String
Global MSG_APPLICATION As String
Global MSG_TOPIC As String
Global MSG_ITEM As String
Global MSG_FUNCTION_COMP As String
Global MSG_DDE_ERROR As String
Global MSG_PARA_ERROR As String
Global MSG_INVALID_DATA As String
Global MSG_OK As String
Global MSG_NG As String
Global MSG_INVALID_PSID As String

Global Const cdlOFNReadOnly = &H1             'Checks Read-Only check box for Open and Save As dialog boxes.
Global Const cdlOFNOverwritePrompt = &H2      'Causes the Save As dialog box to generate a message box if the selected file already exists.
Global Const cdlOFNHideReadOnly = &H4         'Hides the Read-Only check box.
Global Const cdlOFNNoChangeDir = &H8          'Sets the current directory to what it was when the dialog box was invoked.
Global Const cdlOFNHelpButton = &H10          'Causes the dialog box to display the Help button.
Global Const cdlOFNNoValidate = &H100         'Allows invalid characters in the returned filename.
Global Const cdlOFNAllowMultiselect = &H200   'Allows the File Name list box to have multiple selections.
Global Const cdlOFNExtensionDifferent = &H400 'The extension of the returned filename is different from the extension set by the DefaultExt property.

Global Const cdlOFNPathMustExist = &H800   'User can enter only valid path names.
Global Const cdlOFNFileMustExist = &H1000  'User can enter only names of existing files.
Global Const cdlOFNCreatePrompt = &H2000   'Sets the dialog box to ask if the user wants to create a file that doesn't currently exist.
Global Const cdlOFNShareAware = &H4000     'Sharing violation errors will be ignored.
Global Const cdlOFNNoReadOnlyReturn = &H8000  'The returned file doesn't have the Read-Only attribute set and won't be in a write-protected directory.
Global Const cdlOFNExplorer = &H8000       'Use the Explorer-like Open A File dialog box template.  (Windows 95 only.)
Global Const cdlOFNNoDereferenceLinks = &H100000       'Do not dereference shortcuts (shell links).  By default, choosing a shortcut causes it to be dereferenced by the shell.  (Windows 95 only.)

Global Const cdlOFNLongNames = &H200000               'Use Long filenames.  (Windows 95 only.)








Public Function GetDisplayType(SessionId As String) As String
On Error GoTo ErrHandler
   FunctionComp = True

   GetDisplayType$ = "NONE"
   
   rc = DoEvents()              'If you use VisualBasic V2.0, call
                                'DoEvents function each time before
                                'starting DDE conversation.
   MainForm.GetDisplayTypeText.LinkTimeout = 50  ' Wait 5 seconds
   MainForm.GetDisplayTypeText.LinkTopic = "IBM327032|System"
   MainForm.GetDisplayTypeText.LinkMode = COLD
   MainForm.GetDisplayTypeText.LinkItem = "Status"
   MainForm.GetDisplayTypeText.LinkRequest
   MainForm.GetDisplayTypeText.LinkMode = NONE
   If FunctionComp = True Then
      AllSessionInfo$ = MainForm.GetDisplayTypeText.Text
      
      NLCR$ = Chr$(13) + Chr$(10)
      ' There are at most 26 sessions.
      For LineCount = 1 To 26
        If (Mid$(AllSessionInfo$, 1, 1) = SessionId) Then

          BeginningOfField = 0
          EndOfField = 0
          For Index = 1 To 3
            BeginningOfField = BeginningOfField + EndOfField + 1
            EndOfField = InStr(Mid$(AllSessionInfo$, BeginningOfField), Chr$(9))
          Next Index
          
          ReturnString$ = Mid$(AllSessionInfo$, BeginningOfField, EndOfField - 1)
          GetDisplayType$ = Left$(ReturnString$, 4)
          Exit For
        Else
          EndOfLine = InStr(1, AllSessionInfo$, NLCR$)
        
          If EndOfLine = 0 Then
            ' No more lines.
            Exit For
          Else
            ' Found NLCR.
            AllSessionInfo$ = Mid$(AllSessionInfo$, EndOfLine + 2)
            ' Just in case the last line has a NLCR in the future.
            If AllSessionInfo$ = "" Then
              Exit For
            End If
          End If
        End If
      Next LineCount
   End If
   Exit Function

ErrHandler:
   FunctionComp = False
   Resume Next

End Function

Public Sub GetSessionDimensions(SessionId As String, Width As Integer, Height As Integer)
On Error GoTo ErrHandler
   FunctionComp = True
   Width = 0
   Height = 0

   Topic$ = "Session" + SessionId
   Item$ = "SSTAT"
   
   rc = DoEvents()              'If you use VisualBasic V2.0, call
                                'DoEvents function each time before
                                'starting DDE conversation.
   MainForm.SessionDimensionsTextBox.LinkTimeout = -1
   MainForm.SessionDimensionsTextBox.LinkTopic = APPLICATION_NAME + "|" + Topic$
   MainForm.SessionDimensionsTextBox.LinkMode = COLD
   MainForm.SessionDimensionsTextBox.LinkItem = Item$
   MainForm.SessionDimensionsTextBox.LinkRequest
   MainForm.SessionDimensionsTextBox.LinkMode = NONE

   If FunctionComp = True Then
     StartPos& = 1
     EndPos& = 1
     StringLength& = Len(MainForm.SessionDimensionsTextBox.Text)
     For i% = 0 To 3
       EndPos& = InStr(StartPos&, MainForm.SessionDimensionsTextBox.Text, Chr$(9))
       If EndPos& = 0 Then
         Width = 0
         Height = 0
         Exit Sub
       End If
       If i% = 2 Then
         Width = LTrim$(RTrim$(Mid$(MainForm.SessionDimensionsTextBox.Text, StartPos&, EndPos& - StartPos&)))
       ElseIf i% = 3 Then
         Height = LTrim$(RTrim$(Mid$(MainForm.SessionDimensionsTextBox.Text, StartPos&, EndPos& - StartPos&)))
       End If
       StartPos& = EndPos& + 1
     Next i%
   End If
Exit Sub

ErrHandler:
   FunctionComp = False
   Resume Next
End Sub

Public Sub CleanUpNumberText(NumberText As TextBox)
Dim NumericalValue As Integer

  InsertionPoint = NumberText.SelStart
  temp$ = NumberText.Text
  For Counter = 1 To Len(NumberText.Text)
    If InStr("0123456789", Mid(temp$, Counter, 1)) = 0 Then
      Mid(temp$, Counter, 1) = "0"
    End If
  Next Counter
  NumberText.Text = temp$
  NumberText.SelStart = InsertionPoint

End Sub



Public Function GetTrimRectangleCoords(SessionId As String, TopLeftColumn, TopLeftRow, BottomRightColumn, BottomRightRow) As String
On Error GoTo ErrHandler
   FunctionComp = True
   
   GetTrimRectangleCoords = "Closed"
   TopLeftColumn = 0
   TopLeftRow = 0
   BottomRightColumn = 0
   BottomRightRow = 0

   Topic$ = "Session" + SessionId
   Item$ = "SSTAT"
   
   rc = DoEvents()              'If you use VisualBasic V2.0, call
                                'DoEvents function each time before
                                'starting DDE conversation.
   MainForm.SessionCoordsTextBox.LinkTimeout = -1
   MainForm.SessionCoordsTextBox.LinkTopic = APPLICATION_NAME + "|" + Topic$
   MainForm.SessionCoordsTextBox.LinkMode = COLD
   MainForm.SessionCoordsTextBox.LinkItem = Item$
   MainForm.SessionCoordsTextBox.LinkRequest
   MainForm.SessionCoordsTextBox.LinkMode = NONE

   If FunctionComp = True Then
     StartPos& = 1
     EndPos& = 1
     StringLength& = Len(MainForm.SessionCoordsTextBox.Text)
     For i% = 0 To 10
       EndPos& = InStr(StartPos&, MainForm.SessionCoordsTextBox.Text, Chr$(9))
       If EndPos& = 0 Then
         GetTrimRectangleCoords = "Closed"
         Exit Function
       End If
       
       If (i% >= 6) And (i% <= 10) Then
         If i% = 6 Then
           GetTrimRectangleCoords = LTrim$(RTrim$(Mid$(MainForm.SessionCoordsTextBox.Text, StartPos&, EndPos& - StartPos&)))
         ElseIf i% = 7 Then
           TopLeftColumn = LTrim$(RTrim$(Mid$(MainForm.SessionCoordsTextBox.Text, StartPos&, EndPos& - StartPos&)))
         ElseIf i% = 8 Then
           TopLeftRow = LTrim$(RTrim$(Mid$(MainForm.SessionCoordsTextBox.Text, StartPos&, EndPos& - StartPos&)))
         ElseIf i% = 9 Then
           BottomRightColumn = LTrim$(RTrim$(Mid$(MainForm.SessionCoordsTextBox.Text, StartPos&, EndPos& - StartPos&)))
         ElseIf i% = 10 Then
           BottomRightRow = LTrim$(RTrim$(Mid$(MainForm.SessionCoordsTextBox.Text, StartPos&, EndPos& - StartPos&)))
         End If
       End If
       StartPos& = EndPos& + 1
     Next i%
   End If
Exit Function

ErrHandler:
   FunctionComp = False
   Resume Next
End Function

Public Sub AdjustForNT351(FormToAdjust As Form)

  For Each IndexControl In FormToAdjust.Controls()
    If TypeOf IndexControl Is TextBox Then
      If IndexControl.ScrollBars = 1 Then ' if Horizontal ScrollBar
        IndexControl.Height = IndexControl.Height + 120 ' Flat
        IndexControl.Top = IndexControl.Top - 30 ' Flat
      End If
    End If
  Next IndexControl
End Sub


