conversion to VB fails

T

TJS

when converting this to VB, the result fails , can anyone help ?

C#

private void CreateDayEffects(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
if (Calendar1.DayStyle.BackColor != Color.Empty)
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='" +
Calendar1.DayStyle.BackColor.ToKnownColor() + "';";
else
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='';";
}
VB

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"

If myCalendar.DayStyle.BackColor <> Color.Empty Then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='';"
End If
End Sub 'CreateDayEffects

ERROR

Compiler Error Message:
BC30452: Operator '<>' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.Source Error:
Line 65: Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
Line 66: e.Cell.Attributes("onmouseover") =
"this.style.backgroundColor='pink';"
Line 67: If myCalendar.DayStyle.BackColor <> Color.Empty Then
Line 68: e.Cell.Attributes("onmouseout") =
"this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Line 69: Else
 
K

Karl

change the if myCalendar.DayStyle.BackColor <> Color.Empty then

to if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then


Karl
 
T

TJS

thanks, that cured the error message but I have a nother problem, the mouser
turns the date background to pink but on mouseout it turns to black instead
of the assigned background value of "lightyellow" in the control.

do you know why that may be happening

here's the entire script
==========================

<%@ Page Language="VB" autoeventwireup="True" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

'Hide the title of the calendar control
myCalendar.ShowTitle = False

'Populate month and year dropdown list boxes which
'replace the original calendar title
If Not Page.IsPostBack Then

Call Populate_MonthList()

Call Populate_YearList()
End If

End Sub


Sub Set_Calendar(Sender As Object, E As EventArgs)

'Whenever month or year selection changes display the calendar for
that month/year
myCalendar.TodaysDate = CDate(drpCalMonth.SelectedItem.Value & " 1,
" & drpCalYear.SelectedItem.Value)

End Sub


Sub Populate_MonthList()

drpCalMonth.Items.Add("January")
drpCalMonth.Items.Add("February")
drpCalMonth.Items.Add("March")
drpCalMonth.Items.Add("April")
drpCalMonth.Items.Add("May")
drpCalMonth.Items.Add("June")
drpCalMonth.Items.Add("July")
drpCalMonth.Items.Add("August")
drpCalMonth.Items.Add("September")
drpCalMonth.Items.Add("October")
drpCalMonth.Items.Add("November")
drpCalMonth.Items.Add("December")


drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected = True

End Sub


Sub Populate_YearList()

'Year list can be extended
Dim intYear As Integer

For intYear = DateTime.Now.Year - 20 to DateTime.Now.Year + 20

drpCalYear.Items.Add(intYear)
Next

drpCalYear.Items.FindByValue(DateTime.Now.Year).Selected = True

End Sub

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)

e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"
if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" &
myCalendar.DayStyle.BackColor.ToKnownColor() & "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='red';"
End If

End Sub 'CreateDayEffects

</script>

<style type="text/css">
BODY { font-family: verdana, arial, helvetica;
}

.calTitle {font-weight: bold;
font-size: 11;
background-color:#cccccc;
color: black;
width: 90px;
}

.calBody {font-size: 11;
border-width: 10px;
}
</style>

<form id="frmCal" runat="server">
<table cellspacing="0" cellpadding="0" width="20%" border="0">
<tbody>
<tr>
<td align="left" bgcolor="#cccccc">
<asp:DropDownList id="drpCalMonth" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
<td align="right" bgcolor="#cccccc">
<asp:DropDownList id="drpCalYear" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Calendar
OnDayRender="CreateDayEffects"
OtherMonthDayStyle-BackColor="White"
DayStyle-BackColor="LightYellow"
id="myCalendar"
Runat="Server"
cssClass="calBody"
DayHeaderStyle-BackColor="#eeeeee"
Width="100%">
</asp:Calendar>
</td>
</tr>
</tbody>
</table>
</form>











Karl said:
change the if myCalendar.DayStyle.BackColor <> Color.Empty then

to if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then


Karl


TJS said:
when converting this to VB, the result fails , can anyone help ?

C#

private void CreateDayEffects(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
if (Calendar1.DayStyle.BackColor != Color.Empty)
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='" +
Calendar1.DayStyle.BackColor.ToKnownColor() + "';";
else
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='';";
}
VB

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"

If myCalendar.DayStyle.BackColor <> Color.Empty Then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='';"
End If
End Sub 'CreateDayEffects

ERROR

Compiler Error Message:
BC30452: Operator '<>' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.Source Error:
Line 65: Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
Line 66: e.Cell.Attributes("onmouseover") =
"this.style.backgroundColor='pink';"
Line 67: If myCalendar.DayStyle.BackColor <> Color.Empty Then
Line 68: e.Cell.Attributes("onmouseout") =
"this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Line 69: Else
 
