473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with C# class to VB.net conversion.

Ty
Hello all,

I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.

The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.

The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).

Any help woulld be greatful.

C# CODE

public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}


private static readonly object EventClick = new object();

public event EventHandler Click
{
add
{

Events.AddHandler(EventClick,

value);
}
remove
{

Events.RemoveHandler(EventClick,

value);
}

}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;

if (h != null)
h(

this, e);
}

#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(

EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(

HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}

}

************************************************** ************************************************** ******************************
VB CONVERTED CODE

Imports Microsoft.VisualBasic

Public Class ClickableTableCell
Inherits TableCell
Implements IPostBackEventHandler
Public Sub New()
Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
End Sub


Private Shared ReadOnly EventClick As New Object()

Public Custom Event Click As EventHandler

AddHandler(ByVal value As EventHandler)


Events.[AddHandler](EventClick, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)


Events.[RemoveHandler](EventClick, value)
End RemoveHandler
End Event

Protected Sub OnClick(ByVal e As EventArgs)
Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
RaiseEvent h(Me, e)
End Sub


Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "lbl" Then
OnClick(EventArgs.Empty)

End If
End Sub
Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)

writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub

End Class
Thanks,

Ty
Aug 10 '08 #1
4 2327
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
'...
End RaiseEvent

Other than that your conversion looks good.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Ty" wrote:
Hello all,

I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.

The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.

The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).

Any help woulld be greatful.

C# CODE

public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}


private static readonly object EventClick = new object();

public event EventHandler Click
{
add
{

Events.AddHandler(EventClick,

value);
}
remove
{

Events.RemoveHandler(EventClick,

value);
}

}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;

if (h != null)
h(

this, e);
}

#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(

EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(

HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}

}

************************************************** ************************************************** ******************************
VB CONVERTED CODE

Imports Microsoft.VisualBasic

Public Class ClickableTableCell
Inherits TableCell
Implements IPostBackEventHandler
Public Sub New()
Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
End Sub


Private Shared ReadOnly EventClick As New Object()

Public Custom Event Click As EventHandler

AddHandler(ByVal value As EventHandler)


Events.[AddHandler](EventClick, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)


Events.[RemoveHandler](EventClick, value)
End RemoveHandler
End Event

Protected Sub OnClick(ByVal e As EventArgs)
Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
RaiseEvent h(Me, e)
End Sub


Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "lbl" Then
OnClick(EventArgs.Empty)

End If
End Sub
Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)

writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub

End Class
Thanks,

Ty
Aug 11 '08 #2
Ty
On Aug 10, 8:31*pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
* * '...
End RaiseEvent

Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI

"Ty" wrote:
Hello all,
I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.
The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.
The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).
Any help woulld be greatful.
C# CODE
public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}
private static readonly object EventClick = new object();
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick,
value);
}
remove
{
Events.RemoveHandler(EventClick,
value);
}
}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}
#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(
EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(
HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}
}
************************************************** ************************************************** *******************************
VB CONVERTED CODE
Imports Microsoft.VisualBasic
Public Class ClickableTableCell
* * Inherits TableCell
* * Implements IPostBackEventHandler
* * Public Sub New()
* * * * Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
* * End Sub
* * Private Shared ReadOnly EventClick As New Object()
* * Public Custom Event Click As EventHandler
* * * * AddHandler(ByVal value As EventHandler)
* * * * * * Events.[AddHandler](EventClick, value)
* * * * End AddHandler
* * * * RemoveHandler(ByVal value As EventHandler)
* * * * * * Events.[RemoveHandler](EventClick, value)
* * * * End RemoveHandler
* * End Event
* * Protected Sub OnClick(ByVal e As EventArgs)
* * * * Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
* * * * RaiseEvent h(Me, e)
* * End Sub
* * Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
* * * * If eventArgument = "lbl" Then
* * * * * * OnClick(EventArgs.Empty)
* * * * End If
* * End Sub
* * Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
* * * * MyBase.AddAttributesToRender(writer)
* * * * writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
* * End Sub
End Class
Thanks,
Ty- Hide quoted text -

- Show quoted text -
Hello David,

The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.

Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.

Thanks,
Ty
Aug 11 '08 #3
Here's a link which gives a sample of what the RaiseEvent block should contain:
http://www.codeguru.com/vb/gen/vb_ge...icle.php/c9481
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Ty" wrote:
On Aug 10, 8:31 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
'...
End RaiseEvent

Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI

