Send and receive fax calls from VB6

The Modem FAX ActiveX is an OCX component that can send an receive fax calls from your program.


This demonstrate will show you how to use the Modem FAX ActiveX from Visual Basic 6.


Requirements:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
Option Explicit
 
Dim bOpenFlag As Boolean
 
Private Sub cmdConfig_Click()
Dim lErr As Long
 
'Display configuration:
lErr = cFaxModem1.LineConfigDialog(cboModemDevices.ListIndex)
If lErr <> 0 Then
    'Err
End If
 
End Sub
 
Private Sub cmdLineInfo_Click()
 
Dim LineDev As LineDevCap
 
'Set the line index to get the results for:
cFaxModem1.LineIndex = cboModemDevices.ListIndex
 
'Get the device index to the LineDev:
cFaxModem1.LineGetDevDetails LineDev
 
'Display the results:
txtResults = txtResults & vbCrLf _
            & "Device Name:" & LineDev.DeviceName & vbCrLf _
            & "Tapi Capability: " & LineDev.TapiCapability & vbCrLf _
            & "Max Rate: " & LineDev.MaxRate & vbCrLf _
            & "Support Monitor Digits: " & LineDev.MonitorDigits & vbCrLf _
            & "Support Generate Digits: " & LineDev.GenerateDigits & vbCrLf _
            & "Data Mode:" & LineDev.MediaDatamodem & vbCrLf _
            & "Interactivevoice:" & LineDev.MediaInteractivevoice & vbCrLf _
            & "Auto Voice:" & LineDev.MediaAutomatedvoice & vbCrLf _
            & "CommPort:" & "COM" & cFaxModem1.GetPortNumber(cboModemDevices.ListIndex) & vbCrLf
 
            txtResults = txtResults & vbCrLf
 
End Sub
 
Private Sub cmdLocInfo_Click()
 
'Get the country code:
txtResults.Text = txtResults & "Local country Code:" & cFaxModem1.GetCountryCode & vbCrLf
 
'Get the city code:
txtResults.Text = txtResults & "Local city Code:" & cFaxModem1.GetCityCode & vbCrLf
 
End Sub
 
 
Private Sub cmdLocProp_Click()
 
cFaxModem1.LineTranslateDialog
 
End Sub
 
 
Private Sub cmdSetValues_Click()
 
'*****************************************************************
'Set more propeties of the fax call.

'Please Note: You don't have to set these values,
'the default values of the control are ready to
'receive and send faxes with the most modem devices.

'This sample shows how to set the properties of the fax call.

cFaxModem1.FaxClass = cboFaxClass.ListIndex
cFaxModem1.FaxReceiveEncoding = cboEncoding.ListIndex
'For sending:
'cboEncoding.ListIndex = cFaxModem1.FaxSendEncoding
cFaxModem1.FaxReceiveBaud = cboBaud.ListIndex
'For sending:
'cboBaud.ListIndex = cFaxModem1.FaxSendBaud
cFaxModem1.SpeakerMode = cboSpeakerMode.ListIndex
cFaxModem1.SpeakerVol = cboSpeakerVol.ListIndex
cFaxModem1.ComStopBits = cboStopBits.ListIndex
cFaxModem1.ComParity = cboParity.ListIndex
 
'Check boxes
cFaxModem1.FlowControlCTS = CBool(chkFlowControlCTS.Value)
cFaxModem1.FlowControlDSR = CBool(chkFlowControlDSR.Value)
cFaxModem1.FlowControlSOFT = CBool(chkFlowControlSOFT.Value)
cFaxModem1.FaxSendECM = CBool(chkFaxSendECM.Value)
cFaxModem1.FaxSendFine = CBool(chkFaxSendFine.Value)
cFaxModem1.FaxSendECM = CBool(chkFaxSendECM.Value)
cFaxModem1.FaxSendUnlimited = CBool(chkFaxSendUnlimited.Value)
cFaxModem1.FaxPulseDialing = CBool(chkFaxPulseDialing.Value)
 
'*****************************************************************

End Sub
 
Private Sub Form_Load()
 
'Init the control, must be call
'before using any functionality
'of the control.
'
'sKey = Your license key.
'
cFaxModem1.Init "Trial Mode."
 
Dim LineIndex As Long
Dim sDeviceName As String
Dim LineDev As LineDevCap
 
 
'Scan all the modem devices and
'get the device name:
For LineIndex = 0 To cFaxModem1.NumOfLines - 1
 
    'Get device details by the index
    cFaxModem1.LineIndex = LineIndex
    cFaxModem1.LineGetDevDetails LineDev
    sDeviceName = LineDev.DeviceName
 
    'Add to the list DeviceName and DeviceIndex.
    cboModemDevices.AddItem sDeviceName
 
