Bruce, I'm still confused as to what you're problem is.
Class # 31 shows how to deal with detecting when a listview selected item has changed. Chip -----Original Message----- From: LB [mailto:[email protected]] Sent: Wednesday, January 15, 2014 7:50 AM To: [email protected] Subject: Re: listbox change Hi Chip, My mistake, I am playing with the ListView and it has less features than the ListBox and tried to mention that. I also had no time to test it out and that makes it more confusing. For in the ListBox you have everything for setting and getting items but no columns which I wanted at first but may not use in the future. At least Jeff has an example he can use but I did try to stress that all the features he needed did exist in the ListBox but not the ListView. For when EventInfo is only given it defaults to the control and not it's items in some case, for there is just no control for a selected item; it says no object, and noticed it went to the control level instead. Buttons are nice but as I had stated, the keydown event and keyup even can be used to compensate for control loss by setting and resetting a flag. Hopefully Jeff can get his app running using the example and yes, having all the flags set for an app such as the Explicit is very important to reduce debug time. Bruce Sent: Tuesday, January 14, 2014 8:11 PM Subject: RE: listbox change Hi Jeff, I'm sorry to keep disagreeing with Bruce, but I did take your example, made several corrections, and it works just as expected. You have several places where your names in the vbs don't match the names in the xml, and you have a variable (or two) which aren't initialized (I think sButton was one of them). It might help if you added "option explicit" at the top of the vbs. Anyway, below is a modified version of your vbs example which speaks some extra text each time the selected listbox item changes. First yu'll hear We read the new listbox item, then you'll hear my modified example speak the same line with some added text at the beginning so you can tell it apart from what WE is speaking. Aside from correcting variable names, all I did was to add a test for the listboxSelectionChange event(and as Bruce pointed out), you do have to initialize it to start with, so that it will work the very first time; otherwise, it won't start working until the second time. option explicit Dialog "testlist.xml", "Dialoglistbox", "DialogEventHandler" Function DialogEventHandler(dObj, dEvent, dId, dControl) Dim Result : Result = "" If dEvent = dialogCreated Then dObj.Control("lst").Width = 800 BuildList dObj End If DialogEventHandler = False Select Case dEvent ' Process dialog events case ListboxSelectionChange DialogEventHandler = True queue "SaySelectedItem", dObj.control("lst").text Case dialogCreated DialogEventHandler = True Case buttonClicked If dId = "btnCancel" Then dObj.Close DialogEventHandler = True End If If dId = "BtnOk" Then Result = dObj.Control("lst").Text queue "SaySelectedItem", Result DialogEventHandler = True End If End Select End Function Function BuildList(dObj) dObj.Control("lst").Add "This is the first line in the listBox!" dObj.Control("lst").Add "Here is the second line." dObj.Control("lst").Add "Here is the third and longest line in the listbox!" dObj.Control("lst").FocusedIndex = 1 End Function Sub SaySelectedItem(Result) Speak "The item you selected was " & VbCrLf & Result End Sub Hth, Chip -----Original Message----- From: Jeff Weiss [mailto:[email protected]] Sent: Tuesday, January 14, 2014 12:12 PM To: [email protected] Subject: Re: listbox change I was unable to get any info while still in the list. I found another way to do what I wanted. I added an extra button, made it the default button with enter as its shortcut, and by pressing enter while still in the list, I can get extra information. That's not exactly what I wanted, but it's close. Below is a .vbs and a .xml file showing a simple listbox with 2 buttons. The files are nameed DialogListBoxFromScript.vbs DialogListBoxFromScript.xml If anybody wants to try to add something to the select case section to automatically speak additional information when you are just up or down arrowing through the list, I would certainly appreciate knowing how to do this. thanks again, Jeff Weiss ' DialogListBoxFromScript Dim IsVisible : IsVisible = 0 Dim myHotkey : Set myHotkey = Keyboard.RegisterHotkey("Alt-Control-Shift-I","LaunchDialog") Sub LaunchDialog() 'This routine is called when the hotkey is pressed. If isVisible = 0 Then Queue "DisplayDialog" End If End Sub Sub DisplayDialog() Dialog "DialogListBoxFromScript.xml", "Dialoglistbox", "DialogEventHandler" End Sub Function DialogEventHandler(dObj, dEvent, dId, dControl) Dim Result : Result = "" dObj.Control("lst").Width = 800 If dEvent = dialogCreated Then BuildList dObj, Result End If DialogEventHandler = False Select Case dEvent ' Process dialog events Case dialogCreated DialogEventHandler = True Case buttonClicked sButton = dControl.Text sButton = Replace(sButton, "&", "") Speak sButton If sButton = "Close" Then dObj.Control("lst").Clear dObj.Close Exit Function End If If sButton = "Ok" Then Result = dObj.Control("lst").Text SaySelectedItem dObj, Result Result = "" Exit Function End If End Select End Function Function BuildList(dObj, Result) dObj.Control("lst").Add "This is the first line in the listBox!" dObj.Control("lst").Add "Here is the second line." dObj.Control("lst").Add "Here is the third and longest line in the listbox!" dObj.Control("lst").FocusedIndex = 1 End Function Sub SaySelectedItem(dObj, Result) Sleep 200 Speak " " Speak "The item you selected was " & VbCrLf & Result Sleep 1000 End Sub ' here is the .xml file: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <wescriptui> <options> <languageorder> WE,OS,en-us </languageorder> </options> <language id="en-us"> <dialog id="Dialoglistbox" modal="yes"> ListBox from Script <group> <group> <static shortcut="l"> List </static> <listbox id="lst" sort = "no"> </listbox> </group> <group justify="center"> <button id="BtnOk" default="yes" widthclass="button" shortcut="Enter"> Ok </button> <button id="btnCancel" system="cancel" widthclass="button"> Close </button> </group> </group> </dialog> </language> </wescriptui> From: Chip Orange [mailto:[email protected]] Sent: Monday, January 13, 2014 12:21 PM To: [email protected] Subject: RE: listbox change Jeff, I don't see that you're initializing the variable Temp anywhere, and I also don't see that you are setting the focusedIndex property of the listbox anywhere (which is usually done when you add items to the listbox; you usually set it to 1 when you add your listbox items). Take out the line: If fObj("lst").FocusedIndex <> Temp Then And you should then hear something spoken each time your listbox item is changed. Chip From: Jeff Weiss [mailto:[email protected]] Sent: Sunday, January 12, 2014 10:33 PM To: [email protected] Subject: Re: listbox change Thank you for all of the suggestions. This is indeed my own xml listbox dialog and I can get the button to work but not the listbox change to register where I can do something when it changes. The list works fine and displays 12 spelling words. Here is the function: Function DialogEventHandler3(fObj, fEvent, fId, fControl) DialogEventHandler3 = False Dim Result : Result = "" fObj.Control("lst").Width = 200 If fEvent = dialogCreated Then BuildList fObj, Result End If DialogEventHandler3 = False Select Case fId Case fId = "lst" If fEvent = listboxSelectionChange Then If fObj("lst").FocusedIndex <> Temp Then Temp = fObj.Control("lst").FocusedIndex Result = fObj.Control("lst").Text Speak Result Speak Temp Speak "this is a test." Result = "" Exit Function End If End If Case "button_MainMenu" If fEvent = buttonClicked Then Speak "" Sleep 200 Speak "Returning to Main Menu" Sleep 200 fObj.Control("lst").Clear fObj.Close DialogEventHandler3 = True Exit Function End If Case Else If fEvent = dialogCreated Then DialogEventHandler3 = True Exit Function End If End Select End Function I must be missing something here. Please let me know what I am missing here. thanks Jeff Weiss Jeff Weiss, M.Ed. Director of Life Skills Rehabilitation Teacher World Services for the Blind 2811 Fair Park Blvd. Little Rock, AR 72204 Email: [email protected] www.wsblind.org The mission of World Services for the Blind is empowering blind or visually impaired adults in the United States and around the world to achieve sustainable independence. --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
