Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all 4356 articles
Browse latest View live

Monitoring a folder

$
0
0

Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed += new FileSystemEventHandler(OnChanged);
        watcher.Created += new FileSystemEventHandler(OnChanged);
        watcher.Deleted += new FileSystemEventHandler(OnChanged);
        watcher.Renamed += new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \'q\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}


RE: COBCH0852 System error - unexpected error while generating IL code

$
0
0

This sounds like a compiler bug. Could you please open up a support incident with Customer Care and attach an example to the incident so we can test this in-house?

What product version are you using?

COBCH0852 System error - unexpected error while generating IL code

$
0
0

I ran into this error as I was defining my file. My file has 1435 fields and I got this error right around the 850 feild. If I use just 849 fields defined it works fine. Once I use the 850 field I get the error. 

Any suggestions on how I can fix this error and continue on.

Thanks

Chris

RE: Listing a Folder's contents

$
0
0

Here is a small program that I wrote that will recursively list all folders, subfolders and files within those folders using native Visual COBOL.

Use and modify as required:

       identification division.
       program-id. testscandir.

       environment division.
       configuration section.

       data division.
       working-storage section.
       01 f-entry.         
          03 f-attribute        pic x(4) comp-5.
          03 f-date-stamp.  
             05 f-year          pic x(4) comp-5.
             05 f-month         pic x(2) comp-5.
             05 f-day           pic x(2) comp-5.
             05 f-hour          pic x(2) comp-5.
             05 f-minute        pic x(2) comp-5.
             05 f-second        pic x(2) comp-5.
             05 f-millisec      pic x(2) comp-5.
             05 f-dst           pic x    comp-5.
             05 f-size          pic x(8) comp-5.
             05 f-name.     
                07 f-max-len    pic x(2) comp-5.
                07 f-entry-name pic x(1024).
       
       01 scan-pattern.
           05 pattern-len       pic x(2) comp-5  value 0.
           05 pattern-text      pic x(256)       value spaces.
       01 scan-attrib           pic x(4) comp-5  value 1.      
       01 scan-flags            pic x(4) comp-5  value 2.
       01 scan-status           pic x(2) comp-5  value 0.
       01 scan-entry.
           05 entry-attrib      pic x(4) comp-5.
           05 entry-date-stamp.
               10 e-year        pic x(2) comp-5.
               10 e-month       pic x(2) comp-5.
               10 e-dow         pic x(2) comp-5.
               10 e-hour        pic x(2) comp-5.
               10 e-minute      pic x(2) comp-5.
               10 e-seconds     pic x(2) comp-5.
               10 e-mill        pic x(2) comp-5.
               10 e-dst         pic x    comp-5.
               10 e-filesize    pic x(8) comp-5.
               10 e-filename.
                  15 e-name-len pic x(2) comp-5.
                  15 e-name-text pic x(1024).
       01 next-pattern          pic x(1024)     value spaces. 
       
       01 sub1                  pic 9(9)        value zeroes.
       01 any-key               pic x.
       local-storage section.             
       01 scan-handle           pointer.
       01 prev-pattern          pic x(1024)     value spaces.
       procedure division.
           display "enter starting dir name; e.g. C:\TEMP"
           accept next-pattern
           move 0 to pattern-len
           move 3 to scan-attrib
           move 2 to scan-flags
           call "do-scan"
           display "complete"
           accept any-key
           goback.
           
        
       entry "do-scan".
           
           move next-pattern to pattern-text
           perform varying sub1 from length of pattern-text by -1 
              until sub1 = 1
              if pattern-text(sub1:1) not = " "
                 move "\*.*" & x"00" to pattern-text(sub1 + 1:)
                 exit perform
              end-if
           end-perform
           
           initialize f-entry
           move length of f-entry-name to f-max-len
           display "folder = " pattern-text(1:70)
           accept any-key
           call "CBL_DIR_SCAN_START" 
              using by reference scan-handle,
                    by reference scan-pattern,
                    by value scan-attrib,
                    by value scan-flags,
              returning scan-status
           end-call
           perform until exit           
              move spaces to f-entry-name
              call "CBL_DIR_SCAN_READ"
                 using  by reference scan-handle
                                     f-entry
                 returning scan-status
              end-call
              if scan-status = 0
                 perform 100-remove-quotes
                 *> Is a folder?       
                 if f-attribute b-and 2 = 2 
                    if f-entry-name not = "." and not = ".."
                       move next-pattern to prev-pattern
                       perform varying sub1 from length of f-entry-name 
                         by -1 until sub1 = 1
                         if next-pattern(sub1:1) not = " "
                            move x"00" to next-pattern(sub1 + 1:)
                            exit perform
                         end-if
                       end-perform
                       string next-pattern delimited by x"00"
                          "\"
                          f-entry-name delimited by size
                          into next-pattern
                       end-string
                       *> recursive call for next folder level
                       call "do-scan"
                       display "return"
                       move prev-pattern to next-pattern
                    else
                      display "folder = " f-entry-name(1:70)
                      accept any-key
                    end-if
                 else
                    display "file = " f-entry-name(1:70)
                    accept any-key
                 end-if
              else
                 call "CBL_DIR_SCAN_END" using scan-handle
                 goback
              end-if
           end-perform.
       
       100-remove-quotes.
                 
           perform varying sub1 from 1 by 1 
              until sub1 = length of f-entry-name - 1
              if f-entry-name(sub1:1) = '"'
                 move f-entry-name(sub1 + 1:) to f-entry-name(sub1:)
              end-if
           end-perform.
                 
       end program testscandir.

