Hi Rick,
It is a good idea, but exactly how organized do you think I am? I'm
usually
working on those examples right up to class time! Still, here they are
below as it stands right now:
' class #6 examples: (3/27/2011)
' example 1 (this was example 5 last week, but not discussed or documented
properly)
' display a list of all the files in a given folder, whose name is passed
in
as a parameter to this sub.
' This uses an object supplied by Windows, so it's available to any
programming environment: the scripting.filesystemobject.
' this object is documented at the site:
http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx
' below is a sub you can call from within your app; it's meant for you to
call it specifying a folder name as the parameter.
sub ShowFolderList(folderspec)
' folder spec is a string, passed in, which is the name of the folder.
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject") ' creates an
fileSystem
object, but it has no data
Set f = fso.GetFolder(folderspec) ' creates a folder object, holding the
data from the given folder
Set fc = f.Files ' creates a files object, which is a "collection" of file
objects, holding data from the folder
' (a collection is an object which is something like an array in that it
holds a list of objects;
' but all of them must be the same type, and you don't "dimension" the
list
ahead of time to tell it how many objects there may be
' (which means there is no limit to how many are in the list)).
' now loop through all the files in the "collection",
' adding their names to a growing string, with a carriage return after
each
name.
' you can use a special command to loop through collections, it is the
"FOR
EACH ... NEXT" loop,
' and you don't have to use numbered indexes to get to each member of the
collection; instead, each member is put into a temporary loop control
variable.
' (note: the FOR EACH loop will also work just as well on arrays, but it
does count on every element in the array having some data).
s = ""
For Each f1 in fc
' f1 is the temporary loop control variable,
' and holds the current file object from the collection the loop is
currently processing.
s = s & f1.name & vbCR
' adds the name from the current file object to the string of file names
being built and follows it with a carriage return
Next
msgBox "This directory has " & fc.count & " files:" & vbcr & s
' collections almost always have a .count property
Set fso = nothing
set f = nothing
Set fc = nothing
End sub
' note that when working with collections, the order of their members
might
change (say a new file is added to a directory; it might appear as the
first
collection member).
' This isn't true of arrays; it's assumed an element's numerical index in
the array will stay the same while working with the array.
' end of example 1
' example 2
' using a WE object model object (which are *all* built-in).
' main body
Dim myHotkey
' below uses a method of the built-in WE keyboard object to associate a
hotkey with a subroutine of your app
Set myHotkey = Keyboard.RegisterHotkey ("Control-Shift-1",
"hotkeyHandler")
' it's important to know the result of the registerHotkey method (or
function) must be stored in a global variable or it will not work
properly.
' the keyboard object is one of the "root level" objects; that is, not
only
is it built-in, but you do not have to go through any other object to get
to
it.
' the "root level" objects are all the properties and methods of the
window-eyes application object (found in the app developers manual).
' "root level" objects are described and listed in the GW wiki article at:
http://www.gwmicro.com/mediawiki/index.php/So_you_want_to_write_a_script%3F
' end of main body
Sub hotkeyHandler()
' this sub is called when the hotkey is pressed.
' (this is very much like an event handler, but is called a "callback").
MsgBox "Hello World!"
End Sub
' end of example 2
' example 3
' shows an event handler.
' this uses the WE built-in SPEECH object, and it's onSpeak event.
' Determines if the selected synthesizer is the DECtalk Access32
(Window-Eyes), and if so
' prepends the phrase "DECtalk Says:" to the string about to be spoken.
' main body
ConnectEvent Speech, "OnSpeak", "OnSpeak"
' end of main body
Function OnSpeak(originalString)
' event handler for the onSpeak event.
OnSpeak = originalString
' returns the original string (so it will be spoken), in case it's not
dec-talk speaking
If Synthesizer.Description = "DECtalk Access32 (Window-Eyes)" Then
OnSpeak = "DECtalk Says: " & originalString
End If
End Function
' Now, every string spoken when the DECtalk Access32 (Window-Eyes)
synthesizer is selected
' will begin with "DECtalk Says."
' end of example 3
' example 4
' shows an event handler using the QUEUE method.
' this uses the same event as example 3, but it needs to do something
which
takes a little time;
' and this is not allowed in an event-handler, so you must use the "QUEUE"
method, to cause the time-consuming portion to be executed later.
' main body
dim onSpeakID
onSpeakID = ConnectEvent (Speech, "OnSpeak", "OnSpeak")
' onSpeakID now holds an identifier for this event handling which can be
used to stop handling this event by passing it to the DISCONNECT method.
' end of main body
Function OnSpeak(originalString)
' event handler for the onSpeak event.
' it looks for lines which mention Chip Orange, and if found, writes them
to
the end of a file.
OnSpeak = originalString
' returns the original string (so it will be spoken), in case it's not
dec-talk speaking
IF inStr(UCase(originalString), "CHIP ORANGE") then
' this line mentions Chip Orange
' need to write this line to the end of a file, but that would take too
long
in an event handler,
' so delay a sub for execution later, in a separate thread, to do this.
queue "saveString", originalString
end if
End Function
sub saveString(theLine)
' appends this string to the end of a specific file
' this gets executed by the queue method, so it happens a fraction of a
second later, and sort of in a separate program, not where and when the
command is placed.
dim oText, oFS
Set oFS = CreateObject("Scripting.FileSystemObject") ' creates an
fileSystem
object, but it has no data
Set oText = oFS.OpenTextFile("c:\temp\lines.txt", 8, False) ' 8 is the
appending mode of opening
oText.WriteLine (theLine) ' appends the line to the file
oText.close
set oText = nothing
set oFS = nothing
end sub
' end of example 4
-----Original Message-----
From: RicksPlace [mailto:ofbgm...@mi.rr.com]
Sent: Sunday, March 27, 2011 7:49 AM
To: gw-scripting@gwmicro.com
Subject: Re: tomorrow's online scripting class
Hi Chip: The classes are going fine. My only idea would be to release the
sample code or documents one day prior to the class on your site. That way
we could load them up, read through them to formulate questions in our
mind
and do a little browsing of the Windoweyes Documentation prior to the
class.
It would also allow us to ask questions or allow you to comment on code in
a
particular line of code or group of lines of code.
If everyone has the same code blocks and line numbers in their editors we
could alt tab to the code samples and step through them one line at a time
with you as you describe what is going on.
That is just a thought and I might bring it up tonight or you can mention
it
or just tell me if not a good idea so I don't bring it up or whatever...
I'm easy and grayteful you are doing this for us and just want to be
helpful.
Rick USA
----- Original Message -----
From: "Chip Orange" <lists3...@comcast.net>
To: <gw-i...@gwmicro.com>; <gw-scripting@gwmicro.com>
Sent: Saturday, March 26, 2011 6:05 PM
Subject: tomorrow's online scripting class
Hi all,
just an FYI that in tomorrow's online scripting class, we'll be moving
away from basic VBScript programming, and into object-oriented
programming, using window-eyes objects for examples, and discussing
the differences between the window-eyes VBScript environment and the
standard VBScript environment.
we're beginning to cover all of the window-eyes objects, and examples
which show how they're used, and how a scripter would go about solving
various types of problems.
Anyone wishing to participate in the live online TeamTalk class can
drop me an email for the scripting.tt file to be used with TeamTalk at
7 pm on Sunday evenings, EDT.
Those who wish to follow the class using the recordings can obtain the
audio archives from the site at:
http://acorange.home.comcast.net/scripting
there's also an RSS link there for those who use podcasting agrogators.
It's my opinion however, especially as we move out of standard
VBScript, and into WE specific scripting, that everyone will get more
out of the classes if you show up to the live sessions and ask
questions. You're welcome to ask your favorite script author if
he/she will take a session and talk about a topic of interest.
I'd appreciate hearing from those who are following the audio
archives/podcasts as to how well you're finding the classes: are we going
too fast or too slow, etc.
thanks.
Chip
acora...@comcast.net