![]() |
KnowBrainer Speech Recognition | ![]() |
Topic Title: Advanced Scripting libraries Topic Summary: Where are they Created On: 05/15/2023 01:08 AM Status: Post and Reply |
|
![]() |
![]() |
- Steve Morris | - 05/15/2023 01:08 AM |
![]() |
![]() |
- Matt_Chambers | - 05/15/2023 05:36 AM |
![]() |
![]() |
- Steve Morris | - 05/15/2023 05:24 PM |
![]() |
![]() |
- Steve Morris | - 05/15/2023 11:01 PM |
![]() |
![]() |
- Mav | - 05/16/2023 01:50 AM |
![]() |
![]() |
- Steve Morris | - 05/16/2023 05:25 PM |
![]() |
![]() |
- Steve Morris | - 05/16/2023 07:42 PM |
![]() |
![]() |
- Mav | - 05/17/2023 01:42 AM |
![]() |
![]() |
- Matt_Chambers | - 05/16/2023 07:41 AM |
![]() |
![]() |
- MDH | - 05/17/2023 03:50 PM |
![]() |
![]() |
- monkey8 | - 05/17/2023 04:52 AM |
![]() |
|
In the ActiveX Automation Members window of the Advanced Scripting window in Dragon Pro 16, how do you get references: "OLE Automation", "Microsoft Scripting Runtime", "Microsoft Visual Basic for Applications Extensibility 5.3", and "Windows Script Host Object Model." I only have DgnMyCommands and DNSTools.
-------------------------
Steve |
|
|
|
![]() |
|
Press Alt+Enter, then scroll down, and check the boxes for those references. They are there in Dragon 16.
|
|
|
|
![]() |
|
Oops. Cheers
-------------------------
Steve |
|
|
|
![]() |
|
I am so not a coder. It hurts my little brain. Does anyone have any insights as to what I am doing wrong in this script. It is an attempt to create a list of open windows. I know Dragon already does it. But I am trying to understand how do to this stuff and I am missing something critical. '#Language "WWB-COM" Option Explicit Sub Main() ' Constants Const GW_CHILD As Long = 5 Const GW_HWNDNEXT As Long = 2 ' Declarations Dim hWnd As Long Dim sCaption As String Dim iNumWindows As Integer Dim sWindows() As String Dim i As Integer Dim dlg As Object Dim iSelected As Integer Dim Shell As Object ' Get handle to shell object Set Shell = CreateObject("WScript.Shell") ' API Declarations Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wCmd As Long) As Long Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpWindowText As String, ByVal nMaxCount As Integer) As Long ' Call API functions Function MyGetWindow(ByVal hWnd As Long, ByVal wCmd As Long) As Long MyGetWindow = GetWindow(hWnd, wCmd) End Function Function MyGetWindowText(ByVal hWnd As Long, ByVal lpWindowText As String, ByVal nMaxCount As Integer) As Long MyGetWindowText = GetWindowText(hWnd, lpWindowText, nMaxCount) End Function ' Count the number of visible windows hWnd = MyGetWindow(0, GW_CHILD) Do While hWnd <> 0 If IsWindowVisible(hWnd) Then iNumWindows = iNumWindows + 1 End If hWnd = MyGetWindow(hWnd, GW_HWNDNEXT) Loop ' Store the window captions ReDim sWindows(0 To iNumWindows - 1) As String i = 0 hWnd = MyGetWindow(0, GW_CHILD) Do While hWnd <> 0 If IsWindowVisible(hWnd) Then sCaption = Space(256) MyGetWindowText hWnd, sCaption, Len(sCaption) sWindows(i) = sCaption i = i + 1 End If hWnd = MyGetWindow(hWnd, GW_HWNDNEXT) Loop ' Show the list of open windows to the user Set dlg = New SelectWindow For i = 0 To iNumWindows - 1 dlg.WindowsList.AddItem sWindows(i) Next i iSelected = dlg.Show() ' Bring the selected window into focus If iSelected >= 0 Then Set Shell = CreateObject("WScript.Shell") Shell.AppActivate sWindows(iSelected) End If End Sub -------------------------
Steve |
|
|
|
![]() |
|
Hi Steve! One of the most impoprtant things when asking for help (especially with a programming-related program) is to be as precise as possible.
You wrote one line what you want to achive, but don't tell us why the code you posted doesn't do what you want. Are there any errors? Is the behavior different from what you expect?
Just for fun I fed your code into ChatGPT and asked it to explain the code. This is the result: This Visual Basic code is used to create a script that lists all open windows and allows the user to select a window to bring into focus. Here's a breakdown of the code: Even with the free version you can use it in a situation like this very efficiently. hth |
|
|
|
![]() |
|
Oh well. -------------------------
Steve |
|
|
|
![]() |
|
Sorry. I was assuming too much. It fails all over the place. The declarations of functions returns "unterminated block statement" variable keep saying they need to be defined. For this reason, I thought it might have been something obviously stupid I was missing. I will keep working at it. Thanks. -------------------------
Steve |
|
|
|
![]() |
|
I think the most important skill you have to learn is how to debug effectively. The script editor in Dragon is not really well-suited for this task, I'm afraid.
But if you get the information which variables are not declared that's a first step.
You can either declare all remaining variables or remove the "Option Explicit" statement, in which case variables are declared the first time they're being used. While it's annoying having to declare each variable, it still offers an additional layer of protection against typos, mostly.
Cheers mav |
|
|
|
![]() |
|
Yes, ChatGPT is very good at code. Not very good at much else, but that's for another forum.
|
|
|
|
![]() |
|
"Yes, ChatGPT is very good at code. Not very good at much else, but that's for another forum."
Well, upon further reflection, maybe that is not the case:
ChatGPT Egg Balancing Task Convinced Microsoft That AGI Is Closer (businessinsider.com)
MDH ------------------------- |
|
|
|
![]() |
|
I would say that the Dragon debugger is more than adequate to resolve the issue and what you're missing is programming experience in VB. The first thing you need to do is look at the format/organisation of the script. Looks like VB code possibly taken straight from Google. It is not in the correct format and syntax for a WinWrap basic script. What Is the Structure of a WinWrap Basic Script? Taking it stage by stage this is what I would do in terms of organisation of the script(there are other ways):
1) Declare your variables, constants and functions and then declare the Sub Main which calls on the variables, constants and declared functions.
Constants Variables Functions Sub Main
2) So the first thing wrong with the script is that the Sub Main is declared on line 5 in the wrong syntax. Remove the Sub Main from line 5 (in other words remove line 5) and then run the debugger, you run the debugger by green play button.
3) The debugger will then fail on line 22 Set Shell = CreateObject ("WScript.Shell")
Again you need programming experience to understand the issue but I would set the initialisation within Sub Main. So remove this line, copying it to insert later. Run the debugger again. This time the debugger will run through all the constant declarations, all the variable declarations and all the function declarations and then fail on the line hWnd = MyGetWindow(0, GW_CHILD) . The reason for this is the these lines should be declared within your Sub Main so you need to insert your Sub Main (which we removed earlier) just before the failing line and also add the other line of code we removed earlier (Set Shell = CreateObject ("WScript.Shell").
So this then leaves us with the following script, run the debugger on the script below and then carry on your debugging from there(Clue: From the failing line onwards it's not in a WinWrap basic style/form for displaying a dialogue. ):
'#Language "WWB-COM" Option Explicit ' Constants Const GW_CHILD As Long = 5 Const GW_HWNDNEXT As Long = 2 ' Variables Dim hWnd As Long Dim sCaption As String Dim iNumWindows As Integer Dim sWindows() As String Dim i As Integer Dim dlg As Object Dim iSelected As Integer Dim Shell As Object ' Windows API Function Declarations Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wCmd As Long) As Long Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpWindowText As String, ByVal nMaxCount As Integer) As Long ' Your Function Declarations Function MyGetWindow(ByVal hWnd As Long, ByVal wCmd As Long) As Long MyGetWindow = GetWindow(hWnd, wCmd) End Function Function MyGetWindowText(ByVal hWnd As Long, ByVal lpWindowText As String, ByVal nMaxCount As Integer) As Long MyGetWindowText = GetWindowText(hWnd, lpWindowText, nMaxCount) End Function ' Main Routine Sub Main
Sub Main hWnd = MyGetWindow(0, GW_CHILD) Do While hWnd <> 0 If IsWindowVisible(hWnd) Then iNumWindows = iNumWindows + 1 End If hWnd = MyGetWindow(hWnd, GW_HWNDNEXT) Loop ' Store the window captions ReDim sWindows(0 To iNumWindows - 1) As String i = 0 hWnd = MyGetWindow(0, GW_CHILD) Do While hWnd <> 0 If IsWindowVisible(hWnd) Then sCaption = Space(256) MyGetWindowText hWnd, sCaption, Len(sCaption) sWindows(i) = sCaption i = i + 1 End If hWnd = MyGetWindow(hWnd, GW_HWNDNEXT) Loop ' Show the list of open windows to the user Set dlg = New SelectWindow For i = 0 To iNumWindows - 1 dlg.WindowsList.AddItem sWindows(i) Next i iSelected = dlg.Show() ' Bring the selected window into focus If iSelected >= 0 Then Set Shell = CreateObject("WScript.Shell") Shell.AppActivate sWindows(iSelected) End If 'End of main routine End Sub ------------------------- |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2023 FuseTalk™ Inc. All rights reserved.