RE: COBCH1623 error when attach method

$
0
0

Hi Phil,

What does the method signature for link__CreateReportHeaderArea  look like in COBOL?

COBCH1623 error when attach method

$
0
0

This line of code gives the error "COBCH1623: Anonymous method or method group cannot be cast to type DevExpress.XtraPrinting.CreateAreaEventHander.":

ATTACH METHOD link__CreateReportHeaderArea to link::CreateReportHeaderArea

This is the C# code that I'm converting to Visual COBOL:

      private void btnPrint_Click(object sender, EventArgs e)
        {
            IPrintable component = gridControl1;
            PrintableComponentLinkBase link = new PrintableComponentLinkBase()
            {
                PrintingSystemBase = new PrintingSystemBase(),
                Component = component,
            };
            link.CreateReportHeaderArea += link_CreateReportHeaderArea;

        }
        private void link_CreateReportHeaderArea(object sender,
        CreateAreaEventArgs e)
        {
            string reportHeader = "Categories Report";
            e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
            e.Graph.Font = new Font("Tahoma", 14, FontStyle.Bold);
            RectangleF rec = new RectangleF(0, 0, e.Graph.ClientPageSize.Width, 50);
            e.Graph.DrawString(reportHeader, Color.Black, rec, BorderSide.None);
        }

I don't get the error in C#, just COBOL, and I am not able to subscribe to the CreateReportHeaderArea event.  Any ideas on how to get this working?

RE: COBCH1623 error when attach method

$
0
0

      method-id link_CreateReportHeaderArea final private.

      procedure division using by value sender as object e as type CreateAreaEventArgs.

          goback.

      end method.

Intellisense shows me the error even if I have this method commented out.

RE: COBCH1623 error when attach method

$
0
0

Is it just a typo that you have two consecutive underscores in the name in the ATTACH statement or is that the actual problem?

"link__CreateReportHeaderArea"


RE: COBCH1623 error when attach method

$
0
0

Here is the COBOL code I wrote for subscribing to the event:

   $set ilusing"DevExpress.XtraPrinting"

   $set ilusing"DevExpress.XtraPrinting.Links"

   $set ilusing"DevExpress.XtraPrintingLinks"

                         .

                         .

                         .

    method-id btnPrint_Click final private.

      local-storage section.

        01  link                                       type PrintableComponentLinkBase.

        01  PrintingSystemBase        type PrintingSystemBase.

        01  component                         type IPrintable.

      procedure division using by value sender as object e as type System.EventArgs.

          set component to gridControl1

          set link to new type PrintableComponentLinkBase.

          set PrintingSystemBase to new type PrintingSystemBase.

          set Component to component.

          ATTACH METHOD link__CreateReportHeaderArea to link::CreateReportHeaderArea

      end method.

RE: Monitoring a folder

$
0
0

