Solved

Converting C sharp to Vb.Net

Posted on 2004-10-26
315 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
Question by:timmyzx7r
    2 Comments
     
    LVL 85

    Accepted Solution

    by:
    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
    Thanks,  I found this site but it did not work correclty.

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    Suggested Solutions

    Title # Comments Views Activity
    Datatable processing strangely slow 2 22
    prevent lose focus 6 38
    Wordmerge 8 16
    Richtextbox formatting 8 4
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    856 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now