home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / commdemo / module1.bas < prev    next >
BASIC Source File  |  1991-07-11  |  6KB  |  219 lines

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