everybody, please PLEASE read

whosyodaddy

Well-known member
Joined
Jun 23, 2003
Messages
83
Hello everybody. I need some help to finish creating this project of mine. I have one Listbox, named Listbox1, a button, named Button1, and another Listbox, named Listbox2. When a user clicks on a certain text in Listbox1, then clicks Button1, how do i make it so that certain text comes up in Listbox2? For example: There are 5 different things listed in Listbox1, i select one of them, then click Button1, and then certain text for the thing i selected in Listbox1 comes up in Listbox2. How do i do this? If you give me code please tell me where to put it. Thank you! Help would be appreciated over and beyond.
 
thanks for the link, that explains if something in the two boxs are the same. but what about the Button??
 
you mustve not read clearly, what about when clicking on something in Listbox1, for example "Cat" in listbox1, then press the button, then "Dog" appears in Listbox2. HOW!??!
 
You could store the two things in two arrays:
Code:
Dim stuff1 As String() = New String() {"Dog", "Up", "Black", "Day", "On"}
Dim stuff2 As String() = New String() {"Cat", "Down", "White", "Night", "Off"}
Then you find the position of the word you want in the first array, and use that position to extract the word from the second array. For example:
Code:
Private Function FindOpposite(word As String) As String
  Dim position As Integer = Array.IndexOf(stuff1, word)
  
  If position >= 0 Then
    Return stuff2(position)
  Else
    Return ""
  End If
End Function
I believe something like that will work. For example, FindOpposite("Up") will return "Down", etc. Just make sure that the two corresponding words in the arrays are at the same position; for example, "Day" and "Night" are both at position 4 in the two arrays.
 
Last edited by a moderator:
im sorry to say that all of you were wrong.

here is the right code i needed:

Dim s As String
Dim i As Integer

ListBox2.Items.Clear()
i = ListBox1.SelectedIndex()
s = ListBox1.SelectedItem()

this is a test
If (s.Equals("Something")) Then
ListBox2().Items.Add("What Something?")
ElseIf (s.Equals("007 Agent Under Fire")) Then
ListBox2().Items.Add("Bam!")
End If

so just incase somebody asks a similiar question you can answer it right ;-)
 
Actually, the code I posted is much more efficient, and easier to expand. You just need to make sure not to add "" to the listbox if necessary, and it will work exactly how you want.

If the elements in stuff1 are "Something" and "007 Agent Under Fire", and the elements in stuff2 are "What Something" and "Bam!", it will work the way you posted.

Just do
Code:
List2.Items.Add(FindOpposite(s))
 
well, i changed listbox2 to a textbox. i have the code and stuff. i am going to be making over 500 selections in Listbox1, and about 2 paragraphs text that will appear in Textbox1 for EACH selection in Listbox1. what would be the easiest method (code) for this? im not just doing one word like "dog" and "white". its more like this length:

"muchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewords".

so please help and tell what you would do.
 
The answer you have found, hardly matches your actual description for what you wanted. Its just hard coded IF statments rather then dynamic arrays for multiple links for multiple results.

There are people in this forum who could boggle your brain with what they know about coding.
 
Back
Top