"Ty" wrote:
Hello all,
I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.
The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.
The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).
Any help woulld be greatful.
C# CODE
public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}
private static readonly object EventClick = new object();
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick,
value);
}
remove
{
Events.RemoveHandler(EventClick,
value);
}
}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}
#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(
EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(
HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}
}
************************************************** *************************Â************************ ********************************
VB CONVERTED CODE
Imports Microsoft.VisualBasic
Public Class ClickableTableCell
Inherits TableCell
Implements IPostBackEventHandler
Public Sub New()
Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
End Sub
Private Shared ReadOnly EventClick As New Object()
Public Custom Event Click As EventHandler
AddHandler(ByVal value As EventHandler)
Events.[AddHandler](EventClick, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.[RemoveHandler](EventClick, value)
End RemoveHandler
End Event
Protected Sub OnClick(ByVal e As EventArgs)
Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
RaiseEvent h(Me, e)
End Sub
Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "lbl" Then
OnClick(EventArgs.Empty)
End If
End Sub
Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)
writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub
End Class
Thanks,
Ty- Hide quoted text -
- Show quoted text -

Hello David,

The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.

Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.

Thanks,
Ty
Aug 11 '08 #4
Ty
On Aug 11, 11:16*am, David Anton
<DavidAn...@discussions.microsoft.comwrote:
Here's a link which gives a sample of what the RaiseEvent block should contain:http://www.codeguru.com/vb/gen/vb_ge...icle.php/c9481
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI

"Ty" wrote:
On Aug 10, 8:31 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
* * '...
End RaiseEvent
Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Ty" wrote:
Hello all,
I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.
The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.
The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).
Any help woulld be greatful.
C# CODE
public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}
private static readonly object EventClick = new object();
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick,
value);
}
remove
{
Events.RemoveHandler(EventClick,
value);
}
}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}
#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(
EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(
HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}
}
************************************************** ************************************************** ********************************
VB CONVERTED CODE
Imports Microsoft.VisualBasic
Public Class ClickableTableCell
* * Inherits TableCell
* * Implements IPostBackEventHandler
* * Public Sub New()
* * * * Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
* * End Sub
* * Private Shared ReadOnly EventClick As New Object()
* * Public Custom Event Click As EventHandler
* * * * AddHandler(ByVal value As EventHandler)
* * * * * * Events.[AddHandler](EventClick, value)
* * * * End AddHandler
* * * * RemoveHandler(ByVal value As EventHandler)
* * * * * * Events.[RemoveHandler](EventClick, value)
* * * * End RemoveHandler
* * End Event
* * Protected Sub OnClick(ByVal e As EventArgs)
* * * * Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
* * * * RaiseEvent h(Me, e)
* * End Sub
* * Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
* * * * If eventArgument = "lbl" Then
* * * * * * OnClick(EventArgs.Empty)
* * * * End If
* * End Sub
* * Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
* * * * MyBase.AddAttributesToRender(writer)
* * * * writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
* * End Sub
End Class
Thanks,
Ty- Hide quoted text -
- Show quoted text -
Hello David,
The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.
Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.
Thanks,
Ty- Hide quoted text -

- Show quoted text -
Hello all,

David thanks for you help. I got the answer from my original post
although I was not expecting it. See here for the answer.
http://forums.asp.net/p/1303134/2551012.aspx#2551012
Aug 11 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Don Bruder | last post by:
Got a stumper here. I imagine that for someone experienced in C++, this is too pathetic for words. For a rookie, using this project as a sort of "midterm exam" in his self-taught "how to program in...
4
by: Jim Hubbard | last post by:
I have some C# code that is supposed to wrap the defrag APIs and I am trying to convert it to VB.Net (2003). But, I keep having problems. The C# code is relatively short, so I'll post it...
3
by: Rob F | last post by:
I am trying to compile a string class which was working before but subsequent attempts to make it more 'object orientated' (privatizing the member variables and implenting query functions) it...
13
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
3
by: CoolPint | last post by:
After upgrading to gcc 3.4.2 from gcc 3.2.3, I got compiler errors that I could not figure out. After reading other postings, I learned that my coding was not compliant to the standard in the first...
5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
19
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.