2 Replies - 577 Views - Last Post: 02 April 2013 - 12:23 AM Rate Topic: -----

#1 Crypters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 01-April 13

Assigning an Array to a Listbox selection

Posted 01 April 2013 - 10:53 PM

Hello Everybody, this is my first time posting on this website (even though I have had much help from multiple answered questions on this site) I am still relativity new to coding.

Question: The code I am building is suppose to be able to display my Dim intDaysinTheMonth() As Integer array as the user selects a month from the List box. This is what I have so far...unfortunately I can only get the first month of January to display the number of days.

Code :
 Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' fills the list box with values and
        ' then selects the first item
        Dim strMonths() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
                                     "November", "December"}
        For Each strMonthToDays As String In strMonths
            lstMonths.Items.Add(strMonthToDays)
        Next strMonthToDays
        lstMonths.SelectedIndex = 0


        'The days associated with each month, as the month is selected, the corresponding days
        ' show in the lblDays box
        Dim intDaysinTheMonth() As Integer = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

        Dim intsub As Integer = lstMonths.SelectedIndex
        lblDays.Text = intDaysinTheMonth(intsub).ToString
    End Sub


    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

This post has been edited by AdamSpeight2008: 02 April 2013 - 02:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Assigning an Array to a Listbox selection

#2 Crypters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 01-April 13

Re: Assigning an Array to a Listbox selection

Posted 01 April 2013 - 11:20 PM

I fixed it............... I just moved the Dim intDaysInTheMonth to the lstMonths_SelectedValueChanged
Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: Assigning an Array to a Listbox selection

Posted 02 April 2013 - 12:23 AM

Welcome to the forum!

For your future reference, this is VB.Net code, so please post it in the correct forum if you post again in future... that way you'll get more specific answers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1