KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Camel Case
Topic Summary: A simple, open-ended version
Created On: 05/27/2023 03:29 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Camel Case   - Edgar - 05/27/2023 03:29 PM  
 Camel Case   - awomanonwheels - 05/31/2023 11:07 AM  
 Camel Case   - awomanonwheels - 05/31/2023 12:22 PM  
 Camel Case   - Edgar - 05/31/2023 02:17 PM  
 Camel Case   - Edgar - 05/31/2023 02:28 PM  
 Camel Case   - awomanonwheels - 05/31/2023 03:19 PM  
 Camel Case   - Alan Cantor - 05/31/2023 02:12 PM  
 Camel Case   - awomanonwheels - 05/31/2023 03:23 PM  
 Camel Case   - Edgar - 05/31/2023 05:25 PM  
 Camel Case   - awomanonwheels - 05/31/2023 06:16 PM  
Keyword
 05/27/2023 03:29 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1405
Joined: 04/03/2009

awomanonwheels said, in a private message…

“Hello Edgar,

a few years ago you answered a query of mine regarding using a command to camel case two words, with the first word lowercase and the second word capitalized…”

Asking about extending this and making it open-ended; then suggested that my reply might be better on the open forum, so…

Until it comes to doing error checking on the initial open-ended ListVar1, this is a fairly straightforward software challenge.

1) trim all leading and trailing white spaces

2) [the error checking part] handle inappropriate characters*

3) split what is left into an array of individual words

4) force the first letter of the first word to be lowercase

5) force the first letter of all the rest of the words to be uppercase

6) combined all the resulting words together into a single word with no white space

Our Advanced Scripting command might be named something like: “camel case <dictation>” (it does not matter what you call it as long as it has only a single open-ended list variable). here is the code:

'#Language "WWB-COM"

Option Explicit

Sub Main
    Dim words() As String' dimension a string array
    Dim dictation As String
    Dim k As Integer
    Dim result As String

    ' dictation = CleanUpAllErrors (ListVar1)
    dictation = ListVar1' error checking turns out to be quite complicated
    words=Split(dictation, " ")' splits ListVar1 based on the space between words
    ' contrary to most basic arrays, words is zero-based
    words(0) = LCase(Left(words(0),1)) & Mid(words(0),2)' force the first word to lowercase its first letter
    For k = 1 To UBound(words)' start at 1 so we ignore the first word
        words(k) = UCase(Left(words(k),1)) & Mid(words(k),2)' force all the other words to uppercase their first letters
    Next
    For k = 0 To UBound(words)' start at 0 so we get all the words
        result = result & words(k)
    Next

    MsgBox result
End Sub


-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic & Shokz OpenComm UC version 1 wireless headset, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 05/31/2023 11:07 AM
User is offline View Users Profile Print this message

Author Icon
awomanonwheels
Top-Tier Member

Posts: 201
Joined: 09/21/2014

Good morning Edgar,
Thank you so much!!!

I have been looking for this since the day I got your reply! Unfortunately I was looking in the wrong areas. I finally thought to do an advanced search for your name. And lo and behold here you are!

I cannot wait to implement this code. And I will continue studying Visual Basic so that I can learn how to write this kind of code to help increase my utilization of Dragon.

Thank you, again!
Maritza
 05/31/2023 12:22 PM
User is offline View Users Profile Print this message

Author Icon
awomanonwheels
Top-Tier Member

Posts: 201
Joined: 09/21/2014

click okay click okay

Good morning Edgar,

I just copied and pasted your code into a new command and I got an "array out of bounds error" at line 15. Did my copy and paste go awry? How can I fix that?

 

I named my command "Zotz Words" and uttered the command "Zotz Words whiskey tango foxtrot"

 

  1.     Option Explicit On


  2.     Sub Main()
  3.         Dim words() As String ' dimension a string array
  4.         Dim dictation As String
  5.         Dim k As Integer
  6.         Dim result As String


  7.         ' dictation = CleanUpAllErrors (ListVar1)
  8.         dictation = ListVar1 ' error checking turns out to be quite complicated
  9.         words = Split(dictation, " ") ' splits ListVar1 based on the space between words
  10.         ' contrary to most basic arrays, words is zero-based
  11.         words(0) = LCase(Left(words(0), 1)) & Mid(words(0), 2) ' force the first word to lowercase its first letter
  12.         For k = 1 To UBound(words) ' start at 1 so we ignore the first word
  13.             words(k) = UCase(Left(words(k), 1)) & Mid(words(k), 2) ' force all the other words to uppercase their first letters
  14.         Next
  15.         For k = 0 To UBound(words) ' start at 0 so we get all the words
  16.             result = result & words(k)
  17.         Next


  18.         MsgBox result
  19. End Sub

 

 

 05/31/2023 02:17 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1405
Joined: 04/03/2009

Did you name the command:

Zotz Words <dictation>

so that it has the open-ended dictation ListVar1?

Did you include the first line:

'#Language "WWB-COM"

