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
Sam HobbsPosted Dec 8, 2010, 9:11 PM
I think you can use the AscW function to convert the characters to integers that will work in the code that was generated, and use ChrW to convert back to characters.
Shahan AyyubPosted Dec 8, 2010, 4:21 PM
try the below code: (converted from here:http://www.carlosag.net/Tools/CodeTranslator/)
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
'filling items in combobox1
If (comboBox1.SelectedIndex = 0) Then
comboBox2.Items.Clear
Dim i As Char = Microsoft.VisualBasic.ChrW(65)
Do While (i < Microsoft.VisualBasic.ChrW(68))
comboBox2.Items.Add(i)
i = (i + 1)
Loop
End If
If ((comboBox1.SelectedIndex = 1) _
OrElse ((comboBox1.SelectedIndex = 2) _
OrElse (comboBox1.SelectedIndex = 3))) Then
comboBox2.Items.Clear
Dim i As Char = Microsoft.VisualBasic.ChrW(65)
Do While (i < Microsoft.VisualBasic.ChrW(69))
comboBox2.Items.Add(i)
i = (i + 1)
Loop
End If
If (comboBox1.SelectedIndex = 4) Then
comboBox2.Items.Clear
Dim i As Char = Microsoft.VisualBasic.ChrW(65)
Do While (i < Microsoft.VisualBasic.ChrW(70))
comboBox2.Items.Add(i)
i = (i + 1)
Loop
End If
If ((comboBox1.SelectedIndex = 5) _
OrElse (comboBox1.SelectedIndex = 6)) Then
comboBox2.Items.Clear
Dim i As Char = Microsoft.VisualBasic.ChrW(65)
Do While (i < Microsoft.VisualBasic.ChrW(71))
comboBox2.Items.Add(i)
i = (i + 1)
Loop
End If
If ((comboBox1.SelectedIndex = 7) _
OrElse ((comboBox1.SelectedIndex = 8) _
OrElse (comboBox1.SelectedIndex = 9))) Then
comboBox2.Items.Clear
Dim i As Char = Microsoft.VisualBasic.ChrW(65)
Do While (i < Microsoft.VisualBasic.ChrW(73))
comboBox2.Items.Add(i)
i = (i + 1)
Loop
End If
End Sub
Jiteendra SampathiraoPosted Nov 25, 2010, 12:19 AM
Use before implementing for loop....
1)
Dim i as char
or
2)
Dim i as char
I hope atleast one of the the above will goes successfully........
-------------------------------------------------------------------------------------------------
If this post helped you, then tick the "Do you like this Answer" checkbox.