Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to get combobox value in a textbox

How to get combobox value in a textbox

Scheduled Pinned Locked Moved Visual Basic
helpcsharpvisual-studiotutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rrrriiizz
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • R rrrriiizz

      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

      A Offline
      A Offline
      amjad ali shah
      wrote on last edited by
      #2

      urtextboxname.text=urcomboboxname.selectedindex.text or simply write urtextboxname.text=urcomboboxname.text

      R 1 Reply Last reply
      0
      • A amjad ali shah

        urtextboxname.text=urcomboboxname.selectedindex.text or simply write urtextboxname.text=urcomboboxname.text

        R Offline
        R Offline
        rrrriiizz
        wrote on last edited by
        #3

        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?

        T A 2 Replies Last reply
        0
        • R rrrriiizz

          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?

          T Offline
          T Offline
          The ANZAC
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • R rrrriiizz

            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?

            A Offline
            A Offline
            amjad ali shah
            wrote on last edited by
            #5

            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

            T R 2 Replies Last reply
            0
            • A amjad ali shah

              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

              T Offline
              T Offline
              TwoFaced
              wrote on last edited by
              #6

              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
              
              1 Reply Last reply
              0
              • A amjad ali shah

                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

                R Offline
                R Offline
                rrrriiizz
                wrote on last edited by
                #7

                Thanks A lot it was working very nice. thanks for all the others for your reply. thanks

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups