?
Solved

Converting C sharp to Vb.Net

Posted on 2004-10-26
2
Medium Priority
?
342 Views
Last Modified: 2007-12-19
I am mainly confussed with the *****'s if some one could please convert and explain the marked parts please?

The int part in **1**
The buffer in **2**
The encbuffer in **3**
The buffer2 in **4**

Thanks in advanced.

-Tim

private void Encrypt()
            {
                  try
                  {
                        GoToBusyMode();
                        progressBar.Minimum=0;
                        System.IO.FileInfo finfo=new System.IO.FileInfo(inFile);
**1**                        progressBar.Maximum=(int)(finfo.Length/32);
                        lblStatus.Text="Encrypting...";

                        System.IO.FileStream fout=System.IO.File.Open(outFile,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.Write);
                        System.IO.FileStream fin=System.IO.File.Open(inFile,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
**2**                        byte []buffer=new byte[32];
**3**                        byte []encbuffer=new byte[32];
                        int c=0;
*****                        while((c=fin.Read(buffer,0,32))>0)
*****                        {
*****                              if(c!=buffer.Length)
*****                              {
*****                                    byte[]buffer2=new byte[c];
*****                                    for(int i=0;i<c;i++)
**4**                                          buffer2[i]=buffer[i];
*****                                    encbuffer=rsa.Encrypt(buffer2,false);
*****                                    fout.Write(encbuffer,0,encbuffer.Length);
*****                              }
*****                              else
*****                              {
*****                                    encbuffer=rsa.Encrypt(buffer,false);
*****                                    fout.Write(encbuffer,0,encbuffer.Length);
*****                              }
                              progressBar.Increment(1);
                        }
                        fin.Close();
                        fout.Close();
                        lblStatus.Text="Encryption successful";
                        GoToReadyMode();
                  }
                  catch(Exception ex)
                  {
                        MessageBox.Show("Error:"+ex.Message);
                        thread.Abort();
                        GoToReadyMode();
                  }
            }
0
Comment
Question by:timmyzx7r
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 12412936
This is the result of passing the code through the utility at:
http://www.developerfusion.com/utilities/convertcsharptovb.aspx

Private Sub Encrypt()
 Try
   GoToBusyMode()
   progressBar.Minimum = 0
   Dim finfo As System.IO.FileInfo = New System.IO.FileInfo (inFile)
   progressBar.Maximum = CType((finfo.Length / 32), Integer)
   lblStatus.Text = "Encrypting..."
   Dim fout As System.IO.FileStream = System.IO.File.Open(outFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write)
   Dim fin As System.IO.FileStream = System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
   Dim buffer(32) As Byte
   Dim encbuffer(32) As Byte
   Dim c As Integer = 0
   While (c = fin.Read(buffer, 0, 32)) > 0
     If Not (c = buffer.Length) Then
       Dim buffer2(c) As Byte
       Dim i As Integer = 0
       While i < c
         buffer2(i) = buffer(i)
         i += 1
       End While
       encbuffer = rsa.Encrypt(buffer2, False)
       fout.Write(encbuffer, 0, encbuffer.Length)
     Else
       encbuffer = rsa.Encrypt(buffer, False)
       fout.Write(encbuffer, 0, encbuffer.Length)
     End If
     progressBar.Increment(1)
   End While
   fin.Close()
   fout.Close()
   lblStatus.Text = "Encryption successful"
   GoToReadyMode()
 Catch ex As Exception
   MessageBox.Show("Error:" + ex.Message)
   thread.Abort()
   GoToReadyMode()
 End Try
End Sub
0
 

Author Comment

by:timmyzx7r
ID: 12412991
Thanks,  I found this site but it did not work correclty.

http://www.kamalpatel.net/ConvertCSharp2VB.aspx
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question