Hi folks,
I've recently bought a CallerID device which has a parallel interface.
With it, it has a piece of source code which i cannot figure out.

Form1 Code:
VB Code:
  1. Public port
  2.  
  3. Private Sub Command1_Click()
  4. Close
  5. Open "c:\clid\clid.prt" For Output As #1
  6. If Option1.Value = True Then
  7. Print #1, "1"
  8. Else
  9. Print #1, "2"
  10. End If
  11. End
  12. End Sub
  13.  
  14. Private Sub Command2_Click()
  15. Form1.WindowState = 1
  16. End Sub
  17.  
  18. Private Sub Command3_Click()
  19. If Text1.Text <> "" Then
  20. Open "c:\clid\clid.dat" For Append As #1
  21. Print #1, Text1.Text; Spc(50 - (Len(Text1.Text))); Mid$(List1.List(List1.ListIndex), 11, 10)
  22. Close #1
  23. Label2.Visible = False
  24. Label3.Visible = False
  25. Text1.Visible = False
  26. List1.Visible = True
  27. Command1.Visible = True
  28. Command2.Visible = True
  29. Command3.Visible = False
  30. Text1.Text = ""
  31. End If
  32. End Sub
  33.  
  34. Private Sub Form_Load()
  35. Label2.Visible = False
  36. Label3.Visible = False
  37. Text1.Visible = False
  38. Command3.Visible = False
  39. Open "c:\clid\clid.prt" For Input As #1
  40. Line Input #1, prt$
  41. If prt$ = "1" Then
  42. Option1.Value = True
  43. Else
  44. Option2.Value = True
  45. End If
  46. Close #1
  47. ' This is a sample program. By no means the author can be held responsible
  48. ' for damage caused by this program. By using this program you agree with
  49. ' this terms. USE AT YOUR OWN RISC if your pc will implode or explode your in
  50. ' bad luck ;-)
  51.  
  52. ' Dit is een demonstratie programma. Het gebruik van dit programma is geheel
  53. ' voor EIGEN RISICO.
  54. ' Auteur kan niet aansprakelijk gehouden worden voor schade (van welke aard
  55. ' dan ook ) resulterende uit het gebruik van dit programma. Tevens kan auteur
  56. ' niet aansprakelijk worden gehouden voor fouten in het programma en of
  57. ' door operator gemaakte fouten.
  58. ' Door dit programma te gebruiken stemt U in met deze voorwaarden.
  59.  
  60. ' LET OP : Sluit nooit iets aan op de printerpoort terwijl de pc of het appa-
  61. '          raat wat u wilt aansluiten aanstaat.
  62. valid = 0
  63. Form1.WindowState = 1 'start minimized
  64. 'Print
  65. 'Print "Tijd          Naam                        Nummer"
  66. 'Print "-------------------------------------------------------------------"
  67. Do While True
  68.  
  69.     ' Here the subroutine is called which decodes the values received by the
  70.     ' decoder.
  71.     listen nr$, valid
  72.    
  73.     ' The following code will search a file for the received phonenumber.
  74.     ' If found the number will be dislayed on the screen with the corresponding
  75.     ' name. If not found Onbekend with the received number will be displayed.
  76.     If valid = 1 Then
  77.         Open "c:\clid\clid.dat" For Input As #2
  78.         tmp$ = "begin"
  79.         naam$ = "Onbekend                                          "
  80.  
  81.         Do While Not EOF(2)
  82.             Line Input #2, tmp$
  83.             nrtmp$ = Mid$(tmp$, 51)
  84.            
  85.             'check for -. or space in number
  86.             If InStr(nrtmp$, "-") Then
  87.                 nrtmp1$ = Left$(nrtmp$, (InStr(nrtmp$, "-") - 1))
  88.                 nrtmp1$ = nrtmp1$ + Mid$(nrtmp$, (InStr(nrtmp$, "-") + 1))
  89.                 nrtmp$ = nrtmp1$
  90.             End If
  91.            
  92.             If InStr(nrtmp$, ".") Then
  93.                 nrtmp1$ = Left$(nrtmp$, (InStr(nrtmp$, ".") - 1))
  94.                 nrtmp1$ = nrtmp1$ + Mid$(nrtmp$, (InStr(nrtmp$, ".") + 1))
  95.                 nrtmp$ = nrtmp1$
  96.             End If
  97.            
  98.             If InStr(nrtmp$, " ") Then
  99.                 nrtmp1$ = Left$(nrtmp$, (InStr(nrtmp$, " ") - 1))
  100.                 nrtmp1$ = nrtmp1$ + Mid$(nrtmp$, (InStr(nrtmp$, " ") + 1))
  101.                 nrtmp$ = nrtmp1$
  102.             End If
  103.            
  104.             If InStr(nrtmp$, nr$) Then
  105.                 naam$ = Left$(tmp$, 50)
  106.             End If
  107.         Loop
  108.  
  109.     Close #2
  110.  
  111.     List1.AddItem (Time$ & "  " & nr$ & "  " & naam$), 0
  112.     valid = 0
  113.     mstmp$ = Time$ & "  " & nr$ & "  " & naam$
  114.     Form1.WindowState = 2
  115.     Form1.Show
  116.     Open "c:\clid\clid.log" For Append As #2
  117.     Print #2, Date$ & " " & Time$ & "  " & nr$ & "  " & naam$
  118.     Close #2
  119.     End If
  120. Loop
  121. End Sub
  122.  
  123. Static Sub listen(nr$, valid)
  124. Static btime
  125. nr$ = ""
  126. Form1.Show
  127. i = Inp(port) '379 for lpt1 279 for lpt2
  128. Do While (i And 64) = 64 'While STD is high read decoded DTMF signal
  129. i = Inp(port)
  130. DoEvents
  131. Loop
  132. valid = 0 ' Indicator for receiving a complete number.
  133. ' A complete number begins with a 'D' then the numerals and ends with a 'C'
  134. If (i And 184) = &H8 Then a$ = a$ + "9"
  135. If (i And 184) = &H10 Then a$ = a$ + "0"
  136. If (i And 184) = &H18 Then a$ = a$ + "*"
  137. If (i And 184) = &H20 Then a$ = a$ + "#"
  138. If (i And 184) = &H28 Then
  139. a$ = ""
  140. btime = Now 'a$ + "A"
  141. End If
  142. If (i And 184) = &H30 Then
  143. a$ = ""
  144. btime = Now 'a$ + "B"
  145. End If
  146. If (i And 184) = &H80 Then
  147. a$ = ""
  148. btime = Now ' A 'D' was received. Clear nr$ for reception of new number
  149. End If
  150. If (i And 184) = &H88 Then a$ = a$ + "1"
  151. If (i And 184) = &H90 Then a$ = a$ + "2"
  152. If (i And 184) = &H98 Then a$ = a$ + "3"
  153. If (i And 184) = &HA0 Then a$ = a$ + "4"
  154. If (i And 184) = &HA8 Then a$ = a$ + "5"
  155. If (i And 184) = &HB0 Then a$ = a$ + "6"
  156. If (i And 184) = &HB8 Then a$ = a$ + "7"
  157. If (i And 184) = &H0 Then a$ = a$ + "8"
  158. Do While (i And 64) = 0 'While no new data wait (STD==LOW)
  159. i = Inp(port)
  160. DoEvents
  161. Loop
  162.  
  163. If (i And 184) = &H38 Then
  164. ' A 'C' is received. The number is complete and
  165. ' will be returned to the calling application.
  166. If DateDiff("s", btime, Now) <= 3 Then ' is het nummer binnen 2 sec ontvangen ?
  167. nr$ = a$
  168. a$ = ""
  169. valid = 1
  170. Exit Sub
  171. Else
  172. nr$ = ""
  173. a$ = ""
  174. End If
  175. End If
  176. End Sub
  177.  
  178. Private Sub List1_DblClick()
  179. List1.Visible = False
  180. Command1.Visible = False
  181. Command2.Visible = False
  182. Label2.Visible = True
  183. Text1.Visible = True
  184. Text1.SetFocus
  185. Label3.Visible = True
  186. Command3.Visible = True
  187. End Sub
  188.  
  189. Private Sub Option1_Click()
  190. port = &H379
  191. End Sub
  192.  
  193. Private Sub Option2_Click()
  194. port = &H279
  195. End Sub
  196.  
  197. Private Sub Text1_KeyPress(KeyAscii As Integer)
  198. If KeyAscii = 13 Then
  199. Command3.Value = True
  200. End If
  201. End Sub

