Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IntelliUser

macrumors 6502
Original poster
Nov 1, 2009
376
4
Why does it matter?
Hello,

I'm trying to do something but I need some help.

Basically I have a PopupMenu, and when one of the values is selected, some other values are displayed in 3 text fields.

Now I want to do something like this

Array that contains PopupMenu options, containing " ", "a" and "b"
Array containing the values displayed in the Text field, containing " ", " ", " ", "bla", "blabla", "blablabla", "da","dada", "dadada".

Now I want that when a user selects " ", the first 3 values of the second array appear respectively in 3 Text fields. If he selects "a", the second 3 values and so on.

Note: I want to avoid doing an If statement for each possibility, so that I can just add more values to the two arrays in the future and have the program do the rest.
How can I do it?
 
I don't know RB, but it sounds like you want to use an index value.

If the Popup has the option of returning a numeric value (or deriving it somehow) for the position selected, then that can be used to use gain access to the second array. Assuming your array positions start at zero, it might be 1 in RB, here is what you want. If RB uses 1, I'll leave it to you to figure out the math.

Here is some pseudo code to get the idea. Notice how the formula for the three assignments repeats.

Code:
popupvalue returns 0, text1 = arrary2[popupvalue * 3]
popupvalue returns 0, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 0, text3 = arrary2[popupvalue * 3] + 2

popupvalue returns 1, text1 = arrary2[popupvalue * 3]
popupvalue returns 1, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 1, text3 = arrary2[popupvalue * 3] + 2

popupvalue returns 2, text1 = arrary2[popupvalue * 3]
popupvalue returns 2, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 2, text3 = arrary2[popupvalue * 3] + 2
So instead of if statements, you have

Code:
text1 = arrary2[popupvalue * 3]
text2 = arrary2[popupvalue * 3] + 1
text3 = arrary2[popupvalue * 3] + 2

Another way to do this is with a dictionary. The dictionary key would equal your popup values and the dictional value would be an ordered array with your replacement values. This is may be less prone to errors.
 
Consider going to the RB forums, where there are quite a few people who I'm sure can help. Props to MacRumors users and any answers you get, but that RB forum is at the source.
 
I don't know RB, but it sounds like you want to use an index value.

If the Popup has the option of returning a numeric value (or deriving it somehow) for the position selected, then that can be used to use gain access to the second array. Assuming your array positions start at zero, it might be 1 in RB, here is what you want. If RB uses 1, I'll leave it to you to figure out the math.

Here is some pseudo code to get the idea. Notice how the formula for the three assignments repeats.

Code:
popupvalue returns 0, text1 = arrary2[popupvalue * 3]
popupvalue returns 0, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 0, text3 = arrary2[popupvalue * 3] + 2

popupvalue returns 1, text1 = arrary2[popupvalue * 3]
popupvalue returns 1, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 1, text3 = arrary2[popupvalue * 3] + 2

popupvalue returns 2, text1 = arrary2[popupvalue * 3]
popupvalue returns 2, text2 = arrary2[popupvalue * 3] + 1
popupvalue returns 2, text3 = arrary2[popupvalue * 3] + 2
So instead of if statements, you have

Code:
text1 = arrary2[popupvalue * 3]
text2 = arrary2[popupvalue * 3] + 1
text3 = arrary2[popupvalue * 3] + 2
That is what I have been thinking and trying to do for hours without success, I can't seem to find out how to get the current position from PopupMenu.
Another way to do this is with a dictionary. The dictionary key would equal your popup values and the dictional value would be an ordered array with your replacement values. This is may be less prone to errors.
Have't got much experience with dictionaries, but I suppose it would require the popupmenu value, right?

Consider going to the RB forums, where there are quite a few people who I'm sure can help. Props to MacRumors users and any answers you get, but that RB forum is at the source.

I can't seem to be able to register there, they won't accept my email, even though I downloaded all the demos available on the site...
 
I'm not sure but it maybe listindex you are looking for. As in
Code:
popupvalue.listindex

Surely RB has a Help menu. Look there for answers.
 
I'm not sure but it maybe listindex you are looking for. As in
Code:
popupvalue.listindex

Surely RB has a Help menu. Look there for answers.

This code doesn't work completely:

Code:
  Dim a() as String
  a = Array ("A", "B", "C")
  
  TextField1.Text = a(PopupMenu1.ListIndex)

TextField1 gets stuck at A. Any idea?
 
As I said, I'm not an RB programmer. So, no, I have no further ideas.

Typically when things are not turning out as expected, a common practice is to debug he the code. The simplest technique is to print out the value of concern to see what it is returning.

If you are learning RB, I suggest you get a book. If you can't afford one, try the library.
 
This code doesn't work completely:

Code:
  Dim a() as String
  a = Array ("A", "B", "C")
  
  TextField1.Text = a(PopupMenu1.ListIndex)

TextField1 gets stuck at A. Any idea?

Where are you putting this code?

When I put it into the PopupMenu1's change event it works just fine.

Although I did have to rename EditField1 to TextField1 to match your code.
 
Where are you putting this code?

When I put it into the PopupMenu1's change event it works just fine.

Although I did have to rename EditField1 to TextField1 to match your code.

You're right, I was putting it in the window. Silly me.

PS: EditField1 is named TextField 1 in the latest version(s?)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.