home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / comdem / module1.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  5.7 KB  |  219 lines

  1.  
  2. Sub CenterDialog (A_Form As Form)
  3.  
  4.     Dim cLeft As Integer
  5.     Dim cTop As Integer
  6.  
  7.     cLeft = (Screen.Width - A_Form.Width) / 2
  8.     cTop = (Screen.Height - A_Form.Height) / 2
  9.  
  10.     A_Form.Move cLeft, cTop
  11.  
  12. End Sub
  13.  
  14. Sub Delay (amount As Single)
  15.     
  16.     t! = Timer
  17.     
  18.     While t! + amount > Timer
  19.     Wend
  20.  
  21. End Sub
  22.  
  23. Sub DisplayQBOpen (TempDCB As CommStateDCB, DevName As String, RB As Integer, TB As Integer, Interval As Integer)
  24.  
  25.     ParityChar$ = "NOEMS"
  26.  
  27.     A$ = " Open " + Chr$(34) + DevName
  28.     A$ = A$ + LTrim$(Str$(TempDCB.BaudRate)) + ","
  29.     A$ = A$ + Mid$(ParityChar$, Asc(TempDCB.Parity) + 1, 1) + ","
  30.     A$ = A$ + LTrim$(Str$(Asc(TempDCB.ByteSize))) + ","
  31.     
  32.     Select Case Asc(TempDCB.StopBits)
  33.         Case 0
  34.             B$ = "1"
  35.         Case 1
  36.             B$ = "1.5"
  37.         Case 2
  38.             B$ = "2"
  39.         Case Else
  40.     End Select
  41.  
  42.     A$ = A$ + B$ + ","
  43.     
  44.     A$ = A$ + "RB" + LTrim$(Str$(RB)) + ","
  45.     A$ = A$ + "TB" + LTrim$(Str$(TB)) + ","
  46.     A$ = A$ + "CD" + LTrim$(Str$(TempDCB.RlsTimeOut)) + ","
  47.     A$ = A$ + "CS" + LTrim$(Str$(TempDCB.CtsTimeOut)) + ","
  48.     A$ = A$ + "DS" + LTrim$(Str$(TempDCB.DsrTimeOut)) + ","
  49.     A$ = A$ + "TI" + LTrim$(Str$(Interval))
  50.     
  51.     A$ = A$ + Chr$(34)
  52.  
  53.     UpdateCaption A$, 0
  54.  
  55. End Sub
  56.  
  57. Sub Draw3d (wLeft As Integer, wTop As Integer, wWidth As Integer, wHeight As Integer, A_Form As Form)
  58.     Dim LeftY As Integer
  59.     Dim LeftX As Integer
  60.     
  61.     Dim RightY As Integer
  62.     Dim RightX As Integer
  63.  
  64.     Dim Depth As Integer
  65.  
  66.     Dim OffSet As Integer
  67.     Dim SetIn As Integer
  68.  
  69.     OffSet = 15
  70.     SetIn = 1
  71.     
  72.     ' Draw the Black and White lines to give a "Set In" effect
  73.     ' around the text and buttons
  74.  
  75.     For Depth = OffSet To OffSet * SetIn Step OffSet
  76.         
  77.         LeftX = wLeft - Depth
  78.         LeftY = wTop - Depth
  79.         RightX = wLeft + wWidth + Depth
  80.         RightY = wTop + wHeight + Depth
  81.  
  82.         ' Draw the Top and Bottom Lines
  83.         A_Form.Line (LeftX, LeftY)-(RightX, LeftY), QBColor(0)
  84.         A_Form.Line (LeftX, RightY)-(RightX, RightY), QBColor(15)
  85.         
  86.         ' Draw the Left and Right Lines
  87.         A_Form.Line (LeftX - OffSet, LeftY)-(LeftX - OffSet, RightY + OffSet), QBColor(0)
  88.         A_Form.Line (RightX, LeftY)-(RightX, RightY + OffSet), QBColor(15)
  89.  
  90.     Next Depth
  91.  
  92. End Sub
  93.  
  94. Function ReadCommPort (ReadAmount As Integer) As String
  95.     
  96.     Dim ApiErr As Integer
  97.     Dim EventMask As Integer
  98.     Dim Found As Integer
  99.  
  100.     If ReadAmount < 1 Then
  101.         ReadCommPort = ""
  102.         Exit Function
  103.     End If
  104.  
  105.     EventMask = CommEventMask
  106.     ApiErr = GetCommEventMask(CommHandle, EventMask)
  107.     
  108.     If ApiErr And EV_RXCHAR Then
  109.         Buffer$ = Space$(ReadAmount)
  110.         ApiErr = ReadComm(CommHandle, Buffer$, Len(Buffer$))
  111.  
  112.         If ApiErr < 0 Then
  113.             UpdateCaption " ReadCOMM API FAILED! (ERR " + Str$(ApiErr) + ")", 3
  114.             Buffer$ = ""
  115.         Else
  116.             Buffer$ = Left$(Buffer$, ApiErr)
  117.             
  118.             ' Expand CR to CR/LF for "Text" box display
  119.  
  120.             Found = 1
  121.             Do
  122.                 Found = InStr(Found, Buffer$, Chr$(13))
  123.                 If Found Then
  124.                     Buffer$ = Left$(Buffer$, Found) + Chr$(10) + Right$(Buffer$, Len(Buffer$) - Found)
  125.                     Found = Found + 1
  126.                 End If
  127.             Loop While Found
  128.         End If
  129.     End If
  130.  
  131.     If (ApiErr And EV_RXFLAG) And (CommEventMask And EV_RXFLAG) Then
  132.     End If
  133.  
  134.     If (ApiErr And EV_TXEMPTY) And (CommEventMask And EV_XFLAG) Then
  135.     End If
  136.  
  137.     If (ApiErr And EV_CTS) And (CommEventMask And EV_CTS) Then
  138.     End If
  139.  
  140.     If (ApiErr And EV_DSR) And (CommEventMask And EV_DSR) Then
  141.     End If
  142.  
  143.     If (ApiErr And EV_RLSD) And (CommEventMask And EV_RLSD) Then
  144.     End If
  145.  
  146.     If (ApiErr And EV_BREAK) And (CommEventMask And EV_BREAK) Then
  147.     End If
  148.  
  149.     If (ApiErr And EV_ERR) And (CommEventMask And EV_ERR) Then
  150.     End If
  151.     
  152.     If (ApiErr And EV_PERR) And (CommEventMask And EV_PERR) Then
  153.     End If
  154.     
  155.     If (ApiErr And EV_RING) And (CommEventMask And EV_RING) Then
  156.         UpdateCaption " Receive Window: RING! ", 0
  157.         Beep
  158.     End If
  159.     
  160.     ReadCommPort = Buffer$
  161.  
  162. End Function
  163.  
  164. Sub Remove_Items_From_SysMenu (A_Form As Form)
  165.  
  166.     HSysMenu = GetSystemMenu(A_Form.Hwnd, 0)
  167.   
  168.     R = RemoveMenu(HSysMenu, 8, MF_BYPOSITION) 'Switch to
  169.     R = RemoveMenu(HSysMenu, 7, MF_BYPOSITION) 'Separator
  170.     R = RemoveMenu(HSysMenu, 5, MF_BYPOSITION) 'Separator
  171.     R = RemoveMenu(HSysMenu, 4, MF_BYPOSITION) 'Maximize
  172.     R = RemoveMenu(HSysMenu, 3, MF_BYPOSITION) 'Minimize
  173.     R = RemoveMenu(HSysMenu, 2, MF_BYPOSITION) 'Size
  174.     R = RemoveMenu(HSysMenu, 0, MF_BYPOSITION) 'Restore
  175.  
  176. End Sub
  177.  
  178. Sub UpdateCaption (Msg$, Wait As Single)
  179.  
  180.     Dim wHeight As Integer
  181.     Dim wCenter As Integer
  182.  
  183.     If CommDemo.TextWidth(CaptionText$) > CommDemo.TextWidth(Msg$) Then
  184.  
  185.         CommDemo.CurrentX = CaptionLeft
  186.         CommDemo.CurrentY = CaptionCenter
  187.         CommDemo.ForeColor = CommDemo.BackColor
  188.         CommDemo.Print CaptionText$;
  189.         CommDemo.ForeColor = 0
  190.  
  191.     End If
  192.     
  193.     wHeight = CommDemo.TextHeight(Msg$)
  194.     wCenter = (CaptionHeight - wHeight) / 2
  195.  
  196.     CaptionCenter = CaptionTop + wCenter
  197.     CaptionText$ = Msg$
  198.     
  199.     CommDemo.CurrentX = CaptionLeft
  200.     CommDemo.CurrentY = CaptionCenter
  201.     CommDemo.Print CaptionText$;
  202.  
  203.     If Wait Then
  204.         Delay Wait
  205.     End If
  206.  
  207. End Sub
  208.  
  209. Sub WriteCommPort (Send$)
  210.  
  211.     ApiErr% = WriteComm(CommHandle, Send$, Len(Send$))
  212.  
  213.     If ApiErr% < 0 Then
  214.         UpdateCaption " WriteComm API Failed! (ERR " + Str$(ApiErr%) + ")", 2
  215.     End If
  216.  
  217. End Sub
  218.  
  219.