Real Software Forums
http://forums.realsoftware.com/

NilObjectException with XP but not Win7
http://forums.realsoftware.com/viewtopic.php?f=6&t=48035
Page 1 of 1

Author:  dgdavidge [ Sat Jun 01, 2013 10:31 am ]
Post subject:  NilObjectException with XP but not Win7

Sub Open()
dim rs As RecordSet, f As FolderItem
rs = app.MainDB.SQLSelect("SELECT * FROM Setups WHERE Name = 'pdfFolder'")
if rs <> nil and rs.RecordCount > 0 Then
PDFPath = rs.Field("Value").StringValue
f = GetFolderItem(PDFPath)
if not f.Exists Then
dim f1 As FolderItem = f.Parent
if not f1.Exists Then
dim f2 As FolderItem = f1.Parent
if not f2.Exists Then f2.CreateAsFolder
f1.CreateAsFolder
Else
f.CreateAsFolder
end if
end if
end if


End Sub
This routine works fine in Win7 but throws an nil object error at the line
if not f1.Exists Then
This was with 2012R2.1. I rebuilt it with 2011R4.3 and the same thing still happens. The code was originally developed several years ago an an XP machine. The updated program has some features that I'm afraid won't work if I have to go back several years to fix this.

The recordset returns a valid path that exists on the computer. I'm looking for suggestions for a work around.

Author:  kermit [ Sat Jun 01, 2013 11:12 am ]
Post subject:  Re: NilObjectException with XP but not Win7

Not sure what you were hoping for but look at what the code is doing:

if not f.Exists Then
dim f1 As FolderItem = f.Parent




So you already know f does not exist, but then you set a variable to its parent anyway?
What is the parent of a non existent item?

Author:  timhare [ Sat Jun 01, 2013 12:18 pm ]
Post subject:  Re: NilObjectException with XP but not Win7

Quote:
The recordset returns a valid path that exists on the computer.

The nilobjectexception would indicate otherwise. Double check your path. There is something wrong with it.

Author:  npalardy [ Sat Jun 01, 2013 12:28 pm ]
Post subject:  Re: NilObjectException with XP but not Win7

dgdavidge wrote:
Sub Open()
dim rs As RecordSet, f As FolderItem
rs = app.MainDB.SQLSelect("SELECT * FROM Setups WHERE Name = 'pdfFolder'")
if rs <> nil and rs.RecordCount > 0 Then
PDFPath = rs.Field("Value").StringValue
f = GetFolderItem(PDFPath)
if not f.Exists Then
dim f1 As FolderItem = f.Parent
if not f1.Exists Then
dim f2 As FolderItem = f1.Parent
if not f2.Exists Then f2.CreateAsFolder
f1.CreateAsFolder
Else
f.CreateAsFolder
end if
end if
end if


End Sub
This routine works fine in Win7 but throws an nil object error at the line
if not f1.Exists Then
This was with 2012R2.1. I rebuilt it with 2011R4.3 and the same thing still happens. The code was originally developed several years ago an an XP machine. The updated program has some features that I'm afraid won't work if I have to go back several years to fix this.

The recordset returns a valid path that exists on the computer. I'm looking for suggestions for a work around.


f = GetFolderItem(PDFPath)

I'd double check this line
It probably just needs to be updated to

f = GetFolderItem(PDFPath,Folderitem.PathTypeAbsolute)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/