|
-
Apr 15th, 2007, 08:21 PM
#1
Thread Starter
Hyperactive Member
[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:
while ((objEntry = s.GetNextEntry()) != null) {}
to
VB.NET
VB Code:
While Not ((objEntry = s.GetNextEntry) Is Nothing)
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?
-
Apr 15th, 2007, 08:23 PM
#2
Re: [2005] When 2 types equal
I think you need to rewrite it like this:
VB Code:
objEntry = s.GetNextEntry
While Not objEntry Is Nothing
'Do stuff...
objEntry = s.GetNextEntry
End While
EDIT: haha pressed the URL button instead of the code button
-
Apr 15th, 2007, 08:40 PM
#3
Thread Starter
Hyperactive Member
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:
Using s As ZipInputStream = New ZipInputStream(File.OpenRead(ImportPublisher_Path.Text))
Dim objEntry As ZipEntry
objEntry = s.GetNextEntry
While Not objEntry Is Nothing
objEntry = s.GetNextEntry
Dim directoryName As String = Path.GetDirectoryName(objEntry.Name)
Dim fileName As String = Path.GetFileName(objEntry.Name)
If directoryName.Length > 0 Then
Directory.CreateDirectory(directoryName)
End If
If Not (fileName = String.Empty) Then
Using streamWriter As FileStream = File.Create(objEntry.Name)
Dim size As Integer = 2048
Dim data As Byte() = New Byte(2048) {}
While True
size = s.Read(data, 0, data.Length)
If size > 0 Then
streamWriter.Write(data, 0, size)
Else
Exit While
End If
End While
End Using
End If
End While
End Using
Orginal C# code:
C# Code:
using (ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null) {
Console.WriteLine(theEntry.Name);
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if ( directoryName.Length > 0 ) {
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty) {
using (FileStream streamWriter = File.Create(theEntry.Name)) {
int size = 2048;
byte[] data = new byte[2048];
while (true) {
size = s.Read(data, 0, data.Length);
if (size > 0) {
streamWriter.Write(data, 0, size);
} else {
break;
}
}
}
}
}
}
-
Apr 15th, 2007, 08:42 PM
#4
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.
-
Apr 15th, 2007, 08:43 PM
#5
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.
-
Apr 15th, 2007, 08:53 PM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|