dimanche 19 avril 2015

Number of days in a month array visual basic

I'm working on a project where I enter a month of a year in a textbox and have it return (by pressing a button) the number of days that are in it. I must use a for each...next statement to search and match the strings between both arrays.

Here is what I have so far:

Dim monthname() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

Dim monthdays() As String = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

For Each y As String In monthname
TextBox1.Text = (y)

For Each x As String In monthdays

Dim search As String
Dim index As Integer = -1

For i = 0 To monthdays
If monthdays Is monthname Then
index = i
Exit For
End If

I can't figure out how to make the arrays compare to one another when the name of the month is put in the textbox. Right now when it works the program just adds the last month (december) in the textbox and all the number of days into the listbox.

thanks for any help!

Aucun commentaire:

Enregistrer un commentaire