Hi Jeff,

    Good and I understand having an example makes it much clearer for the 
Object Model section jumps around and is not very good in explaining without 
lots of trial and error.

    As I had stated last the Listview also can do the same thing you want using 
the same event but, it comes under control.text instead of items which is not 
explained at all in the object model where it just states go to the Event Info 
to get an explanation, which there is none.

    I kept getting no object errors until I just used the dControl.Text which 
is up in the Control section and not in the Control types section.

    You can use the very same technique if you only want to know the text 
change and nothing else. But in the ListBox you can also get and set the Index 
which you can not do in the Listview; but I may be mistaking based only on the 
description of the ListView Index setting and have not attempted to try it 
since there is no object inside the event we are using...for an Items.Index.

    Just in case you want to use this event for a list view, as I stated you 
can only use the control.text object.

    I have been too busy to explain it any better since I kept getting that no 
object error all the time because I was too stubborn in wanting to get my 
Listview version to work.

    Enjoy and I understand the need for an example since the documentation is 
very lacking for it.


        Take Care,
        Bruce


Sent: Wednesday, January 15, 2014 9:43 AM
Subject: RE: listbox change


Thanks Chip and Bruce.
Chip, Your example does work just the way I wanted it to.
After case ListboxSelectionChange, I was missing:

DialogEventHandler = True
queue "SaySelectedItem",  dObj.control("lst").text

I guess that I am a person who learns by concrete examples, and this is a good 
one.
Thanks
Jeff Weiss


-----Original Message-----
From: Chip Orange [mailto:[email protected]]
Sent: Tuesday, January 14, 2014 7:12 PM
To: [email protected]
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

Reply via email to