K

Karl

Can't say for sure, did you try to ToString() that value?

"this.style.backgroundColor='" &
myCalendar.DayStyle.BackColor.ToKnownColor().ToString() & "';"

also, what if you just try to hardcode the value for now, does that work?

"this.style.backgroundColor='lightyellow';"

finally, how does the HTML look with your code? does it properly display
"lightyellow" ?

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/


TJS said:
thanks, that cured the error message but I have a nother problem, the mouser
turns the date background to pink but on mouseout it turns to black instead
of the assigned background value of "lightyellow" in the control.

do you know why that may be happening

here's the entire script
==========================

<%@ Page Language="VB" autoeventwireup="True" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

'Hide the title of the calendar control
myCalendar.ShowTitle = False

'Populate month and year dropdown list boxes which
'replace the original calendar title
If Not Page.IsPostBack Then

Call Populate_MonthList()

Call Populate_YearList()
End If

End Sub


Sub Set_Calendar(Sender As Object, E As EventArgs)

'Whenever month or year selection changes display the calendar for
that month/year
myCalendar.TodaysDate = CDate(drpCalMonth.SelectedItem.Value & " 1,
" & drpCalYear.SelectedItem.Value)

End Sub


Sub Populate_MonthList()

drpCalMonth.Items.Add("January")
drpCalMonth.Items.Add("February")
drpCalMonth.Items.Add("March")
drpCalMonth.Items.Add("April")
drpCalMonth.Items.Add("May")
drpCalMonth.Items.Add("June")
drpCalMonth.Items.Add("July")
drpCalMonth.Items.Add("August")
drpCalMonth.Items.Add("September")
drpCalMonth.Items.Add("October")
drpCalMonth.Items.Add("November")
drpCalMonth.Items.Add("December")


drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected = True

End Sub


Sub Populate_YearList()

'Year list can be extended
Dim intYear As Integer

For intYear = DateTime.Now.Year - 20 to DateTime.Now.Year + 20

drpCalYear.Items.Add(intYear)
Next

drpCalYear.Items.FindByValue(DateTime.Now.Year).Selected = True

End Sub

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)

e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"
if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" &
myCalendar.DayStyle.BackColor.ToKnownColor() & "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='red';"
End If

End Sub 'CreateDayEffects

</script>

<style type="text/css">
BODY { font-family: verdana, arial, helvetica;
}

.calTitle {font-weight: bold;
font-size: 11;
background-color:#cccccc;
color: black;
width: 90px;
}

.calBody {font-size: 11;
border-width: 10px;
}
</style>

<form id="frmCal" runat="server">
<table cellspacing="0" cellpadding="0" width="20%" border="0">
<tbody>
<tr>
<td align="left" bgcolor="#cccccc">
<asp:DropDownList id="drpCalMonth" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
<td align="right" bgcolor="#cccccc">
<asp:DropDownList id="drpCalYear" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Calendar
OnDayRender="CreateDayEffects"
OtherMonthDayStyle-BackColor="White"
DayStyle-BackColor="LightYellow"
id="myCalendar"
Runat="Server"
cssClass="calBody"
DayHeaderStyle-BackColor="#eeeeee"
Width="100%">
</asp:Calendar>
</td>
</tr>
</tbody>
</table>
</form>











Karl said:
change the if myCalendar.DayStyle.BackColor <> Color.Empty then

to if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then


Karl


TJS said:
when converting this to VB, the result fails , can anyone help ?

C#

private void CreateDayEffects(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
if (Calendar1.DayStyle.BackColor != Color.Empty)
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='" +
Calendar1.DayStyle.BackColor.ToKnownColor() + "';";
else
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='';";
}
VB

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"

If myCalendar.DayStyle.BackColor <> Color.Empty Then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='';"
End If
End Sub 'CreateDayEffects

ERROR

Compiler Error Message:
BC30452: Operator '<>' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.Source Error:
Line 65: Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
Line 66: e.Cell.Attributes("onmouseover") =
"this.style.backgroundColor='pink';"
Line 67: If myCalendar.DayStyle.BackColor <> Color.Empty Then
Line 68: e.Cell.Attributes("onmouseout") =
"this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Line 69: Else
 
T

TJS

I got it working in Firefox, but it still isn't right in IE.

--I dropped that line of code altogether and the following "else" statment
--I added the "lightyellow" into the calBody style code for background
--I added SelectedDayStyle-BackColor="silver" into the control

then it works to give the right colors ( at least for mozilla, which is all
that matters :)

thanks for the help.






Karl said:
Can't say for sure, did you try to ToString() that value?

"this.style.backgroundColor='" &
myCalendar.DayStyle.BackColor.ToKnownColor().ToString() & "';"

also, what if you just try to hardcode the value for now, does that work?

