by edgar.blaustein » Thu Jan 10, 2019 11:56 pm
Could one of the generous experts on this forum help with a difficulty in connecting to a modem from a CALC macro? (This is my last difficulty in porting a couple of Windows EXCEL based office programs to UBUNTU-OO).
The following is a slightly simplified version of code submitted to this forum by migalhas and zizi, at the top of this thread.
*****************
Option explicit
Sub Write_to_modem()
Dim OutputStr as string
Dim f as object
Dim i as integer
Dim OutputChar
Dim oFSO
OutputStr = " ATDT0123456789" & Chr(13) & Chr(10)
oFSO =
createUnoService("com.sun.star.bridge.OleObjectFactory").createInstance("Scripting.FileSystemObject")
f = oFSO.OpenTextFile("COM3:9600,N,8,1", 2) 'correct settings for my modem
' but this version crashes
' with "unexpected exception"
'f = oFSO.OpenTextFile("COM1:9600,N,8,1", 2) 'as written in this forum,
'wrong port number,
but does not crash
For i= 1 to Len(OutputStr)
OutputChar=(Mid(OutputStr,i,1))
f.write(OutputChar) 'Sending by each character
next i
f.close
End Sub
************************
This macro crashes at the .OpenTextFile command, with and "unexpected exception" error message.
I have tried different settings for the modem, including changing from my modem (COM3) to a non existant COM1 modem.
The following is a snippet of the VBA macro that I want to replace. This code works correctly.
********************
REM VBA macro that operates correctly
Sub DialNumber()
Dim PhoneNumber as String
Dim CommPort As String
Dim bModemCommand(256) As Byte, ModemCommand As String
Dim OpenPort As Long
Dim i As Integer
PhoneNumber = "0123456789"
' Open the communications port for read/write (&HC0000000).
' Must specify existing file (3).
OpenPort = CreateFile("COM3", &HC0000000, 0, 0, 3, 0, 0)
ModemCommand = "ATDT" & PhoneNumber & vbCrLf
' Pack the string in a Byte array.
For i = 0 To Len(ModemCommand) - 1
bModemCommand(i) = Asc(Mid(ModemCommand, i + 1, 1))
Next
' Write the string to the Com port.
RetVal = WriteFile(OpenPort, bModemCommand(0), _
Len(ModemCommand), RetBytes, 0)
End Sub
*******************************
Related question, in case this problem turns out to be insoluble: can anyone indicate a Ubuntu compatible stand alone dialer, that could be chained to, in order to replace this code?
Many thanks for your aid.
- Attachments
-
code1.doc
- (20 KiB) Downloaded 53 times
OpenOffice 4.1.5, WinXP and Ubuntu