Yash Kapoor

Yash Kapoor

  • NA
  • 1
  • 16k

Equivalent of this C# code in VB

Nov 24 2010 6:17 PM
The code in C# is as follows:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //filling items in combobox1
            if (comboBox1.SelectedIndex==0)
            {
            comboBox2.Items.Clear();
            for (char i ='A' ; i < 'D'; i++)
            {
                comboBox2.Items.Add(i);
            }
            }
            if (comboBox1.SelectedIndex == 1 || comboBox1.SelectedIndex == 2 || comboBox1.SelectedIndex == 3)
            {
                comboBox2.Items.Clear();
                for (char i = 'A'; i < 'E'; i++)
                {
                    comboBox2.Items.Add(i);
                }
            }
            if (comboBox1.SelectedIndex == 4)
            {
                comboBox2.Items.Clear();
                for (char i = 'A'; i < 'F'; i++)
                {
                    comboBox2.Items.Add(i);
                }
            }
            if (comboBox1.SelectedIndex == 5 || comboBox1.SelectedIndex == 6)
            {
                comboBox2.Items.Clear();
                for (char i = 'A'; i < 'G'; i++)
                {
                    comboBox2.Items.Add(i);
                }
            }
            if (comboBox1.SelectedIndex == 7 || comboBox1.SelectedIndex == 8 || comboBox1.SelectedIndex == 9)
            {
                comboBox2.Items.Clear();
                for (char i = 'A'; i < 'I'; i++)
                {
                    comboBox2.Items.Add(i);
                }
            }
        }

I want to implement this code in VB. Using a converter, i got this:

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
'filling items in combobox1
If comboBox1.SelectedIndex = 0 Then
comboBox2.Items.Clear()
For i As Char = "A"C To "D"C - 1
comboBox2.Items.Add(i)
Next
End If
If comboBox1.SelectedIndex = 1 OrElse comboBox1.SelectedIndex = 2 OrElse comboBox1.SelectedIndex = 3 Then
comboBox2.Items.Clear()
For i As Char = "A"C To "E"C - 1
comboBox2.Items.Add(i)
Next
End If
If comboBox1.SelectedIndex = 4 Then
comboBox2.Items.Clear()
For i As Char = "A"C To "F"C - 1
comboBox2.Items.Add(i)
Next
End If
If comboBox1.SelectedIndex = 5 OrElse comboBox1.SelectedIndex = 6 Then
comboBox2.Items.Clear()
For i As Char = "A"C To "G"C - 1
comboBox2.Items.Add(i)
Next
End If
If comboBox1.SelectedIndex = 7 OrElse comboBox1.SelectedIndex = 8 OrElse comboBox1.SelectedIndex = 9 Then
comboBox2.Items.Clear()
For i As Char = "A"C To "I"C - 1
comboBox2.Items.Add(i)
Next
End If
End Sub


When i compile the code, it returns an error saying Error

" 'For' loop control variable cannot be of type 'Char' because the type does not support the required operators"

Can you please help me out with this?
I have a project to submit tomorrow :S

Answers (3)