how to replace text in listbox to textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joelin139
    New Member
    • Mar 2014
    • 2

    how to replace text in listbox to textbox

    Dear Guru,
    i have listbox data :

    morning;Good Morning
    evening;Good Evening
    afternoon;Good Afternoon

    i have text1 text2 and command1 so what i want is like this

    when text1 enter morning command1 click text2 will show Good Morning
    when text1 enter evening command1 click text2 will show Good Evening
    when text1 enter afternoon command1 click text2 will show Good Afternoon

    please help me thanks
  • kiad198
    New Member
    • Mar 2014
    • 2

    #2
    I hope this will help you!

    Code:
    Private Sub Command1_Click()
    If Text1.Text = "morning" Or Text1.Text = "Morning" Then
       Text2.Text = "Good Morning"
    ElseIf Text1.Text = "afternoon" Or Text1.Text = "Afternoon" Then
        Text2.Text = "Good Afternoon"
    ElseIf Text1.Text = "evening" Or Text1.Text = "Evening" Then
        Text2.Text = "Good Evening"
    End If
    End Sub

    Comment

    • Honduras2811
      New Member
      • Apr 2014
      • 21

      #3
      Do you really need the listbox? From what you posted it appears that you don't. The previous answer doesn't use the listbox either.

      If you don't need to use the listbox, the previous answer should work fine. The only change I would make is
      Code:
      If LCase(Text1.Text) = "morning" Then
         Text2.Text = "Good Morning"
      If you have to use the listbox, all you need to do is:
      1. loop through it using InStr to search for the string that is in TextBox1.Text
      2. If found, copy the list item to a string variable and use InStr to find the location of the comma.
      3. Use Right$ to get everything after the comma.
      4. Put that into Text2.Text

      Does that seem reasonable?

      Comment

      Working...