Error While running macro - Device I/O Error

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Error While running macro - Device I/O Error

Post by anant.chirmade »

Hi Team,

I have the following macro code in a file, which was working perfectly till now from many days.

however, now suddenly I am experimenting this error on multiple systems. I haven't changed anything in the code.

Please help.

Error :

Basic Runtime Error
Device I/O Error

Code :

Code: Select all

Sub Main


Dim FileNo As Integer
Dim Filename As String
dim Currentline as string

Doc = ThisComponent
Sheet = Doc.Sheets(0)
 
Cell = Sheet.getCellRangeByName("C12")
caseid = Cell.String

'Cell2 = Sheet.getCellRangeByName("D12")
'EmpCode = Cell2.String

Cell3 = Sheet.getCellRangeByName("C14")
Rmks = Cell3.String

Cell4 = Sheet.getCellRangeByName("C15")
AMName = Cell4.String

Cell5 = Sheet.getCellRangeByName("C16")
CMs = Cell5.String

if len(cell5.string) >= 30 then 

	msgbox "Your comments have exceeded the limit, Enter only required information in comments." & vbcrlf & "Case NOT Submitted."
	
	exit sub
	
end if

if cell5.string = "" or  cell4.string = "" or cell3.string = "" or cell.string = "" then

msgbox "Please fill all the fields. You cannot leave any field blank."

exit sub
end if

Filename = "\\172.19.32.61\xxx\yyy\xxxx.txt"            ' Define file name 
FileNo = FreeFile               ' Establish free file handle

Open Filename For Append As #FileNo

Print #FileNo, caseid  & "^" & right(Environ( "USERNAME" ) ,6) & "^" & Rmks & "^" & AMName & "^" & date & "^" & CMs

Close #FileNo                  


Msgbox "Case Submitted Successfully."

End Sub
Thanks in Advance...
Last edited by RoryOF on Mon Jul 13, 2015 11:29 am, edited 1 time in total.
Reason: Added [code] tags. [RoryOF, Moderator]
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Error While running macro - Device I/O Error

Post by MTP »

Based on the error message, I'm guessing the problem is with the writing to the text file? Which code line is highlighted when you get the error?
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Re: Error While running macro - Device I/O Error

Post by anant.chirmade »

Code: Select all

Open Filename For Append As #FileNo
This code is getting highlighted when the error occurs.
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Error While running macro - Device I/O Error

Post by Zizi64 »

Code: Select all

 Open Filename For Append As #FileNo
It means: The file, or the directory, or the device, or the IP address represented by the string in the variable 'Filename' is not exist or is not available.
Try it with function ISEXIST:

Code: Select all

If FileExists(Filename) Then  
     MsgBox "The file is exists and available"
Else
     MsgBox "The file is NOT exist or NOT available"
End If  
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Re: Error While running macro - Device I/O Error

Post by anant.chirmade »

Thanks for the response Zizi64.

But the file is alredy there from long time, when this tool was created.

Now also I check the file exists in the folder and still getting the same error while updating a case.
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: Error While running macro - Device I/O Error

Post by karolus »

Hallo

fileexists( "some file path" ) doesn't check the permissions to write the file...

Karolus
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Re: Error While running macro - Device I/O Error

Post by anant.chirmade »

Hi Karolus,

I checked the folder and file permissions and found that the associates already have read-write access to it.
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Error While running macro - Device I/O Error

Post by RoryOF »

In some cases I find OpenOffice cannot make a backup file; this inability may be causing your problem. If I write to my network iOmega device, OpenOffice can make the backup file. If I write to my network Buffalo LinkStation, OO cannot make a backup file, although it can save a new file. As far as I can tell, I (as User), and hence OO, have full read/write rights on both devices. Life not being long enough to sort out some mysteries, I merely backup important work by hand when using the Buffalo.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Re: Error While running macro - Device I/O Error

Post by anant.chirmade »

Hi RoryOF,

Honestly, I don't have any idea what you are referring to.

Still would like to know, what can we do if OO is not creating a Backup file..

The drive and file is saved on a Shared (Common) Drive from Users' system.
All the associates have Read-write access to it.
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Error While running macro - Device I/O Error

Post by RoryOF »

My point is simple: in some cases, on a shared drive, for unknown reasons (at least to me!), OpenOffice cannot create a backup file. This inability to create a file occurs in the background processing, not at the user level of OO, as one can readily make a new file at that level. Your macro may be running at that background level - what the fix is I cannot say.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
anant.chirmade
Posts: 9
Joined: Tue May 05, 2015 8:24 am

Re: Error While running macro - Device I/O Error

Post by anant.chirmade »

Thanks a lottt :) RoryF,

I got the idea from your suggestion and found that the notepad file (which is the master database and all data is getting updated in it) was open on some user's system.
Therefore, no one was able to update...

Now i have changed the path of master txt file, so user will only open the input file and not the DB.

If you don't mind, I need little more help with the code.

In order to avoid the user opening and keeping the txt file open, I have decided to shutdown the user's system once his shift is over..

So I have the code needed to shut down system, however I couldn't get the code to run the macro "On specific Time" (Like we have in excel application.ontime)

Thanks a ton.
OOVer = OpenOffice.Org 3.3.0
OS = Windows 7
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Error While running macro - Device I/O Error

Post by MTP »

StarBasic lacks any kind of timers. You'd need to use some other language (Python or Java, for example) to run a macro on an interval.

One user posted a workaround to this issue using StarBasic to call a BeanShell routine: [Solved] Can I autorefresh a form on a schedule?
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
Post Reply