question in select case

Discussion in 'MCAD' started by Guest, Feb 19, 2004.

  1. Guest

    Guest Guest

    What's wrong with this code.. I get an error in the
    statment

    name = 1stData.Items(1stData.SelectedIndex)

    Also.. I have another problem...

    If my current program has got any error, when the run the
    program then it is giving me the output of my previous
    program.. what could possible be the reason.. I spent
    hours in figuring out.. Can someone help me..

    Here goes the code...






    Private Sub lstData_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    lstData.SelectedIndexChanged



    'what did we choose?


    Dim name As String
    name = 1stData.Items(1stData.SelectedIndex)

    'use a select case to do something..

    Dim favoritecolor As String

    Select Case name

    Case "x"
    favoritecolor = "x"

    Case "y"
    favoritecolor = "y"

    Case "z"
    favoritecolor = "z"

    Case "a"
    favoritecolor = "a"

    Case "b"
    favoritecolor = "b"
    End Select

    MessageBox.Show(name & "'s favorite color is " &
    favoritecolor, "select demo")

    End Sub
     
    Guest, Feb 19, 2004
    #1
    1. Advertisements

  2. Are you using C#? If so you might have to index it like 1stData.Items[1stData.SelectedIndex]!! Hope this helps!

    ----- wrote: ----



    What's wrong with this code.. I get an error in the
    statment

    name = 1stData.Items(1stData.SelectedIndex

    Also.. I have another problem...

    If my current program has got any error, when the run the
    program then it is giving me the output of my previous
    program.. what could possible be the reason.. I spent
    hours in figuring out.. Can someone help me..

    Here goes the code..






    Private Sub lstData_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    lstData.SelectedIndexChange



    'what did we choose


    Dim name As Strin
    name = 1stData.Items(1stData.SelectedIndex

    'use a select case to do something.

    Dim favoritecolor As Strin

    Select Case nam

    Case "x
    favoritecolor = "x

    Case "y
    favoritecolor = "y

    Case "z
    favoritecolor = "z

    Case "a
    favoritecolor = "a

    Case "b
    favoritecolor = "b
    End Selec

    MessageBox.Show(name & "'s favorite color is " &
    favoritecolor, "select demo"

    End Su
     
    Ramon Guerrero, Feb 19, 2004
    #2
    1. Advertisements

  3. Guest

    kpg Guest

    There is nothing wrong with this VB.NET code.

    Except maybe the "1stData.Items" should be "lstData.Items" .

    d.a.
    kpg

    1stData.Items[1stData.SelectedIndex]!! Hope this helps!!
     
    kpg, Feb 19, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.