2017-07-03 6 views
0

これはVisual Basic Window Formアプリケーションで作成したプログラムで、2つのリストボックス、 1つは月のためのもので、もう1つは誕生石のためのものです。ユーザーが誕生石をクリックすると、対応する月がlblDescriptionコントロールに表示されます。または、ユーザーが_strMonthsリストボックスの月をクリックすると、対応する誕生石がlblDescriptionに表示されます。プログラムは動作していましたが、間違って削除しましたが、今は正確なコードを覚えていません。私は今それを再作成するために1週間は行ってきたが、役に立たない。私はSelectedIndexプロパティを調べましたが、これまで見たことのあるものは、SelectedIndexプロパティは整数ですが、私のものは文字列です。だから私はフォーラムに助けを求めている。コードは単純です。すべてのbirthstonesを表示するMsgBox(_intFill)を追加しました。私はほとんどそこにいますが、まだ葉巻はありません。リストボックスの選択されたインデックスで 'String'タイプの値を 'String'に変換できません。

Option Strict On 

Public Class frmBirthstones 
    'Declare class variables 
    Private _strStones(11) As String 
    Private _strMonths(11) As String 
    Public Shared _intFill As String 
    Public Shared _selectedIndex As String 

    Private Sub frmBirthstones_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     'Array items for Brith Stones 
     _strStones(0) = "Garnet" 
     _strStones(1) = "Amethyst" 
     _strStones(2) = "Aquamarine" 
     _strStones(3) = "Diamond" 
     _strStones(4) = "Emerald" 
     _strStones(5) = "Pearl" 
     _strStones(6) = "Ruby" 
     _strStones(7) = "Peridot" 
     _strStones(8) = "Sapphire" 
     _strStones(9) = "Opal" 
     _strStones(10) = "Topaz" 
     _strStones(11) = "Turquoise" 
     'Array items for Months 
     _strMonths(0) = "January" 
     _strMonths(1) = "February" 
     _strMonths(2) = "March" 
     _strMonths(3) = "April" 
     _strMonths(4) = "May" 
     _strMonths(5) = "June" 
     _strMonths(6) = "July" 
     _strMonths(7) = "August" 
     _strMonths(8) = "September" 
     _strMonths(9) = "October" 
     _strMonths(10) = "November" 
     _strMonths(11) = "December" 

     'Makes label Description visible 
     lblDescription.Visible = True 

     For Each _intFill In _strStones 
      'fills listbox with Birthstones 
      lstStones.Items.Add(_intFill) 
     MsgBox(_intFill) 

     Next 
     For Each _intFill In _strMonths 
      'fills listbox with Months 
      lstMonths.Items.Add(_intFill) 
     Next 

    End Sub 

    Private Sub lstStones_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstStones.SelectedIndexChanged 
     'When user click or selects a Birthstone in this listbox a corresponding Month for the Birthstone is selected 

     '_strStones = _intFill 
     'Doesn't work 
     lblDescription.Text = _strStones.ToString() & "is the Birthstone for the month of " & _strMonths.ToString() 

    End Sub 

    Private Sub lstMonths_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstMonths.SelectedIndexChanged 
     'When user click or selects a Month in this listbox a corresponding Birthstone for that Month is selected 

     '_strMonths = 
     lblDescription.Text = _strMonths.ToString() & "is the Month for the Birthstone " & _strStones.ToString() 
    End Sub 
End Class 
+0

いいえ、SelectedIndexプロパティは、確かに整数です。配列のToString()メソッドを使用することは意味をなさないので、あなたはそれを使用していません。あなたはstrsStones(lstStones.SelectedIndex)を必要とします.ToString()は簡単です。 –

答えて

0
Option Strict On 

Public Class frmBirthstones 
    Private _strStones(11) As String 
    Private _strMonths(11) As String 

    Private Sub frmBirthstones_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load 
     'Array items for Brith Stones 
     _strStones(0) = "Garnet" 
     _strStones(1) = "Amethyst" 
     _strStones(2) = "Aquamarine" 
     _strStones(3) = "Diamond" 
     _strStones(4) = "Emerald" 
     _strStones(5) = "Pearl" 
     _strStones(6) = "Ruby" 
     _strStones(7) = "Peridot" 
     _strStones(8) = "Sapphire" 
     _strStones(9) = "Opal" 
     _strStones(10) = "Topaz" 
     _strStones(11) = "Turquoise" 
     'Array items for Months 
     _strMonths(0) = "January" 
     _strMonths(1) = "February" 
     _strMonths(2) = "March" 
     _strMonths(3) = "April" 
     _strMonths(4) = "May" 
     _strMonths(5) = "June" 
     _strMonths(6) = "July" 
     _strMonths(7) = "August" 
     _strMonths(8) = "September" 
     _strMonths(9) = "October" 
     _strMonths(10) = "November" 
     _strMonths(11) = "December" 



     'Makes label Description visible 
     lblDescription.Visible = True 


     'fills listbox with Birthstones 
     lstStones.Items.AddRange(_strStones) 


     'fills listbox with Months 
     lstMonths.Items.AddRange(_strMonths) 




    End Sub 

    Private Sub lstStones_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lstStones.SelectedIndexChanged 
     lblDescription.Text = _strStones(lstStones.SelectedIndex).ToString() & " is the Birthstone for the month of " & _strMonths(lstStones.SelectedIndex).ToString() 
    End Sub 

    Private Sub lstMonths_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lstMonths.SelectedIndexChanged 
     lblDescription.Text = _strMonths(lstMonths.SelectedIndex).ToString() & " is the Month for the Birthstone " & _strStones(lstMonths.SelectedIndex).ToString() 
    End Sub 
End Class 

多分これはあなたが何をしたいです。

関連する問題