Module Code:
VB Code:
  1. 'Declare Inp and Out for port I/O
  2. Public Declare Function Inp Lib "inpout32.dll" _
  3. Alias "Inp32" (ByVal PortAddress As Integer) As Byte
  4. Public Declare Sub Out Lib "inpout32.dll" _
  5. Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Byte)


From this code i tried to make an ActiveX dll for integration within my application. There i need one function that continously checks if there is a new phonenumber available.

I made a class TAPI:
VB Code:
  1. Option Explicit
  2.  
  3. Private A As String
  4. Private mvarTelNr As String
  5. Private mvarTime As String
  6.  
  7. Private Function PhoneListen() As Boolean
  8.     Static bTime As String
  9.    
  10.     mvarTelNr = ""
  11.     i = Inp(Port) 'LPT1 = 379, LPT2 = 279
  12.    
  13.     Do While (i And 64) = 64
  14.         i = Inp(Port)
  15.         DoEvents
  16.     Loop
  17.    
  18.     PhoneListen = False
  19.    
  20.     If (i And 184) = &H8 Then A = A & "9"
  21.     If (i And 184) = &H10 Then A = A & "0"
  22.     If (i And 184) = &H18 Then A = A & "*"
  23.     If (i And 184) = &H20 Then A = A & "#"
  24.    
  25.     If (i And 184) = &H28 Then
  26.         mvarTelNr = ""
  27.         i = Inp(Port)
  28.         Do While (i And 64) = 64
  29.             i = Inp(Port)
  30.             DoEvents
  31.         Loop
  32.        
  33.         PhoneListen = False
  34.  
  35.         ' A complete number begins with a 'D' then the numerals and ends with a 'C'
  36.         If (i And 184) = &H8 Then A = A & "9"
  37.         If (i And 184) = &H10 Then A = A & "0"
  38.         If (i And 184) = &H18 Then A = A & "*"
  39.         If (i And 184) = &H20 Then A = A & "#"
  40.        
  41.         If (i And 184) = &H28 Then
  42.             A = ""
  43.             bTime = Now()
  44.         End If
  45.        
  46.         If (i And 184) = &H30 Then
  47.             A = ""
  48.             bTime = Now()
  49.         End If
  50.        
  51.         If (i And 184) = &H80 Then
  52.             A = ""
  53.             bTime = Now() ' A 'D' was received. Clear nr$ for reception of new number
  54.         End If
  55.        
  56.         If (i And 184) = &H88 Then A = A & "1"
  57.         If (i And 184) = &H90 Then A = A & "2"
  58.         If (i And 184) = &H98 Then A = A & "3"
  59.         If (i And 184) = &HA0 Then A = A & "4"
  60.         If (i And 184) = &HA8 Then A = A & "5"
  61.         If (i And 184) = &HB0 Then A = A & "6"
  62.         If (i And 184) = &HB8 Then A = A & "7"
  63.         If (i And 184) = &H0 Then A = A & "8"
  64.        
  65.         Do While (i And 64) = 0 'While no new data wait (STD==LOW)
  66.             i = Inp(Port)
  67.             DoEvents
  68.         Loop
  69.  
  70.         If (i And 184) = &H38 Then
  71.             ' A 'C' is received. The number is complete and
  72.             ' will be returned to the calling application.
  73.             If DateDiff("s", bTime, Now) <= 3 Then ' is het nummer binnen 2 sec ontvangen ?
  74.                 mvarTelNr = A
  75.                 PhoneListen = True
  76.                 Exit Function
  77.             Else
  78.                 mvarTelNr = ""
  79.                 A = ""
  80.             End If
  81.         End If
  82.     End If
  83. End Function
  84.  
  85. Public Function GetPhoneNumber() As String
  86.     Dim NrTmp As String
  87.    
  88.     Do While PhoneListen = True
  89.         NrTmp = Trim(mvarTelNr)
  90.        
  91.         If InStr(NrTmp, "-") Then
  92.             NrTmp = Left$(NrTmp, (InStr(NrTmp, "-") - 1)) & Mid$(NrTmp, (InStr(NrTmp, "-") + 1))
  93.         End If
  94.        
  95.         If InStr(NrTmp, ".") Then
  96.             NrTmp = Left$(NrTmp, (InStr(NrTmp, ".") - 1)) & Mid$(NrTmp, (InStr(NrTmp, ".") + 1))
  97.         End If
  98.        
  99.         If InStr(NrTmp, " ") Then
  100.             NrTmp = Left$(NrTmp, (InStr(NrTmp, " ") - 1)) & Mid$(NrTmp, (InStr(NrTmp, " ") + 1))
  101.         End If
  102.     Loop
  103. End Function

and a global module:
VB Code:
  1. Option Explicit
  2.  
  3. Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Byte
  4. Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Byte)

Who can help me with finishing this piece? because i can't see exactly what the original code do. I is a little bit bad programming i guess.