
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello to all!
I want to fill a listbox from a .dat file but I am stuck!!!
method-id ShowListBox public.
local-storage section.
01 listItem string.
procedure division.
open input pinakes.
read pinakes invalid key invoke type MessageBox::Show("ERROR!!!").
invoke listBox1::BeginUpdate.
set listItem to kwd2.
invoke listBox1::Items::Add(listItem).
invoke listBox1::EndUpdate.
close pinakes.
end method.
What Am I doing wrong...?
PS. I am totally noob in Cobol programming!!!!
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I am glad that you found a solution. Since you are new to COBOL programming, I would like to make a suggestion and that is to never use a go to statement in your code. There are structured programming constructs that have been in place for a long time now that allow for alternatives to this potential spaghetti code creator. Periods at the end of statements are also a source of errors. Use the scope terminators like end-if and end-perform where possible. The only place you really need a period in the procedure division is after a section or paragraph name and after the last statement in a section or paragraph.
For instance you could rewrite your code as something like the following:
method-id ShowComboBox public. local-storage section. 01 listItem string. procedure division. open input pinakes move spaces to pin0 start pinakes key is greater than pin0 invalid key invoke type MessageBox::Show("ERROR Den arxise") exit method end-start perform until exit read pinakes next at end close pinakes exit perform not at end invoke comboBox1::BeginUpdate set listItem to perstix invoke comboBox1::Items::Add(listItem) invoke comboBox1::EndUpdate end-read end-perform end method.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Your example looks correct to me. Is this a Windows Forms application or something else? (WPF, ASP.NET?)
You can also just bind a list to the listbox control so you don't have to populate it directly but you can certainly do it the way that you show here.
The following simple demo works for me so when I click a button the listbox will be populated with the records in the text file. If you have non-text data like COMP, COMP-3 etc. then you will need to convert it first.
class-id popListbox.Form1 is partial inherits type System.Windows.Forms.Form. select myfile assign to "listdata.dat" organization is line sequential file status is file-status. fd myfile. 01 myrecord. 05 mynum pic 9(3). 05 myname pic x(10). working-storage section. 01 file-status pic x(2). method-id NEW. procedure division. invoke self::InitializeComponent goback. end method. method-id button1_Click final private. procedure division using by value sender as object e as type System.EventArgs. open input myfile invoke listBox1::BeginUpdate perform until exit read myfile at end exit perform not at end invoke listBox1::Items::Add(myrecord)
end-read end-perform invoke listBox1::EndUpdate close myfile end method. end class.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thank you for the response. I found a solution. Here is my code:
method-id ShowComboBox public.
local-storage section.
01 listItem string.
01 flag pic x value "n".
procedure division.
open input pinakes.
move spaces to pin0.
perform aaaa until flag = "y".
start pinakes key is greater than pin0 invalid key invoke type MessageBox::Show("ERROR Den arxise").
aaaa.
read pinakes next at end go to rrrr
move "y" to flag.
invoke comboBox1::BeginUpdate.
set listItem to perstix.
invoke comboBox1::Items::Add(listItem).
invoke comboBox1::EndUpdate.
rrrr.
close pinakes.
end method.
I'm totaly new to cobol programming so I will have plenty of questions...! haha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I am glad that you found a solution. Since you are new to COBOL programming, I would like to make a suggestion and that is to never use a go to statement in your code. There are structured programming constructs that have been in place for a long time now that allow for alternatives to this potential spaghetti code creator. Periods at the end of statements are also a source of errors. Use the scope terminators like end-if and end-perform where possible. The only place you really need a period in the procedure division is after a section or paragraph name and after the last statement in a section or paragraph.
For instance you could rewrite your code as something like the following:
method-id ShowComboBox public. local-storage section. 01 listItem string. procedure division. open input pinakes move spaces to pin0 start pinakes key is greater than pin0 invalid key invoke type MessageBox::Show("ERROR Den arxise") exit method end-start perform until exit read pinakes next at end close pinakes exit perform not at end invoke comboBox1::BeginUpdate set listItem to perstix invoke comboBox1::Items::Add(listItem) invoke comboBox1::EndUpdate end-read end-perform end method.