Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Saturday, March 31, 2012

Trim array of null object

How to remove null objects from an array? When I use the split function, I end up having an empty first element. How do I remove this? Any code is welcome...
ArrayList alArray = new ArrayList();

for ( int i = 0; i < myArray.Length; ++i )
{
if ( myArray[i] != null )
alArray.Add(myArray[i]);
}


Or maybe, if you want to remove null value objects:

for ( int i = 0; i < myArrayList.Length; i++ )
{
if (myArrayList[i] == null )
myArrayList.RemoveAt[i]);
}

The ArrayList is in many ways extremely practical, as you don't have to redim the size. You just simply remove the unwanted elements.

Trim function in VB.NET

Hey,

In my code the value of strWebService is initially "2 " (that is the number two followed by a space). I then use trim to eliminate the space:


strWebService = readHtmlPage(strTMQuery)
strWebService = Trim(strWebService)

I then run strWebService through a SELECT statement and it always defaults to ELSE:

Select Case strWebService
Case "0"
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case "1"
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case "2"
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select

What am I doing wrong?

MikeHello -

Perhaps you might want to do a conversion to an integer for the case statement?

good luck

take care
tony
I added the following line before my select statement:

Dim intWebService As Integer = CInt(strWebService)

I then removed the double quotes from my case expressions and ran the code but still got the ELSE statement. VB doesn't require BREAK does it?
did you trying doing a response.Write(intWebService) right before the case statement so you can verify the value?


response.write("service =" & strWebService & ".")

Take note of the spaces and period. Should be
service =2.
My code now reads like this (I added the = signs to the label just to make sure the TRIM did its job...)


strWebService = readHtmlPage(strTMQuery)
strWebService = RTrim(strWebService)
Dim intWebService As Integer = CInt(strWebService)

lblTest.Text = "=" & intWebService.ToString & "="
lblTest.Visible = True

Select Case strWebService
Case 0
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case 1
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case 2
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select

I still get the ELSE... Plus, my label does infact read 2... I don't get what I could be doing wrong...
Your select Statement is still referring to strWebService... Change it to intWebService...
Ha ha, good call. It works. Thanks guys. Strings in SELECT CASE statements SUCK!

trim function

does anyone knows what does Trim(!Delete & "") means? what is this Delete ?
thanks
Regards
GohIs it a boolean or some string variable declared elsewhere in your code?
Apparently this isn't an ASP.NET question, the 'original' post is here:

http://www.vbforums.com/showthread.php?p=2067378#post2067378

trim large text

Hi! I have a function that trim large text, but the problem is that it cuts off the last word, so it's not making sense. Is there a function that trim large text in a nice way, making sure the last word is preserved. Thanks for any tip!

Can you just use Trim(myString) ?


You could also use Regular expressions :

using System.Text.RegularExpressions;

private string RemoveSpaces(string str)
{
string result = "";
Regex regulEx = new Regex(@."[\s]+");
result = regulEx.Replace(str," ");
return result;
}

Original code :Laxshmi

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--



I probably didn't explain what I am doing. If I have a large text to pull from the database and I 'd like just a small portion to be displayed in gridview cell, I am uisng:

Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) but this cuts off any last words.


Thank you for the reply! I am looking to shorten text (pulled out of the database)for display in gridview.

Cheers!


:)

Here you go. Even though this is asp code, you will get the idea

http://www.codeproject.com/asp/textpreview.asp

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


James,

if I understand you right then you're saying that you want the last word within the 100 character max limit to be preserved and to not be chopped in two, right? Here's a bit of code that might accomplish it for you if that is what you're looking for. It just involves string manipulations is all.

string myStr ="This string should be cut off at the 25th character, and preserve the final word.";string myStr25 = myStr.Substring(0, 25);int lastIdx = myStr25.LastIndexOf(" ");string finalStr = myStr25.Substring(0, lastIdx);

Let me know if you need help from there, but you should be able to adapt it to your need.


If you don't want to cut off words, just trim to the last index of a space.

string text = Eval("Bulletin").ToString();

if (text.Length > 100)

{

text = text.Substring(0, 100);

text = text.Substring(0, text.LastIndexOf(' ') + 1);

}


