Skip to main content

Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

Hello,

The equivalent of the C# "Using" statement in Visual COBOL would be $set ilusing

Example:

      $set ilusing "System.Data"

Regards,


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

No, as I pointed out in the above, I am looking for the equivalent of the Using statement, not the Using directive.


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

Sorry about that!

As you already know, "using" has always been a reserved word in Cobol, and I read from MSDN here that "The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object. You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block; in fact, this is how the using statement is translated by the compiler. "

In Visual COBOL, you will then need to use the Try...Finally construction.


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

Below is an example:

          perform using cn as type SqlConnection = new SqlConnection(connectString)          

              set cmd to cn::CreateCommand()

              set cmd::CommandText to "select * from dbo.evantb"

              invoke cn::Open()

              perform using rdr as type SqlDataReader = cmd::ExecuteReader()

                  invoke rdr::Read()

                  display rdr["EMPNAME"]::ToString()

              end-perform

           end-perform  


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

@MF_Fano - OK, well, as to there being no exact equivalent to the C# "using" statement, that confirms my suspicion, and I guess I can see why (there is already a using reserved word in COBOL, used for another purpose).

Now on to the 2nd question at the end of my original post...

@evank - How do these performs exit their loops?  I see no tests for exiting the loops.


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

This perform is not a loop. It is the equivalent of the C# or VB using block.


Hello all,

Is there a Visual COBOL equivalent to the C# "Using" statement?

... as shown In the following C# example, the "Using" statement (not the "Using" directive)... (as in the statement that says "Using (OleDbConnection..." ?

.................................................................

using System;

using System.Data;

using System.Data.OleDb;

class Program

{

    static void Main()

    {

        // The connection string assumes that the Access

        // Northwind.mdb is located in the c:\\Data folder.

        // string connectionString =

        // "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        // "c:\\\\Data\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Austin1\\Documents\\Northwind.mdb

        string connectionString =

        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

        "c:\\\\Users\\\\Austin1\\\\Documents\\\\Northwind.mdb;User Id=admin;Password=;";

        // Provide the query string with a parameter placeholder.

        string queryString =

            "SELECT ProductID, UnitPrice, ProductName from products "

                "WHERE UnitPrice > ? "

                "ORDER BY UnitPrice DESC;";

        // Specify the parameter value.

        int paramValue = 10;

        // Create and open the connection in a using block. This

        // ensures that all resources will be closed and disposed

        // when the code exits.

        using (OleDbConnection connection =

            new OleDbConnection(connectionString))

        {

            // Create the Command and Parameter objects.

            OleDbCommand command = new OleDbCommand(queryString, connection);

            command.Parameters.AddWithValue("@pricePoint", paramValue);

            // Open the connection in a try/catch block.

            // Create and execute the DataReader, writing the result

            // set to the console window.

            try

            {

                connection.Open();

                OleDbDataReader reader = command.ExecuteReader();

                while (reader.Read())

                {

                    Console.WriteLine("\\t{0}\\t{1}\\t{2}",

                        reader[0], reader[1], reader[2]);

                }

                reader.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

         }

    }

}

.................................

And would anyone like to convert all of the above to Visual COBOL and post the Visual COBOL equivalent? :-)

 

So, there really IS an equivalent!  I will work with the code you provided to prove it to myself.  Thanks!