Next LineIndex
 
'*****************************************************************
'Get the default propeties of the control:

'Please Note: You don't have to set these values,
'the default values of the control are ready to
'receive and send faxes with the most modem devices.

cboFaxClass.ListIndex = cFaxModem1.FaxClass
cboEncoding.ListIndex = cFaxModem1.FaxReceiveEncoding
'For sending:
'cboEncoding.ListIndex = cFaxModem1.FaxSendEncoding
cboBaud.ListIndex = cFaxModem1.FaxReceiveBaud
'For sending:
'cboBaud.ListIndex = cFaxModem1.FaxSendBaud
cboSpeakerMode.ListIndex = cFaxModem1.SpeakerMode
cboSpeakerVol.ListIndex = cFaxModem1.SpeakerVol
cboStopBits.ListIndex = cFaxModem1.ComStopBits
cboParity.ListIndex = cFaxModem1.ComParity
 
'Check boxes
chkFlowControlCTS.Value = Bool2Val(cFaxModem1.FlowControlCTS)
chkFlowControlDSR.Value = Bool2Val(cFaxModem1.FlowControlDSR)
chkFlowControlSOFT.Value = Bool2Val(cFaxModem1.FlowControlSOFT)
chkFaxSendECM.Value = Bool2Val(cFaxModem1.FaxSendECM)
chkFaxSendFine.Value = Bool2Val(cFaxModem1.FaxSendFine)
chkFaxSendECM.Value = Bool2Val(cFaxModem1.FaxSendECM)
chkFaxSendUnlimited.Value = Bool2Val(cFaxModem1.FaxSendUnlimited)
chkFaxPulseDialing.Value = Bool2Val(cFaxModem1.FaxPulseDialing)
'*****************************************************************

'Select the first modem device from the list:
cboModemDevices.ListIndex = 0
 
 
End Sub
 
 
'Just to set the check box from boolean to number
'(true = 1, false = 0)
Private Function Bool2Val(bVal As Boolean) As Long
If bVal Then Bool2Val = 1
End Function
 
 
Private Sub Form_Unload(Cancel As Integer)
 
If bOpenFlag = True Then
 
    MsgBox "Please close line before closing the program."
    Cancel = 1
    cmdCancelRecive_Click
    Exit Sub
 
End If
 
'Release the control
cFaxModem1.DeInit
 
End Sub
 
Private Sub txtResults_Change()
 
'Auto scroll down:
txtResults.SelStart = Len(txtResults.Text) - 1
 
End Sub
 
 
'************************************************************
'************************************************************
'************************************************************
' FAX
'************************************************************
'************************************************************
'************************************************************

 
Private Sub cmdComDetection_Click()
 
Dim lLineIndex As Long
 
'Get the line index of the device:
lLineIndex = cboModemDevices.ListIndex
 
'Set the comm port of the modem device (e.g: 'COM3')
cFaxModem1.ComPort = "COM" & cFaxModem1.GetPortNumber(lLineIndex)
 
'Detect the fax modem device:
cFaxModem1.FaxClass = FAX_DETECT
cFaxModem1.ComDetection
 
End Sub
 
Private Sub cmdReceiveFax_Click()
 
'Set the comm port of the modem device (e.g: 'COM3')
cFaxModem1.ComPort = "COM" & cFaxModem1.GetPortNumber(cboModemDevices.ListIndex)
 
'*****************************************************************
'Set more propeties of the fax call.

'The default values were set for receive and send faxes with
'most of the fax modem devices.
'But you can set more properties of the fax call
'using the control.

'cFaxModem1.FaxClass = FAX_CLASS_1
'cFaxModem1.RingsBeforeAnswering = 3
'cFaxModem1.ComInitString = "AT&F&C1&D2&K3S7=55S0=0"
'cFaxModem1.FlowControlCTS = True
'cFaxModem1.FlowControlDSR = False
'cFaxModem1.FlowControlSOFT = False
'cFaxModem1.FaxSendBaud = FAX_BAUD_19200
'*****************************************************************

'Get the caller id:
cFaxModem1.ComInitString = "AT+VCID=1"
 
'Set the numeber of rings before answering:
cFaxModem1.RingsBeforeAnswering = txtRingsBeforeAnswering.Text
 