or how about trying this :

<ItemTemplate>
<%# Eval("Bulletin").ToString().Substring(0, 20) + "..." %>
</ItemTemplate>

Just make sure that all the strings are above 20 characters.

Edit : This code would probably cut off the last words. I do not have my visual studio with me, but what you can do is use this code with the suggestion posted by other members to get your solution.

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


I did this but it gave me 95 instead of my text:

<%# Eval("Bulletin").ToString().Substring(0,100).LastIndexOf(" ")%>

I am doing it in the aspx, makes it harder for me.


This is my datalist:

<asp:DataListID="dlBulletins"runat="server">

<ItemTemplate>

<strong><%# Eval("DisplayName")%></strong>

<br/>

<%#formatDate((DateTime)Eval("Bulletin_Date"))%><br/>

<%# Eval("Bulletin").ToString().Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) %>

</ItemTemplate>

How can I use the string text in datalist template?

Cheers!

<separatorTemplate><hrnoshade="noshade"size="1"/>

</separatorTemplate>

</asp:DataList></p>


I am using this but it's only returning the first letter!!

<%# Eval("Bulletin").ToString().Substring(0,100).Substring(0,Eval("Bulletin").ToString().LastIndexOf(' ')) %>


It sounds like it's impossible to do this in the datalist!


Thanks friend!! I don't know what i was thinking, I made a function in the code behind called trimtext, then used it in the aspx. Work great now!

Cheers!

Trimming Blank Spaces in String

You can use the VB.NET function RTRIM.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Temp" <tempmail@dotnet.itags.org.temp.com> wrote in message
news:bh1eg5$o2h@dotnet.itags.org.library2.airnews.net...
> I am trying to remove the blank spaces at the end of a string with the
> .Trim() function. Unfortunately, this removes ALL spaces, not just the
ones
> at the end. I need to preserve the spacing inside the string.
> Does anyone know how I can do this?
> Thanks,
> Ron
> --
> _____________________________
> Ron Rodenberg
> Lead Software Engineer
> Razorvision Technology, Inc.
> (214) 207-1688Do you know of a C# equivalent?

--
_____________________________
Ron Rodenberg
Lead Software Engineer
Razorvision Technology, Inc.
(214) 207-1688
"Steve C. Orr, MCSD" <Steve@.Orr.net> wrote in message
news:%23Qab%23wgXDHA.2392@.TK2MSFTNGP10.phx.gbl...
> You can use the VB.NET function RTRIM.
> --
> I hope this helps,
> Steve C. Orr, MCSD
> http://Steve.Orr.net
>
> "Temp" <tempmail@.temp.com> wrote in message
> news:bh1eg5$o2h@.library2.airnews.net...
> > I am trying to remove the blank spaces at the end of a string with the
> > .Trim() function. Unfortunately, this removes ALL spaces, not just the
> ones
> > at the end. I need to preserve the spacing inside the string.
> > Does anyone know how I can do this?
> > Thanks,
> > Ron
> > --
> > _____________________________
> > Ron Rodenberg
> > Lead Software Engineer
> > Razorvision Technology, Inc.
> > (214) 207-1688

Monday, March 26, 2012

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:

*PSEUDOCODE*

for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE

It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.

Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.

Specifically, what I try to do is store the TextBoxes for comparison
in an array:

Dim ControlName As String' temporary

ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)

' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
...

(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.

Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.

I just thought of a less repetitive algorithm.

Provided I can dynamically obtain the index of the current row:

*PSEUDOCODE*

for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE

Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE

...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
>Dim aObjFirst(2) As TextBox
> Dim ControlName As String' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.

I have a DataGrid containing a TextBox control and a CustomValidator in
each row.

The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.

The algorithm is pretty straightforward:

*PSEUDOCODE*

senderIndex = the row in the DataGrid of the sender

FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE

However, I'm stuck in my attempts to formally code this algorithm:

*CODE*

Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False

For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToV alidate)

If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub

I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.

(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._

--E.)

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum

'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender

'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent

'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent

