I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLCan you show me an example of how you are using this file?
On what statement are you getting the null reference error?
The following works fine in my test program and the file opens correctly and writes the record when the static method is called:
class-id teststaticfile.Form1 is partial
inherits type System.Windows.Forms.Form.
select test-file assign to "testfile.dat"
organization is indexed
access is dynamic
record key is key1
file status is file-status.
data division.
file section.
fd test-file static.
01 test-record.
05 key1 pic x(3).
05 rest pic x(20).
working-storage section.
01 file-status pic x(2) value spaces static.
method-id NEW.
procedure division.
invoke self::InitializeComponent
goback.
end method.
method-id statmethod static.
procedure division.
open output test-file
display file-status
move all "1" to test-record
write test-record
invalid key
display "bad"
end-write
close test-file.
goback.
end method.
method-id button1_Click final private.
procedure division using by value sender as object e as type System.EventArgs.
invoke type teststaticfile.Form1::statmethod
end method.
end class.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLBelow is the code. I just thought of something. I was a little misleading because this is a class was added as a new item to a project that is using winforms. I wouldn't think that would make much of a difference though.
The exception happens when I try and open the return-file.
The compile errors occur when I remove the keyword static from the FD. Thanks for your help.
$set sourceformat(free)
class-id BeneScreens.beneMethods.
Environment division.
select return-file
assign to "c:\\temp\\returnfilebene.wrk"
organization is line sequential.
file section.
fd return-file static.
01 return-rec.
05 rr-pid-number pic x(06).
05 rr-button pic x(10).
working-storage section.
method-id InstanceMethod.
local-storage section.
procedure division.
goback.
end method.
method-id goToPid public static.
local-storage section.
open input return-file.
read return-file
if rr-button = "cancel"
set fromPidNum to goToPidPidNum
else
if rr-button = "ok"
set fromPidNum to rr-pid-number.
close return-file.
end method.
end class.
#VisualCOBOL
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI just added your code to a new class in the same project.
I had to remove the two references to the fromPidNum and the goToPidPidNum because these data items are not defined.
I added the following to my forms class:
invoke type BeneScreens.beneMethods::goToPid
and it invokes the method successfully and opens the file and returns.
I just used a dummy text file named c:\\temp\\returnfilebene.wrk and it all worked ok.
What product version are you using?
Go to Help-->About Microsoft Visual Studio and then select Visual COBOL in the list.
What is the version number?
Thanks.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLYeah, sorry about those two fields. I trimmed out what wasn't necessary. Below is the information that I believe you are looking for.
Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel Microsoft .NET Framework Version 4.5.50709 SP1Rel
Installed Version: IDE Standard
Microsoft Visual Web Developer 2010 01011-532-2002361-70156 Microsoft Visual Web Developer 2010
Hotfix for Visual Studio 2010 Shell (Integrated) - ENU (KB2549864) KB2549864 This hotfix is for Visual Studio 2010 Shell (Integrated) - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit support.microsoft.com/.../2549864.
Hotfix for Visual Studio 2010 Shell (Integrated) - ENU (KB2635973) KB2635973 This hotfix is for Visual Studio 2010 Shell (Integrated) - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit support.microsoft.com/.../2635973.
Micro Focus Visual COBOL 2.2 Serial number: 110000205879 Micro Focus Visual COBOL 2.2 Version 2.2.00244. Serial number: 110000205879 Full license For more information, visit http://www.microfocus.com. Copyright (C) Micro Focus 1984-2013. All rights reserved.
Security Update for Visual Studio 2010 Shell (Integrated) - ENU (KB2645410) KB2645410 This security update is for Visual Studio 2010 Shell (Integrated) - ENU. If you later install a more recent service pack, this security update will be uninstalled automatically. For more information, visit support.microsoft.com/.../2645410.
Visual Studio 2010 Shell (Isolated) - ENU Service Pack 1 (KB983509) KB983509 This service pack is for Visual Studio 2010 Shell (Isolated) - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically. For more information, visit support.microsoft.com/.../983509.
#VisualCOBOL
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLThat is the latest version which is 2.2 and is the same version that I am testing with.
Can you please open up a support incident for this and put my name in the description so that it comes to me?
I will need you to zip up your full project (or better yet a cutdown) and attach it to the incident so that I can try to reproduce the problem here.
Thanks.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI decided to give your code a try (below) that you submitted and when I did that I got an error message when I tried to create the solution -- see attached. I'm thinking that I will un-install the 2.2 and reinstall it before I submit a ticket, unless you think otherwise.
class-id teststaticfile.Form1 is partial
inherits type System.Windows.Forms.Form.
select test-file assign to "testfile.dat"
organization is indexed
access is dynamic
record key is key1
file status is file-status.
data division.
file section.
fd test-file static.
01 test-record.
05 key1 pic x(3).
05 rest pic x(20).
working-storage section.
01 file-status pic x(2) value spaces static.
method-id NEW.
procedure division.
invoke self::InitializeComponent
goback.
end method.
method-id statmethod static.
procedure division.
open output test-file
display file-status
move all "1" to test-record
write test-record
invalid key
display "bad"
end-write
close test-file.
goback.
end method.
method-id button1_Click final private.
procedure division using by value sender as object e as type System.EventArgs.
invoke type teststaticfile.Form1::statmethod
end method.
end class.
#VisualCOBOL
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLDid you have an earlier product release installed that you updated to the 2.2 release or did you install the 2.2 release as the first Visual COBOL product on this system?
Under what OS are you running?
Yes, go ahead and uninstall and reinstall the product and see if that makes a difference.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI had an earlier product release and then just this week I installed the 2.2. I'm on Windows 7 Professional Service Pack 1. I did un-install both the 2.2 release and the data tools 2.2 and I am still having problems in my program. It should also be noted that a co-worker is running pretty much the same software and he is having issues.
I accidently selected NO on that error message that I sent you earlier (attached), do you know how to turn that back on?
#VisualCOBOL
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLDid you mean "a co-worker is running pretty much the same software and he is NOT having issues."
Try uninstalling Visual COBOL 2.2 and then also uninstalling the Visual Studio 2010 Shell and then reinstalling Visual COBOL 2.2 so that it reinstalls the Visual Studio Shell as well.
Thanks.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLNo, a co-worker has pretty much the same software installed on his pc as mine and he IS having issues. He is running win 7 sp1 with vs 2010 shell and visual cobol 2.2. I will un-install the software as you suggested and get back to you.
One more thing in my previous post I asked if you knew how to get that error message to return as I accidently clicked for it to not return (that is what you get when you get into a hurry). Thanks
#VisualCOBOL
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI got the error message to return, must have returned after the re-install of the 2.2. Later today I am going to uninstall vs and vc. Thanks for your help.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLWhat was the version of your previous Visual COBOL product that was installed prior to the upgrade to 2.2?
Was it VC 2.1 or VC 2.1 update 1?
Thanks
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLChris,
I work with BHunt. The previous Visual COBOL version was VC 2.1 update 1.
The problem seems to occur when using an ISAM file and a text file in the same class. See the code below, which will cause the "Object reference not set to an instance of an object" error message. If the ISAM file was replaced with another text file, the error does NOT occur. If the ISAM file FD is set to static and the file status is removed from the select statement, then the error still DOES occur. What changes need to be done to the ISAM file?
class-id BeneScreens.Class1.
Environment division.
select bene-file
assign to "\\data\\bene.dat"
record key is bene-key
organization is Indexed
access mode is dynamic
lock mode is manual
file status is file-status.
select return-file
assign to "c:\\temp\\returnfilebene.wrk"
organization is line sequential.
file section.
fd bene-file.
01 bene-rec.
05 bene-key.
10 bene-nbr pic x(07).
05 bene-relship pic x(25).
fd return-file static.
01 return-rec.
05 rr-pid-number pic x(06).
05 rr-button pic x(10).
working-storage section.
01 file-status pic x(02) property no set.
method-id goPid public static.
procedure division.
open input return-file.
read return-file.
close return-file.
end method.
end class.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLThanks, I can now reproduce the error although I am getting different results.
I get the error whenever there are two files defined and one is static and the other is not.
If I specify them both as static or both as not static then it will work correctly.
I can reproduce with two sequential files so being an ISAM file has nothing to do with it.
I need to raise an RPI for this as it appears to be a bug.
Can you please open up a support incident for this and place my name in the description so that it will be assigned to me?
Thanks.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI just opened up a support incident for this as requested. Thanks for your help.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLI just opened up a support incident for this as requested. Thanks for your help.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLThanks, I created a new RPI for this and attached it to your incident.
I also find that the program will work OK if I change the order of the select statements in the program so that the static file is defined first so perhaps this could be a workaround for now?
select return-file
assign to "c:\\temp\\returnfilebene.wrk"
organization is line sequential.
select bene-file
assign to "\\data\\bene.dat"
record key is bene-key
organization is Indexed
access mode is dynamic
lock mode is manual
file status is file-status.
file section.
fd return-file static.
01 return-rec.
05 rr-pid-number pic x(06).
05 rr-button pic x(10).
fd bene-file.
01 bene-rec.
05 bene-key.
10 bene-nbr pic x(07).
05 bene-relship pic x(25).
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLChris,
I changed the order on the files and received the same results as you did. This will work for us and we will ensure all static methods/files are declared first before any non-static methods/files are.
Thanks for your help.
I am working with winforms and in the file section I have a file that needs to be accessed from a static method. I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field. In order to fix these compile errors I put the keyword static on the FD of the file. When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object.
Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this. How can I resolve this issue? Thanks
#VisualCOBOLAdding this note for the sahe of completeness:
This has been written up as an RPI and the problem has been fixed for inclusion with Visual COBOL 2.2 update 1.
A workaround for the problem is to declare all of your static files first before the declaration of the instance files.