'Set the fax file to receive:
cFaxModem1.TiffFileReceive = txtReceiveFax.Text
 
'Set the line open flag:
bOpenFlag = True
 
'Set the control to wait for fax call:
cFaxModem1.ReceiveFax
 
End Sub
 
Private Sub cmdCancelRecive_Click()
 
cFaxModem1.CancelFax
 
bOpenFlag = False
 
End Sub
 
Private Sub cmdSendFax_Click()
 
'Set the comm port of the modem device (e.g: 'COM3')
cFaxModem1.ComPort = "COM" & cFaxModem1.GetPortNumber(cboModemDevices.ListIndex)
 
cFaxModem1.FaxClass = FAX_DETECT
 
cFaxModem1.TiffFileSend = App.Path & "\1.tif"
cFaxModem1.PhoneNumber = "0545900630"
cFaxModem1.SendFax
 
End Sub
 
 
Private Sub cmdCancelSend_Click()
 
cFaxModem1.CancelFax
 
End Sub
 
'*********************************************************************
'EVENTS:
'*********************************************************************

Private Sub cFaxModem1_FaxCallerID(ByVal CallerID As String)
 
txtResults.Text = txtResults.Text & "CallerID:" & CallerID & vbCrLf
 
End Sub
 
Private Sub cFaxModem1_FaxDetectionFinished(ByVal Classes As String, ByVal Manufacturer As String, _
ByVal Model As String, ByVal ProductCode As String, ByVal IDCode As String, ByVal Class2Capability As String, _
ByVal Class20Capability As String, ByVal VoiceCapability As String)
 
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
txtResults.Text = txtResults.Text & "----FaxDetectionFinished----" & vbCrLf
txtResults.Text = txtResults.Text & "Classes:" & Classes & vbCrLf
txtResults.Text = txtResults.Text & "Manufacturer:" & Manufacturer & vbCrLf
txtResults.Text = txtResults.Text & "Model:" & Model & vbCrLf
txtResults.Text = txtResults.Text & "ProductCode:" & ProductCode & vbCrLf
txtResults.Text = txtResults.Text & "IDCode:" & IDCode & vbCrLf
txtResults.Text = txtResults.Text & "Class2Capability:" & Class2Capability & vbCrLf
txtResults.Text = txtResults.Text & "Class20Capability:" & Class20Capability & vbCrLf
txtResults.Text = txtResults.Text & "VoiceCapability:" & VoiceCapability & vbCrLf
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
 
End Sub
 
Private Sub cFaxModem1_FaxDisconnected()
txtResults.Text = txtResults.Text & "FaxDisconnected" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxError(ByVal ErrorMessage As String)
txtResults.Text = txtResults.Text & "FaxError:" & ErrorMessage & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxFailed()
txtResults.Text = txtResults.Text & "FaxFailed" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxGotRemoteID(ByVal ReceivedID As String)
txtResults.Text = txtResults.Text & "FaxGotRemoteID:" & ReceivedID & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxIdle()
txtResults.Text = txtResults.Text & "FaxIdle" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxInfo(ByVal Message As String)
txtResults.Text = txtResults.Text & "FaxInfo:" & Message & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxPageData(ByVal Percent As Long)
txtResults.Text = txtResults.Text & "FaxPageData:" & Percent & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxReceiveDCS(ByVal BitRate As Long, ByVal PageWidth As Long, _
ByVal PageLength As String, ByVal VertRes As String, ByVal DataFormat As String, _
ByVal ECM As String, ByVal ScanTime As Long)
 
 
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
txtResults.Text = txtResults.Text & "----FaxReceiveDCS----" & vbCrLf
txtResults.Text = txtResults.Text & "BitRate:" & BitRate & vbCrLf
txtResults.Text = txtResults.Text & "PageWidth:" & PageWidth & vbCrLf
txtResults.Text = txtResults.Text & "PageLength:" & PageLength & vbCrLf
txtResults.Text = txtResults.Text & "VertRes:" & VertRes & vbCrLf
txtResults.Text = txtResults.Text & "DataFormat:" & DataFormat & vbCrLf
txtResults.Text = txtResults.Text & "ECM:" & ECM & vbCrLf
txtResults.Text = txtResults.Text & "ScanTime:" & ScanTime & vbCrLf
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
 