'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE
It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.
Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.
Specifically, what I try to do is store the TextBoxes for comparison
in an array:
Dim ControlName As String ' temporary
ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)
' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
..
(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.
Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.
I just thought of a less repetitive algorithm.
Provided I can dynamically obtain the index of the current row:
*PSEUDOCODE*
for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE
Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE
>
...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
> Dim aObjFirst(2) As TextBox
> Dim ControlName As String ' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.
I have a DataGrid containing a TextBox control and a CustomValidator in
each row.
The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.
The algorithm is pretty straightforward:
*PSEUDOCODE*
senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE
However, I'm stuck in my attempts to formally code this algorithm:
*CODE*
Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False
For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToValidate)
If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.
(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._
--E.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Thursday, March 22, 2012

trouble with read method in oledbdatareader object

Public Function GetNextCounter(ByVal QueuePath As String) As Integer
Dim ObjConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & QueuePath)
Dim intGetNextCounter as integer
Dim rdr as OleDbDataReader
Dim ObjCmd as new OleDbCommand("Select * FROM tblReportQueue_ID", ObjConn)

ObjConn.Open()
If rdr.Read then
rdr = ObjCmd.ExecuteReader()
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if
ObjConn.close()

GetNextCounter = intGetNextCounter
End Function

When I compile the page that this function is in, I get an error message saying "Object reference not set to an instance of an object." The error occurs on the line

If rdr.Read then

Can anyone give me a hand as to what went wrong? ThanksMove


rdr = ObjCmd.ExecuteReader()

Before you read rdr
i.e

rdr = ObjCmd.ExecuteReader()
If rdr.Read then
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if

Tuesday, March 13, 2012

Trouble with translating C# into VB.NET code

Hello, I'm trying to implement a function to create zip files in my application. I am using the following articlehttp://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx
which describes how to perform zipping with C#.
My application is in VB.NET so I am trying to translate a class thatperforms the zipping into VB code. I have managed to translate theclass except for two lines. The original C# code is as follows. Mytranslated VB code with errors in emphasized red color can be found just beneath the C#code.The error message I get for the two lines are:
"c:\inetpub\wwwroot\TestApplication\Zip.vb(81):'TestApplication.VbZip.EnumerationMethod' is a delegate type. Delegateconstruction permits only a single AddressOf expression as an argumentlist. Often an AddressOf expression can be used instead of a delegateconstruction.".
Can anyone help me translating these two lines?