Here is the COBOL equivalent:

      $set ilusing"System"
      $set ilusing"System.IO"
      $set ilusing"System.Security.Permissions"
       class-id Watcher.Watcher.
       working-storage section.
       method-id Main public static.
       local-storage section.
       procedure division.
           invoke self::Run
           goback.
       end method.

       method-id #Run public static
       attribute PermissionSet(type SecurityAction::Demand, property Name="FullTrust").
       local-storage section.
       01 any-key  pic x value spaces.
       procedure division.
           
           declare args as string occurs any = type System.Environment::GetCommandLineArgs

        *> If a directory is not specified, exit program.
           if args::Length not = 2
            *> Display the proper way to call the program.
              display "Usage: Watcher.exe (directory)"
              goback
           end-if
        
        *> Create a new FileSystemWatcher and set its properties.
           declare watcher as type FileSystemWatcher = new FileSystemWatcher
           set watcher::Path to args[1]
        *> Watch for changes in LastAccess and LastWrite times, and
        *> the renaming of files or directories. 
           set watcher::NotifyFilter to type NotifyFilters::LastAccess b-or type NotifyFilters::LastWrite
           b-or type NotifyFilters::FileName b-or type NotifyFilters::DirectoryName
        *> Only watch text files.
           set watcher::Filter to "*.txt"

        *> Add event handlers.
           attach method OnChanged as type FileSystemEventHandler to watcher::Changed
           attach method OnChanged as type FileSystemEventHandler to watcher::Created
           attach method OnChanged as type FileSystemEventHandler to watcher::Deleted
           attach method OnRenamed as type RenamedEventHandler to watcher::Renamed
        *> Begin watching.
           set watcher::EnableRaisingEvents to true
      
        *> Wait for the user to quit the program.
           display "Press 'q' to quit the sample."
           perform until exit
              accept any-key
              if function upper-case(any-key) = "Q"
                 exit perform
              end-if
           end-perform
      
           exit method
       end method.
       *> Define the event handlers.
       method-id OnChanged private static.
       procedure division using by value #source as object, e as type FileSystemEventArgs.
        *> Specify what is done when a file is changed, created, or deleted.
           display "File: " &  e::FullPath & " " & e::ChangeType
           goback.
       end method.
       method-id OnRenamed private static.
       procedure division using by value #source as object, e as type RenamedEventArgs.
        *> Specify what is done when a file is renamed.
           display "File: " & e::OldFullPath & " renamed to " & e::FullPath
           goback.
       end method.
       end class.

How do I connect Visual COBOL to SQLWizard?

$
0
0

I got MySQL installed, but I think it would be more convenient for me to use the SQL I already got.

RE: How do I connect Visual COBOL to SQLWizard?

$
0
0

I am not quite sure what you are asking for here.

In Visual COBOL you can connect to databases that have an ODBC driver for native code or an ADO.NET provider for .NET managed code or a JDBC connection for managed JVM code by using OpenESQL which is the Visual COBOL embedded SQL preprocessor.

You can also connect to Oracle using Pro*COBOL and COBSQL or DB2 using the DB2 preprocessor and the DB2 ECM.

This is covered in the docs here

What is it exactly that you are trying to do?

Thanks.

RE: Monitoring a folder

$
0
0

Thanks, helped a lot, but if I need to set a folder (directory), as could be done, already much but thank you. Always remembering that the translation is Google

RE: COBCH1623 error when attach method

$
0
0

I did have an extra underscore in my code but after removing it I still get the COBCH1623 error.

RE: Error 26

$
0
0

Hello Tye Huggins,

Someone will reach out to you by email from Micro Focus Customer Care to help resolve your issue.


Error 26

$
0
0

I was trying to test out some code in regards to the date in Visual Studio Cobol and I temporarily changed my system date on my computer. Now when I try to start VS I get "Unable to obtain the requested license Error 26: Request denied due to clock tamper detection". Is there anything I can do to fix this problem? The email I used to activate VS Cobol is tye_huggins@stu.indianhills.edu. Thanks for any help.

RE: Monitoring a folder

$
0
0

     declare watcher as type FileSystemWatcher = new FileSystemWatcher("C:\temp", "*.txt")

I could do with that came a fixed folder, but can not convert to windows form you could help me, thank you.  

RE: Monitoring a folder

$
0
0

I think you would have to set those properties in the constructor as follows::

declare watcher as type FileSystemWatcher = new FileSystemWatcher(property Path="C:\temp", property Filter="*.txt")

RE: COBCH1623 error when attach method

$
0
0

Please open up a support incident with Customer Care for this as we will most likely require a cutdown example.

Thanks.

RE: Monitoring a folder

$
0
0

Thanks, tried to convert to form windows but I can not.

Viewing all 4356 articles
Browse latest View live