Link to home
Start Free TrialLog in
Avatar of BrijBhasin
BrijBhasin

asked on

convert code from C# to VB

Hi,
 I'm on a tight deadline and would appreaciate if someone can convert the following code from C# to VB.

Thanks

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
KnownColor enumColor = new KnownColor();
Array Colors = Enum.GetValues(enumColor.GetType());
ArrayList ALColor = new ArrayList();
foreach(object clr in Colors)
if (!Color.FromKnownColor((KnownColor)clr).IsSystemColor)
ALColor.Add(clr.ToString());
cboColor.DataSource = ALColor;
cboColor.DataBind();
}
for (int i= 0 ;i < cboColor.Items.Count;i++)
{
cboColor.Items[i].Attributes.Add("style", "color:" + cboColor.Items[i].Text);
}

}
private void cboColor_ServerChanged(object sender, System.EventArgs e)
{
if (cboColor.SelectedIndex > -1)
strSelectedColor = cboColor.Items[cboColor.SelectedIndex].Text;
else
strSelectedColor = cboColor.Items[0].Text;
}
SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrijBhasin
BrijBhasin

ASKER

I'm getting an error System.InvalidCastException: Specified cast is not valid.
 on:
 If Not CType(clr, Color).IsSystemColor Then
BrijBhasin,

Here's a link that will allow you to paste C# code and it will convert it to VB.NET:

http://authors.aspalliance.com/aldotnet/examples/translate.aspx

HtH.

Private Sub Page_Load(sender As Object, e As System.EventArgs)
   If Not IsPostBack Then
      Dim enumColor As New KnownColor()
      Dim Colors As Array = [Enum].GetValues(enumColor.GetType())
      Dim ALColor As New ArrayList()
      Dim clr As Object
      For Each clr In  Colors
         If Not Color.FromKnownColor(CType(clr, KnownColor)).IsSystemColor Then
            ALColor.Add(clr.ToString())
         End If
      Next clr
      cboColor.DataSource = ALColor
      cboColor.DataBind()
   End If
   Dim i As Integer
   For i = 0 To cboColor.Items.Count - 1
      cboColor.Items(i).Attributes.Add("style", "color:" + cboColor.Items(i).Text)
   Next i
End Sub 'Page_Load


Private Sub cboColor_ServerChanged(sender As Object, e As System.EventArgs)
   If cboColor.SelectedIndex > - 1 Then
      strSelectedColor = cboColor.Items(cboColor.SelectedIndex).Text
   Else
      strSelectedColor = cboColor.Items(0).Text
   End If
End Sub 'cboColor_ServerChanged
Why didn't you use
                 "If Not Color.FromKnownColor(clr).IsSystemColor Then"
like in the code I posted?
jensfiederer I didnt see your post when I posted my comment, it was meant for Chaosian. I'm splitting the points and giving you both credit.