which is said to be “optional”? What version of Dragon are you running?



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic & Shokz OpenComm UC version 1 wireless headset, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 05/31/2023 02:28 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1405
Joined: 04/03/2009

And, of course, once you get it working in the MessageBox, you will need to decide how you want to get the result into the target application.

You will probably want to force both leading and trailing spaces:
result = " " & result & " "

Next comes the decision of how you want to actually move the text:

SendKeys result, 1

or possibly use SendDragonKeys or SendSystemKeys (it all depends on the target application which works best but SendKeys seems to be generally reliable for most target applications).

A more heavy-handed but potentially more bulletproof method would be to put result on the clipboard then paste that clipboard content into the application (this relies on the fairly reasonable assumption that an application uses the common keyboard shortcut “control + v” to paste the content of the clipboard into itself:

Clipboard (result)

Wait 0.3' for most computers some delay is

          ' mandatory here but the amount varies considerably

SendKeys "^v", 1' if this is not the last line of your script you will need an additional:

Wait 0.3' optional



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic & Shokz OpenComm UC version 1 wireless headset, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 05/31/2023 03:19 PM
User is offline View Users Profile Print this message

Author Icon
awomanonwheels
Top-Tier Member

Posts: 201
Joined: 09/21/2014

I am an idiot. I forgot to include <dictation> in the name editor. As soon as I added that the message box popped right up. (The compounded words were beautiful to see)

I'm still using DPI 15.61. I'm waiting to see if my job will hook me up with Dragon 16. If I like it well enough I'll purchase it for my own PC.

Right now my primary target is Notepad++. I have not tried to get Visual Studio Code or Visual Studio 2022 to play nice with my Dragon commands. It never occurred to me to even try.

Are there any books you can recommend for learning Visual Basic? What I found at my public library and on Udemy.com still leaves me wanting.

Thank you again for this beautiful code! It truly facilitates my code writing!

Warm regards
Maritza

 05/31/2023 02:12 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4616
Joined: 12/08/2007

Hi Maritza,

Not sure why Edgar's excellent script isn't working for you. I made my own version based on his, and it does seem to work. My command is called Camel <dictation>

Option Explicit

Sub Main
Dim words() As String ' Dimension a string array
Dim dictation, result As String
Dim NumberOfWords, k As Integer

dictation = LCase(ListVar1) ' Lowercase the whole string

words = Split(dictation, " ") ' Split the string based on the space between words
NumberOfWords = UBound(words) ' Calculate number of words in the string

' Contrary to most basic arrays, words() is zero-based
' Nothing to do with words(0). It's already lowercase

' Uppercase the rest, starting at words(1)
For k = 1 To NumberOfWords
words(k) = UCase(Left(words(k),1)) & Mid(words(k),2) ' Uppercase the first letter of other words
Next

' Construct the camel-cased result
For k = 0 To NumberOfWords
result = result & words(k)
Next

MsgBox result
End Sub
 05/31/2023 03:23 PM
User is offline View Users Profile Print this message

Author Icon
awomanonwheels
Top-Tier Member

Posts: 201
Joined: 09/21/2014

Hi Alan,
The only reason Edgar's script did not work for me was because I'm an idiot who forgot to include <dictation> in the command name.

It is just another reminder for me to slow down, and think about what I'm doing, what I've done, and what I intend, before executing.

 05/31/2023 05:25 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1405
Joined: 04/03/2009

It looks like we are off to a good start here now. Notepad++ can be made to be reasonably Dragon-friendly (you will probably need to edit one of your INI files – there was a thread which included the details for this posted in the last couple of days).

For that application SendKeys should be completely adequate.

As for books on Basic, don't forget, Dragon Basic is not quite Visual Basic. However, it does help to learn Basic, last at least the fundamentals (it need not be Visual Basic), before, or while, learning Dragon Basic. I'm not going to try to suggest any specific books other than, possibly, the “… For Dummies” series – “Basic for Dummies” should be available in your local public library.

Don't forget, there is still a fairly large elephant in the room! Most Basic languages do not allow variable names to start with digits. Where “someVariableName” is fine “1someVariableName” is not. At some point it would be appropriate to start doing some error checking on <dictation> – at a bare minimum it should not start with a digit.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic & Shokz OpenComm UC version 1 wireless headset, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 05/31/2023 06:16 PM
User is offline View Users Profile Print this message

Author Icon
awomanonwheels
Top-Tier Member

Posts: 201
Joined: 09/21/2014

Thank you, Edgar! I will check my local library and see if they have anything in their e-book collection that can help me out.

I have already made adjustments to Notepad++'s INI file so that it would recognize the command "next variable" when there are open and close brackets on the page.

Thank you again!

Warm regards,
Maritza
KnowBrainer Speech Recognition » Commands, Scripts, and Macros - Dragon » Camel Case

Statistics
32617 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 115 guests browsing this forum, which makes a total of 115 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2023 FuseTalk™ Inc. All rights reserved.