using System;
using System.Collections;
using java.util;
using java.util.zip;
namespace CsZip
{
public delegate Enumeration EnumerationMethod();
/// <summary>
/// Wraps java enumerators
/// </summary>
public class EnumerationAdapter : IEnumerable
{
private class EnumerationWrapper : IEnumerator
{
private EnumerationMethod m_Method;
private Enumeration m_Wrapped;
private object m_Current;
public EnumerationWrapper(EnumerationMethod method)
{
m_Method = method;
}
// IEnumerator
public object Current
{
get { return m_Current; }
}
public void Reset()
{
m_Wrapped = m_Method();
if (m_Wrapped == null)
throw newInvalidOperationException();
}
public bool MoveNext()
{
if (m_Wrapped == null)
Reset();
bool Result = m_Wrapped.hasMoreElements();
if (Result)
m_Current = m_Wrapped.nextElement();
return Result;
}
}
private EnumerationMethod m_Method;
public EnumerationAdapter(EnumerationMethod method)
{
if (method == null)
throw new ArgumentException();
m_Method = method;
}
// IEnumerable
public IEnumerator GetEnumerator()
{
return new EnumerationWrapper(m_Method);
}
}
public delegate bool FilterEntryMethod(ZipEntry e);
/// <summary>
/// Zip stream utils
/// </summary>
public class ZipUtils
{
public static void CopyStream(java.io.InputStream from, java.io.OutputStream to)
{
sbyte[] buffer = new sbyte[8192];
int got;
while ((got = from.read(buffer, 0, buffer.Length)) > 0)
to.write(buffer, 0, got);
}
public static void ExtractZipFile(ZipFile file, string path, FilterEntryMethod filter)
{
foreach(ZipEntry entry in new EnumerationAdapter(newEnumerationMethod(file.entries)))
{
if (!entry.isDirectory())
{
if ((filter == null ||filter(entry)))
{
java.io.InputStream s = file.getInputStream(entry);
try
{
string fname =System.IO.Path.GetFileName(entry.getName());
string newpath = System.IO.Path.Combine(path,System.IO.Path.GetDirectoryName(entry.getName()));
System.IO.Directory.CreateDirectory(newpath);
java.io.FileOutputStream dest = newjava.io.FileOutputStream(System.IO.Path.Combine(newpath, fname));
try
{
CopyStream(s, dest);
}
finally
{
dest.close();
}
}
finally
{
s.close();
}
}
}
}
}
public static ZipFile CreateEmptyZipFile(string fileName)
{
new ZipOutputStream(new java.io.FileOutputStream(fileName)).close();
return new ZipFile(fileName);
}
public static ZipFileUpdateZipFile(ZipFile file, FilterEntryMethod filter, string[] newFiles)
{
string prev = file.getName();
string tmp = System.IO.Path.GetTempFileName();
ZipOutputStream to = new ZipOutputStream(newjava.io.FileOutputStream(tmp));
try
{
CopyEntries(file, to, filter);
// add entries here
if (newFiles != null)
{
foreach(string f in newFiles)
{
ZipEntry z =new ZipEntry(f.Remove(0, System.IO.Path.GetPathRoot(f).Length));
z.setMethod(ZipEntry.DEFLATED);
to.putNextEntry(z);
try
{
java.io.FileInputStream s = newjava.io.FileInputStream(f);
try
{
CopyStream(s, to);
}
finally
{
s.close();
}
}
finally
{
to.closeEntry();
}
}
}
}
finally
{
to.close();
}
file.close();
// now replace the old file with the new one
System.IO.File.Copy(tmp, prev, true);
System.IO.File.Delete(tmp);
return new ZipFile(prev);
}
public static void CopyEntries(ZipFile from, ZipOutputStream to)
{
CopyEntries(from, to, null);
}
public static void CopyEntries(ZipFile from, ZipOutputStream to, FilterEntryMethod filter)
{
foreach(ZipEntry entry in new EnumerationAdapter(newEnumerationMethod(from.entries)))
{
if (filter == null || filter(entry))
{
java.io.InputStream s =from.getInputStream(entry);
try
{
to.putNextEntry(entry);
try
{
CopyStream(s, to);
}
finally
{
to.closeEntry();
}
}
finally
{
s.close();
}
}
}
}
}
}



