[Migrated content. Thread originally posted on 11 June 2012]
Hi alllet'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