VB.net ws Visiual COBOL

[Migrated content. Thread originally posted on 11 June 2012]

Hi all
let's compare VB.net codes with Visual COBOL(managed or not) codes.
Anyone to convert VB.net codes (below)?

Thanks in advance.


Imports System
Imports System.Text
Imports System.IO
Imports System.Net.Mail

Module Module1
Dim mail As System.Net.Mail.MailMessage
Dim wshost As String = Nothing
Dim wsport As String = Nothing
Dim wssender As String = Nothing
Dim wspassword As String = Nothing
Dim wsrecipient As String = Nothing
Dim wssubject As String = Nothing
Dim wsbody As String = Nothing
Dim wsfile As String = Nothing
Dim wiport As Integer
Dim StreamEncoding As Encoding
Dim txtline As String = Nothing
Dim txtline2() As String = Nothing
Dim flag As Integer

Public Sub Main()
'Before read and write getting encode (for Turkish)
StreamEncoding = System.Text.Encoding.GetEncoding("iso-8859-9")
Dim fs1 As FileStream
fs1 = New FileStream("C:\inform.txt", FileMode.Open, FileAccess.Read)
Dim freader As New IO.StreamReader(fs1, StreamEncoding)

'Write exceptions information to the file
Dim fs2 As FileStream
fs2 = New FileStream("C:\result.txt", FileMode.Create, FileAccess.Write)
Dim fwriter As New IO.StreamWriter(fs2, StreamEncoding)

Do Until freader.EndOfStream()

'Reading file (txt) line by line and truncating

txtline = freader.ReadLine
If txtline = "" Then Exit Do
txtline2 = txtline.Split("»")
wshost = txtline2(0)
wsport = txtline2(1)
wssender = txtline2(2)
wspassword = txtline2(3)
wsrecipient = txtline2(4)
wssubject = txtline2(5)
wsbody = txtline2(6)
wsfile = txtline2(7)
wiport = CInt(wsport)
Dim Mail As New MailMessage
Mail.From = New MailAddress(wssender)
Mail.To.Add(wsrecipient)
Mail.Subject = wssubject
Mail.IsBodyHtml = True
Mail.Body = wsbody
Dim smtp As New SmtpClient(wshost)
smtp.EnableSsl = True
smtp.Port = wiport
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential(wssender, wspassword)
If Not wsfile.Equals(String.Empty) Then
Mail.Attachments.Add(New Attachment(wsfile))
End If
Try
smtp.Send(Mail)
fwriter.WriteLine("1" & wsrecipient)

Catch ex As Net.Mail.SmtpException
fwriter.WriteLine("0" & wsrecipient)

End Try
Mail.Dispose()
'Disposing
Loop
freader.Close()
fs1.Close()
fwriter.Close()
fs2.Close()

End Sub
End Module
  • this instance multiple email sender, has 2 files information and result;
    inform.txt -> informations about sender, smtp address, port and recipent
    result.txt -> informations about successful, and unsuccessful operations.

    dot.net provides comfort and easy control for programmers like this instance
    let's see and understand, how Visiual COBOL support dot.net
  • Verified Answer

    Visual COBOL provides for full access to the .NET Framework classes just like you have in VB or in C#.
    In fact, the syntax looks very similar as can be seen below.

    This example was created using Visual COBOL 2.0 and demonstrates the new feature of allowing local variables to be defined in the procedure division using the DECLARE statement or directly in a PERFORM or CATCH statement.


          $set ilusing"System"
          $set ilusing"System.Text"
          $set ilusing"System.IO"
          $set ilusing"System.Net.Mail"
           program-id. Program1 as "testemail.Program1".
           data division.
           working-storage section.
           01 mail type System.Net.Mail.MailMessage.
           01 wshost string value "".
           01 wsport string value "".
           01 wssender string value "".
           01 wspassword string value "".
           01 wsrecipient string value "".
           01 wssubject string value "".
           01 wsbody string value "".
           01 wsfile string value "".
           01 wiport binary-long.
           01 StreamEncoding type Encoding.
           01 txtline string value "".
           01 txtline2 string occurs any.
           01 flag binary-long.
           procedure division.

            *>Before read and write getting encode (for Turkish)
               set StreamEncoding to type System.Text.Encoding::GetEncoding("iso-8859-9")
               declare fs1 as type FileStream = new FileStream("C:\inform.txt", type FileMode::Open, type FileAccess::Read)
               declare freader as type StreamReader = new StreamReader(fs1, StreamEncoding)
               
            *>Write exceptions information to the file
               declare fs2 as type FileStream = new type FileStream("C:\result.txt", type FileMode::Create, type FileAccess::Write)
               declare fwriter as type StreamWriter = new type StreamWriter(fs2, StreamEncoding)
           
               perform until freader::EndOfStream
            *>Reading file (txt) line by line and truncating
                  set txtline to freader::ReadLine
                  if txtline = ""
                     exit perform
                  end-if   
                  set txtline2 to txtline::Split("»")
                  set wshost to txtline2[0]
                  set wsport to txtline2[1]
                  set wssender to txtline2[2]
                  set wspassword to txtline2[3]
                  set wsrecipient to txtline2[4]
                  set wssubject to txtline2[5]
                  set wsbody to txtline2[6]
                  set wsfile to txtline2[7]
                  set wiport to type System.Convert::ToInt32(wsport)
                  set mail to new MailMessage
                  set mail::From to new MailAddress(wssender)
                  invoke mail::To::Add(wsrecipient)
                  set mail::Subject to wssubject
                  set mail::IsBodyHtml to True
                  set mail::Body to wsbody
                  declare smtp as type SmtpClient = new SmtpClient(wshost)
                  set smtp::EnableSsl to True
                  set smtp::Port to wiport
                  set smtp::UseDefaultCredentials to False
                  set smtp::Credentials to new type System.Net.NetworkCredential(wssender, wspassword)
                  if not wsfile::Equals(type String::Empty)
                     invoke mail::Attachments::Add(New Attachment(wsfile))
                  end-if
                  try
                    invoke smtp::Send(Mail)
                    invoke fwriter::WriteLine("1" & wsrecipient)
                  catch ex as type SmtpException
                    invoke fwriter::WriteLine("0" & wsrecipient)
                  end-try
                  invoke mail::Dispose
               end-perform
               *>Disposing
               invoke freader::Close
               invoke fs1::Close
               invoke fwriter::Close
               invoke fs2::Close
               goback.
               
           end program Program1.
  • Congratulations.
    I can say only one word that "excellent".
    Cobol programmer were always 3-4 steps beyond of other languages
    that's why this situation forced us to learn other languages.
    Cobol programmers have expriences about real life conditions,
    Visual COBOL and expriences of cobol programmers are going to be strong combination.
    Now it's time know, where do we start to learn....
    in my mind, steps are ;
    - prepare table of cobol data type and .net data type(and others)

    cobol dot.net(MSIL objects) java
    -------- --------------------- -------

    - sequences of bits in byte (for 32 and 64 bits)

    - many examples of Visual COBOL
    * grid manuplate(navigation)
    * sql samples
    * GUI technics....
    ans so on and on..