End Sub
 
 
Private Sub cFaxModem1_FaxReceiveDIS(ByVal BitRate As Long, ByVal PageWidth As Long, ByVal PageLength As String, ByVal VertRes As String, ByVal DataFormat As String, ByVal ECM As String, ByVal ScanTime As Long)
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
txtResults.Text = txtResults.Text & "----FaxReceiveDIS----" & vbCrLf
txtResults.Text = txtResults.Text & "BitRate:" & BitRate & vbCrLf
txtResults.Text = txtResults.Text & "PageWidth:" & PageWidth & vbCrLf
txtResults.Text = txtResults.Text & "PageLength:" & PageLength & vbCrLf
txtResults.Text = txtResults.Text & "VertRes:" & VertRes & vbCrLf
txtResults.Text = txtResults.Text & "DataFormat:" & DataFormat & vbCrLf
txtResults.Text = txtResults.Text & "ECM:" & ECM & vbCrLf
txtResults.Text = txtResults.Text & "ScanTime:" & ScanTime & vbCrLf
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxRing()
txtResults.Text = txtResults.Text & "FaxRing" & vbCrLf
End Sub
 
 
Private Sub cFaxModem1_FaxSentDCS(ByVal BitRate As Long, ByVal PageWidth As Long, ByVal PageLength As String, ByVal VertRes As String, ByVal DataFormat As String, ByVal ECM As String, ByVal ScanTime As Long)
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
txtResults.Text = txtResults.Text & "----FaxSentDCS----" & vbCrLf
txtResults.Text = txtResults.Text & "BitRate:" & BitRate & vbCrLf
txtResults.Text = txtResults.Text & "PageWidth:" & PageWidth & vbCrLf
txtResults.Text = txtResults.Text & "PageLength:" & PageLength & vbCrLf
txtResults.Text = txtResults.Text & "VertRes:" & VertRes & vbCrLf
txtResults.Text = txtResults.Text & "DataFormat:" & DataFormat & vbCrLf
txtResults.Text = txtResults.Text & "ECM:" & ECM & vbCrLf
txtResults.Text = txtResults.Text & "ScanTime:" & ScanTime & vbCrLf
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxSentDIS(ByVal BitRate As Long, ByVal PageWidth As Long, ByVal PageLength As String, ByVal VertRes As String, ByVal DataFormat As String, ByVal ECM As String, ByVal ScanTime As Long)
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
txtResults.Text = txtResults.Text & "----FaxSentDIS----" & vbCrLf
txtResults.Text = txtResults.Text & "BitRate:" & BitRate & vbCrLf
txtResults.Text = txtResults.Text & "PageWidth:" & PageWidth & vbCrLf
txtResults.Text = txtResults.Text & "PageLength:" & PageLength & vbCrLf
txtResults.Text = txtResults.Text & "VertRes:" & VertRes & vbCrLf
txtResults.Text = txtResults.Text & "DataFormat:" & DataFormat & vbCrLf
txtResults.Text = txtResults.Text & "ECM:" & ECM & vbCrLf
txtResults.Text = txtResults.Text & "ScanTime:" & ScanTime & vbCrLf
txtResults.Text = txtResults.Text & "***********************************************" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxStartPage(ByVal Page As Long, ByVal Baud As Long)
txtResults.Text = txtResults.Text & "FaxStartPage->Page:" & Page & " Baud:" & Baud & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxStartReceive()
txtResults.Text = txtResults.Text & "FaxStartReceive" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxStartSend()
txtResults.Text = txtResults.Text & "FaxStartSend" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxStartTraining()
txtResults.Text = txtResults.Text & "FaxStartTraining" & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxSuccess()
txtResults.Text = txtResults.Text & "FaxSuccess" & vbCrLf
End Sub
 
Private Sub cFaxModem1_ProcMessage(ByVal sMsg As String)
txtResults.Text = txtResults.Text & sMsg & vbCrLf
End Sub
 
Private Sub cFaxModem1_FaxProcMessage(ByVal sMsg As String)
txtResults.Text = txtResults.Text & sMsg & vbCrLf
End Sub
 
Private Sub cFaxModem1_Error(lErrNumber As Long, sErrMessage As String)
txtResults.Text = txtResults.Text & "ERROR:" & sErrMessage & vbCrLf
End Sub



Links:





read the original story ...
comments: Closed tags: , , , , , , , ,

2 Responses to “Send and receive fax calls from VB6”

  1. aspergers syndromes symptoms says:

    Superb blog post, I have book marked this internet site so ideally I’ll see much more on this subject in the foreseeable future!

  2. auto mechanics says:

    Thanks for an idea, you sparked at thought from a angle I hadn’t given thoguht to yet. Now lets see if I can do something with it.



Pings responses to this post