Results 1 to 6 of 6

Thread: [RESOLVED] [2005] When 2 types equal

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Resolved [RESOLVED] [2005] When 2 types equal

    I converted the C# code for the ICSharp Zip Library to VB.NET for unzipping and when I converted:

    C#:
    C# Code:
    1. while ((objEntry = s.GetNextEntry()) != null) {}

    to

    VB.NET
    VB Code:
    1. While Not ((objEntry = s.GetNextEntry) Is Nothing)
    2. End While

    It throws an error at objEntry = s.GetNextEntry saying:

    Operator '=' is not defined for types 'ICSharpCode.SharpZipLib.Zip.ZipEntry' and 'ICSharpCode.SharpZipLib.Zip.ZipEntry'

    The C# code works perfect, any solutions?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] When 2 types equal

    I think you need to rewrite it like this:


    VB Code:
    1. objEntry = s.GetNextEntry
    2.       While Not objEntry Is Nothing
    3.           'Do stuff...
    4.           objEntry = s.GetNextEntry
    5.       End While
    EDIT: haha pressed the URL button instead of the code button
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] When 2 types equal

    Ok so that worked, but I noticed that if I have a sub folder in the zip, like:

    \Root
    ..\Data
    ....\file2.txt
    ....\file3.txt
    ..\file1.txt

    It will create the Data folder and file2 and 3 but not file1.

    Converted Code:
    VB Code:
    1. Using s As ZipInputStream = New ZipInputStream(File.OpenRead(ImportPublisher_Path.Text))
    2.             Dim objEntry As ZipEntry
    3.             objEntry = s.GetNextEntry
    4.             While Not objEntry Is Nothing
    5.                 objEntry = s.GetNextEntry
    6.                 Dim directoryName As String = Path.GetDirectoryName(objEntry.Name)
    7.                 Dim fileName As String = Path.GetFileName(objEntry.Name)
    8.                 If directoryName.Length > 0 Then
    9.                     Directory.CreateDirectory(directoryName)
    10.                 End If
    11.                 If Not (fileName = String.Empty) Then
    12.                     Using streamWriter As FileStream = File.Create(objEntry.Name)
    13.                         Dim size As Integer = 2048
    14.                         Dim data As Byte() = New Byte(2048) {}
    15.                         While True
    16.                             size = s.Read(data, 0, data.Length)
    17.                             If size > 0 Then
    18.                                 streamWriter.Write(data, 0, size)
    19.                             Else
    20.                                 Exit While
    21.                             End If
    22.                         End While
    23.  
    24.                     End Using
    25.                 End If
    26.             End While
    27.  
    28.         End Using

    Orginal C# code:
    C# Code:
    1. using (ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {
    2.        
    3.             ZipEntry theEntry;
    4.             while ((theEntry = s.GetNextEntry()) != null) {
    5.                
    6.                 Console.WriteLine(theEntry.Name);
    7.                
    8.                 string directoryName = Path.GetDirectoryName(theEntry.Name);
    9.                 string fileName      = Path.GetFileName(theEntry.Name);
    10.                
    11.                 // create directory
    12.                 if ( directoryName.Length > 0 ) {
    13.                     Directory.CreateDirectory(directoryName);
    14.                 }
    15.                
    16.                 if (fileName != String.Empty) {
    17.                     using (FileStream streamWriter = File.Create(theEntry.Name)) {
    18.                    
    19.                         int size = 2048;
    20.                         byte[] data = new byte[2048];
    21.                         while (true) {
    22.                             size = s.Read(data, 0, data.Length);
    23.                             if (size > 0) {
    24.                                 streamWriter.Write(data, 0, size);
    25.                             } else {
    26.                                 break;
    27.                             }
    28.                         }
    29.                     }
    30.                 }
    31.             }
    32.         }

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] When 2 types equal

    The reason that that is legal in C# is because in C-based languages an assignment statement has a return value. All assignments return the value that was assigned. In VB assignments do NOT return a value, so you must do as Atheist says and perform two steps. You have to perform the assignment first, then test the value of the variable that was assigned to.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] When 2 types equal

    Yeah if you look at my previous post again, you see that I have commented the code with "Do stuff", and after that I have the objEntry = s.GetNextEntry line.
    Thats how you need to do aswell, inside this while-loop, the objEntry = s.GetNextEntry line has to be the last line and not the first, or else it will skip the first "Entry" that is returned by the GetNextEntry function.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] When 2 types equal

    Ok, that worked perfect, thanks alot guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width