Path to Segmented Control?

I have a SegmentedControl1 and a TextField1 on my window, but when I try to determine which segment is currently selected from with the TextField’s TextChange event, I get a “this item does not exist” error?

In the TextField code I have:

If SegmentedControl1.itemIndex = 0 then MsgBox("segment 0 ") else MsgBox("segment 1 ") End if

My code above works perfectly in the SegmentedControl’s action event, but not from the TextField?
Thank You.

[quote=107417:@Richard Summers]I have a SegmentedControl1 and a TextField1 on my window, but when I try to determine which segment is currently selected from with the TextField’s TextChange event, I get a “this item does not exist” error?

In the TextField code I have:

If SegmentedControl1.itemIndex = 0 then MsgBox("segment 0 ") else MsgBox("segment 1 ") End if

My code above works perfectly in the SegmentedControl’s action event, but not from the TextField?
Thank You.[/quote]

You see, Richard, your problem is related to the EventID problem you had yesterday. Some variables are only available within the event. In the case of the SegmentedControl, look at the top of the action event : Action(itemindex as integer).

The scope of ItemIndex is limited to the event. It is not a property of SegmentedControl.

If you want to know what was the last value of ItemIndex, create a global property in a module, for instance, LastItemIndex, and set it in the action event as such

LastItemIndex = ItemIndex

Then you can use LastItemIndex anywhere in your program. You can also create LastItemIndex in the window, its scope will then be limited to the window.

Ahhhhhh - That makes things a lot clearer.
I learn something every day - Thank You!

If you selection type is Single, you can loop through the Items() of the segmented control and find the one that is selected.

Function Value(Extends s as segmentedcontrol) as integer
   for i as integer = 0 to s.items.ubound
      if s.items(i).selected then return i
   next
   return -1   // no selection
end function

Thanks Tim.