"this.style.backgroundColor='lightyellow';"

finally, how does the HTML look with your code? does it properly display
"lightyellow" ?

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/


TJS said:
thanks, that cured the error message but I have a nother problem, the mouser
turns the date background to pink but on mouseout it turns to black instead
of the assigned background value of "lightyellow" in the control.

do you know why that may be happening

here's the entire script
==========================

<%@ Page Language="VB" autoeventwireup="True" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

'Hide the title of the calendar control
myCalendar.ShowTitle = False

'Populate month and year dropdown list boxes which
'replace the original calendar title
If Not Page.IsPostBack Then

Call Populate_MonthList()

Call Populate_YearList()
End If

End Sub


Sub Set_Calendar(Sender As Object, E As EventArgs)

'Whenever month or year selection changes display the calendar for
that month/year
myCalendar.TodaysDate = CDate(drpCalMonth.SelectedItem.Value & " 1,
" & drpCalYear.SelectedItem.Value)

End Sub


Sub Populate_MonthList()

drpCalMonth.Items.Add("January")
drpCalMonth.Items.Add("February")
drpCalMonth.Items.Add("March")
drpCalMonth.Items.Add("April")
drpCalMonth.Items.Add("May")
drpCalMonth.Items.Add("June")
drpCalMonth.Items.Add("July")
drpCalMonth.Items.Add("August")
drpCalMonth.Items.Add("September")
drpCalMonth.Items.Add("October")
drpCalMonth.Items.Add("November")
drpCalMonth.Items.Add("December")


drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected = True

End Sub


Sub Populate_YearList()

'Year list can be extended
Dim intYear As Integer

For intYear = DateTime.Now.Year - 20 to DateTime.Now.Year + 20

drpCalYear.Items.Add(intYear)
Next

drpCalYear.Items.FindByValue(DateTime.Now.Year).Selected = True

End Sub

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)

e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"
if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" &
myCalendar.DayStyle.BackColor.ToKnownColor() & "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='red';"
End If

End Sub 'CreateDayEffects

</script>

<style type="text/css">
BODY { font-family: verdana, arial, helvetica;
}

.calTitle {font-weight: bold;
font-size: 11;
background-color:#cccccc;
color: black;
width: 90px;
}

.calBody {font-size: 11;
border-width: 10px;
}
</style>

<form id="frmCal" runat="server">
<table cellspacing="0" cellpadding="0" width="20%" border="0">
<tbody>
<tr>
<td align="left" bgcolor="#cccccc">
<asp:DropDownList id="drpCalMonth" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
<td align="right" bgcolor="#cccccc">
<asp:DropDownList id="drpCalYear" Runat="Server"
AutoPostBack="True" OnSelectedIndexChanged="Set_Calendar"
cssClass="calTitle"></asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Calendar
OnDayRender="CreateDayEffects"
OtherMonthDayStyle-BackColor="White"
DayStyle-BackColor="LightYellow"
id="myCalendar"
Runat="Server"
cssClass="calBody"
DayHeaderStyle-BackColor="#eeeeee"
Width="100%">
</asp:Calendar>
</td>
</tr>
</tbody>
</table>
</form>











message news:[email protected]...
change the if myCalendar.DayStyle.BackColor <> Color.Empty then

to if not myCalendar.DayStyle.BackColor.Equals(Color.Empty) then


Karl


when converting this to VB, the result fails , can anyone help ?

C#

private void CreateDayEffects(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Attributes["onmouseover"] =
"this.style.backgroundColor='pink';";
if (Calendar1.DayStyle.BackColor != Color.Empty)
e.Cell.Attributes["onmouseout"] =
"this.style.backgroundColor='"
+
Calendar1.DayStyle.BackColor.ToKnownColor() + "';";
else
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='';";
}
VB

Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
e.Cell.Attributes("onmouseover") = "this.style.backgroundColor='pink';"

If myCalendar.DayStyle.BackColor <> Color.Empty Then
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Else
e.Cell.Attributes("onmouseout") = "this.style.backgroundColor='';"
End If
End Sub 'CreateDayEffects

ERROR

Compiler Error Message:
BC30452: Operator '<>' is not defined for types
'System.Drawing.Color'
and
'System.Drawing.Color'.Source Error:
Line 65: Private Sub CreateDayEffects(sender As Object, e As
System.Web.UI.WebControls.DayRenderEventArgs)
Line 66: e.Cell.Attributes("onmouseover") =
"this.style.backgroundColor='pink';"
Line 67: If myCalendar.DayStyle.BackColor <> Color.Empty Then
Line 68: e.Cell.Attributes("onmouseout") =
"this.style.backgroundColor='" +
myCalendar.DayStyle.BackColor.ToKnownColor() + "';"
Line 69: Else
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top