VB.NET code:
Imports System
Imports System.Collections
Imports java.util
Imports java.util.zip
Namespace VbZip
Public Delegate Function EnumerationMethod() As Enumeration
Public Class EnumerationAdapter : Implements IEnumerable
Private Class EnumerationWrapper : Implements IEnumerator
Private m_Method As EnumerationMethod
Private m_Wrapped As Enumeration
Private m_Current As Object
Public Sub New(ByVal method As EnumerationMethod)
m_Method = method
End Sub
Public ReadOnly Property Current() As Object _
Implements IEnumerator.Current
Get
Return m_Current
End Get
End Property
Public Sub Reset() _
Implements IEnumerator.Reset
m_Wrapped = m_Method
If m_Wrapped Is Nothing Then
Throw New InvalidOperationException
End If
End Sub
Public Function MoveNext() As Boolean _
Implements IEnumerator.MoveNext
If m_Wrapped Is Nothing Then
Reset()
End If
Dim Result As Boolean = m_Wrapped.hasMoreElements()
If Result Then
m_Current = m_Wrapped.nextElement()
End If
Return Result
End Function
End Class
Private m_Method As EnumerationMethod
Public Function EnumerationAdapter(ByVal method As EnumerationMethod)
If method Is Nothing Then
Throw New ArgumentException
End If
m_Method = method
End Function
'IEnumerable
Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator
Return New EnumerationWrapper(m_Method)
End Function
End Class
Public Delegate Function FilterEntryMethod(ByVal e As ZipEntry) As Boolean
Public Class ZipUtils
Public Shared Sub CopyStream(ByVal from As java.io.InputStream, _
ByVal tto As java.io.OutputStream)
Dim buffer() As System.SByte = New System.SByte(8192) {}
Dim got As Integer
While (got = from.read(buffer, 0, buffer.Length)) > 0
tto.write(buffer, 0, got)
End While
End Sub
Public Shared SubExtractZipFile(ByVal file As ZipFile, ByVal path As String, ByValfilter As FilterEntryMethod)
ForEach entry As ZipEntry In New EnumerationAdapter(NewEnumerationMethod(file.entries))
If Not entry.isDirectory() Then
If (filter = Nothing Or filter(entry)) Then
Dim s As java.io.InputStream = file.getInputStream(entry)
Try
Dim fname As String = System.IO.Path.GetFileName(entry.getName())
Dim Newpath As String = System.IO.Path.Combine(path,System.IO.Path.GetDirectoryName(entry.getName()))
System.IO.Directory.CreateDirectory(Newpath)
Dim dest As java.io.FileOutputStream = Newjava.io.FileOutputStream(System.IO.Path.Combine(Newpath, fname))
Try
CopyStream(s, dest)
Finally
dest.close()
End Try
Finally
s.close()
End Try
End If
End If
Next
End Sub
Public Shared Function CreateEmptyZipFile(ByVal fileName As String) As ZipFile
Dimzos As New ZipOutputStream(New java.io.FileOutputStream(fileName))
zos.close()
Return New ZipFile(fileName)
End Function
Public Shared FunctionUpdateZipFile(ByVal file As ZipFile, ByVal filter As FilterEntryMethod,_
ByVal newFiles As String())
Dim prev As String = file.getName
Dim tmp As String = System.IO.Path.GetTempFileName
Dimtto As ZipOutputStream = New ZipOutputStream(Newjava.io.FileOutputStream(tmp))
Try
CopyEntries(file, tto, filter)
If Not newFiles Is Nothing Then
For Each f As String In newFiles
Dim z As ZipEntry = New ZipEntry(f.Remove(0,System.IO.Path.GetPathRoot(f).Length))
z.setMethod(ZipEntry.DEFLATED)
tto.putNextEntry(z)
Try
Dim s As New java.io.FileInputStream(f)
Try
CopyStream(s, tto)
Finally
s.close()
End Try
Finally
tto.closeEntry()
End Try
Next
End If
Finally
tto.close()
End Try
file.close()
'now replace the old file with the new one
System.IO.File.Copy(tmp, prev, True)
System.IO.File.Delete(tmp)
Return New ZipFile(prev)
End Function
Public Shared Sub CopyEntries(ByVal from As ZipFile, ByVal tto As ZipOutputStream, _
ByVal filter As FilterEntryMethod)
ForEach entry As ZipEntry In New EnumerationAdapter(NewEnumerationMethod(from.entries))
If filter Is Nothing Or filter(entry) Then
Dim s As java.io.InputStream = from.getInputStream(entry)
Try
tto.putNextEntry(entry)
Try
CopyStream(s, tto)
Finally
tto.closeEntry()
End Try
Finally
s.close()
End Try
End If
Next
End Sub
End Class
End Namespace
try the convertor it is for both languages

http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
I have tried a different translator before, and have just tried yoursuggestion. However, the results are the same and the conversion doesnot seem to be perfect. It still requires some manual tuning which Ihave done except for the two lines emphasized in red. Anyone here canhelp me out?Smile [:)]

i know it is not perfect but what i do is deal with errors manually other wise you will not be albe to solve the problem... we can help you if you can not solve the error so you deal in that case with few lines of code rather than 100's lines

Well, the error I'm getting is for the two lines emphasizes in red:
c:\inetpub\wwwroot\TestApplication\Zip.vb(81): 'TestApplication.VbZip.EnumerationMethod' is a delegate type. Delegate construction permits only a single AddressOf expression as an argument list. Often an AddressOf expression can be used instead of a delegate construction.".
I don't know too well how to solve this, so any insight is appreciated.

if you specify the code that making the problem we might help you at the mean time look at this if that will help!!
http://abstractvb.com/code.asp?A=1084
http://www.startvbdotnet.com/language/enumeration.aspx