How to get combobox value in a textbox
-
hai every body, am using VS 2005 and using vb.net, vb is my code begin, my problem is in one combo box i was given all the months(like Jan 07, Feb 07...........,Dec 10)on the next Text box it should automatically retrieve no of days ie 30 or 31 am trying to write for combo changed event and also combo click event But it wont work. How To Solve my issue Please help
-
hai every body, am using VS 2005 and using vb.net, vb is my code begin, my problem is in one combo box i was given all the months(like Jan 07, Feb 07...........,Dec 10)on the next Text box it should automatically retrieve no of days ie 30 or 31 am trying to write for combo changed event and also combo click event But it wont work. How To Solve my issue Please help
urtextboxname.text=urcomboboxname.selectedindex.text or simply write urtextboxname.text=urcomboboxname.text
-
urtextboxname.text=urcomboboxname.selectedindex.text or simply write urtextboxname.text=urcomboboxname.text
Thanks For Your Reply. But It wont work. could you read my question? If the combo box value is jan 07 then the next text box would automatically changed to 31, if the combo value is feb 07 then the text box value automatically changed to 28. Is it Possible. Please help me?
-
Thanks For Your Reply. But It wont work. could you read my question? If the combo box value is jan 07 then the next text box would automatically changed to 31, if the combo value is feb 07 then the text box value automatically changed to 28. Is it Possible. Please help me?
Try starting with: On selectedindexchanged:
Dim subStr As Integer If Me.ComboBox2.Text.Contains("jan") Then subStr = Me.ComboBox2.Text.Substring(Me.ComboBox2.Text.IndexOf("n") + 1, 3) Me.TextBox1.Text = DateTime.DaysInMonth("20" & subStr, 1) ElseIf Me.ComboBox2.Text.Contains("feb") Then subStr = Me.ComboBox2.Text.Substring(Me.ComboBox2.Text.IndexOf("b") + 1, 3) '1. note the change in the letter within the index of Me.TextBox1.Text = DateTime.DaysInMonth("20" & subStr, 2) '2. note the change in the second part of this daysinmonth. End If
Do for each month. The subStr part of this code extracts the year, assuming the indexof letter is the last the only one in the month component and also assuming that there is a space between the month and year and that the year is in a 2 number format. Please note that contains() is case sensitive and needs to be specific. If you do the year as 2007 as oppose to 07 then the "20" part must be removed from the daysinmonth part of the code.Posted by The ANZAC
-
Thanks For Your Reply. But It wont work. could you read my question? If the combo box value is jan 07 then the next text box would automatically changed to 31, if the combo value is feb 07 then the text box value automatically changed to 28. Is it Possible. Please help me?
yest it so easy Function MonthDaysNo(cmbstr As String) As Integer dim str as string str=left(cmbstr,3) Select Case str Case "Jan": urtxtboxname.text="31" Case "Feb": Dim Mydate as DateTime = DateTime.Now Dim MyString As String = MyDate.ToString("yyyy") dim yr as integer yr=cint(Mydate) If yr Mod 4 Then urtxtboxname.text = 29 Else urtxtboxname.text = 28 End If Case "Mar": urtxtboxname.text="31" Case "Apr": urtxtboxname.text="30" Case "May": urtxtboxname.text="31" Case "Jun": urtxtboxname.text="301" Case "Jul": urtxtboxname.text="31" Case "Aug": urtxtboxname.text="31" Case "Sept": urtxtboxname.text="30" Case "Oct": urtxtboxname.text="31" Case "Nov": urtxtboxname.text="30" Case "Dec": urtxtboxname.text="31" End Select End Function then in the item change change call this function by passing argument urcombobox.text
-
yest it so easy Function MonthDaysNo(cmbstr As String) As Integer dim str as string str=left(cmbstr,3) Select Case str Case "Jan": urtxtboxname.text="31" Case "Feb": Dim Mydate as DateTime = DateTime.Now Dim MyString As String = MyDate.ToString("yyyy") dim yr as integer yr=cint(Mydate) If yr Mod 4 Then urtxtboxname.text = 29 Else urtxtboxname.text = 28 End If Case "Mar": urtxtboxname.text="31" Case "Apr": urtxtboxname.text="30" Case "May": urtxtboxname.text="31" Case "Jun": urtxtboxname.text="301" Case "Jul": urtxtboxname.text="31" Case "Aug": urtxtboxname.text="31" Case "Sept": urtxtboxname.text="30" Case "Oct": urtxtboxname.text="31" Case "Nov": urtxtboxname.text="30" Case "Dec": urtxtboxname.text="31" End Select End Function then in the item change change call this function by passing argument urcombobox.text
Actually it's even easier :)
'Date to test Dim stringDate As String = "sep 07" 'Date object Dim parsedDate As Date 'If our string is valid date show days in month If Date.TryParse(stringDate, parsedDate) Then MsgBox(Date.DaysInMonth(parsedDate.Year, parsedDate.Month)) End If
From what I can tell the 'TryParse' method will except 3 letter abbreviations for the month as well as the full name. It won't except 'sept' however so I hope that's not an issue. If it is you could do it a little differently by making your own enumerator.
Private Function Days(ByVal text As String) As Integer Dim split As String() = text.Split 'An error could occur so catch it and return -1 Try Dim month As Integer = \[Enum\].Parse(GetType(Month), split(0).ToUpper) Dim year As Integer = CInt("20" & split(1)) Return Date.DaysInMonth(year, month) Catch ex As Exception Return -1 End Try End Function Private Enum Month JAN = 1 FEB MAR APR MAY JUN JUL AUG SEPT OCT NOV DEC End Enum
-
yest it so easy Function MonthDaysNo(cmbstr As String) As Integer dim str as string str=left(cmbstr,3) Select Case str Case "Jan": urtxtboxname.text="31" Case "Feb": Dim Mydate as DateTime = DateTime.Now Dim MyString As String = MyDate.ToString("yyyy") dim yr as integer yr=cint(Mydate) If yr Mod 4 Then urtxtboxname.text = 29 Else urtxtboxname.text = 28 End If Case "Mar": urtxtboxname.text="31" Case "Apr": urtxtboxname.text="30" Case "May": urtxtboxname.text="31" Case "Jun": urtxtboxname.text="301" Case "Jul": urtxtboxname.text="31" Case "Aug": urtxtboxname.text="31" Case "Sept": urtxtboxname.text="30" Case "Oct": urtxtboxname.text="31" Case "Nov": urtxtboxname.text="30" Case "Dec": urtxtboxname.text="31" End Select End Function then in the item change change call this function by passing argument urcombobox.text