Why do I have to prefix msgbox with VBA - prefix

msgbox "hello" does not work in my macro unless I prefix it with VBA.msgbox
anyone know why only in this macro I have to use prefix VBA.
in all my other macros I have never had to prefix it....???

Related

Test for a specific character with a .txt file (Applescript)

Hi Applescript Stackoverflow Community!
I am attempting to write a code in which a different action will occur depending on the 1st character of a .txt file. This is my code so far (I'm fairly new to Applescript so I'm sorry if this is a basic question).
if first character of "/Users/Goombado/Documents/applescript_test.txt" is 1 then
display dialog "Hi"
else
display dialog "Hello"
end tell
end if
Is it possible to do this in Applescript or not?
Thanks in advance :)
You're not so far.
1) instruction "end tell" should always be after a "tell application" instruction. But in this case, there is no need to call any application.
2) you need to tell the script to read the text file, and the file paths in script are using ":". You can use also paths with "/" separator, but then via posix conversion.
set C1 to first character of (read file "Users:Goombado:Documents:applescript_test.txt")
if C1 = "1" then
display dialog "Hi"
else
display dialog "Hello"
end if
Note : You should avoid to hardcode path and file name.

How to use Mac synthetic voice called from VBA code (through MacScript) to read non-Latin characters (Greek)

I'm facing a problem when trying to call AppleScript (MacScript) to read out aloud non-Latin characters from VBA on Mac Excel 2011 (e.g. text in specific Excel cells). The following code line is working fine to read French text using the synthetic voice "Audrey":
MacScript ("say """ & FrenchStrg & """ using ""Audrey""")
FrenchStrg e.g. "croissant"
However, when trying to use the same code for Greek using the synthetic voice "Nikos", as in
MacScript ("say """ & GreekStrg & """ using ""Nikos""")
GreekStrg e.g. "ούζο"
most of the string (in Greek characters) is interpreted as "_" and is therefore not read aloud (the command "say "ούζο" using "Nikos"" is working fine in the AppleScript editor). In some cases, a few letters may be interpreted as some special character and are read out accordingly, but I couldn't find a useful pattern.
When changing the standard language of Mac OsX from English to Greek, the characters are correctly recognized within the VBA editor and in a MsgBox. However, the output to MacScript is still not working. Does the VBA MacScript function only accept non-unicode text? Is there any solution?
Any help would be much appreciated!
Thank you #Zero for suggesting to use the clipboard. This did indeed solve the problem. Here is the final working code:
Cells(1, 1).Copy
MacScript ("say (the clipboard) using ""Nikos""")
This circumvents the problem of strings getting converted into non-unicode text.
I don't think this will work but to be sure you should try it anyway:
MacScript ("say """ & (GreekStrg as Unicode text) & """ using ""Nikos""")
Unicode Support AppleScript is now entirely Unicode-based.
Comments and text constants in scripts may contain any Unicode
characters, and all text processing is done in Unicode, so all
characters are preserved correctly regardless of the user’s language
preferences. For example, this script works correctly in AppleScript
2.0, where it would not have in previous versions:
set the Japanese_phrase to "日本語"
set the Russian_phrase to "Русский"
set the new_phrase to the Japanese_phrase & " and " & the Russian_phrase
return new_phrase

VBScript SQL select query clarification and variable substitution

I have read this entry (http://stackoverflow.com/questions/8513185/vbscript-to-correctly-re-format-a-delimited-text-file) many times and still do not understand the .Execute section.
WScript.Echo oTDb.Execute(Replace("SELECT * FROM [#T]", "#T", sTbl1)) _
.GetString( adClipString, , "|", vbCrLf, "" )
The pieces I am having trouble with are the [#T] and "#T".
I know it is the "#T" that is reading the filename in the schema file and and the [#T] must be using the "#T" as a substitute. What I cannot find out is where this is mentioned/spoken about.
Some addition questions I have are:
1. If the filename can be substituted with a variable then what else can?
2. What are the rules for maintaining variables
Do they have to start with the # symbol
Are there any reserved words
If they have to start with the # symbol, does the next character have to be a letter
As I am responsible for #Milton's worry/puzzlement:
There is no variable interpolation/substitution in VBScript. Other languages - e.g. Perl - will splice variables or even expression results into string literals when you mark the replacements with special symbols. No such funny letters in VBScript.
SQL dialects allow parameterized commands in which parts to be replaced are marked by ? and/or names prefixed by symbols like #. But here ADO never sees the #T - VBScript's Replace() function has interpolated the table name before the resulting strings is send to .Execute().
Building complex strings from parts (SQL statements, commandlines for .Run or .Exec, ...) by concatenation is cumbersome. The most important drawback is that you can't (proof) read the string anymore for all those " and &.
A simple workaround is to use Replace(), as in
[sResult = ] Replace("SELECT * FROM [#T]", "#T", sTbl1)
I used the # just for letting the placeholder stand out. As you would have to stack/nest the Replace() calls when you need more substitutions on the template, other strategies are worth considering:
writing a function that takes a template string and a dictionary of replacements to apply Regexp.Replace() to the string
using .NET's System.Text.StringBuilder and its .AppendFormat to do the slicing in a sprintf like style

Char to UTF code in vbscript

I'd like to create a .properties file to be used in a Java program from a VBScript. I'm going to use some strings in languages that use characters outside the ASCII map. So, I need to replace these characters for its UTF code. This would be \u0061 for a, \u0062 fro b and so on.
Is there a way to get the UTF code for a char in VBScript?
VBScript has the AscW function that returns the Unicode (wide) code of the first character in the specified string.
Note that AscW returns the character code as a decimal number, so if you need it in a specific format, you'll have to write some additional code for that (and the problem is, VBScript doesn't have decent string formatting functions). For example, if you need the code formatted as \unnnn, you could use a function like this:
WScript.Echo ToUnicodeChar("✈") ''# \u2708
Function ToUnicodeChar(Char)
str = Hex(AscW(Char))
ToUnicodeChar = "\u" & String(4 - Len(str), "0") & str
End Function

Regex to search for a word in a string in Visual Studio

I need to search all of my codebase for "Url" and replace it with "URL". If I search for Url in Visual Studio I also get all my variables with "Url" in it.
Anyone have a Regex I can use to only find Url within a quoted string e.g. "Use this Url:"?
Edit
I was looking looking for a quick and dirty way to find designer text and hard coded strings that had Url in the string and change them to URL.
What I really ended up needing was:
("[^"]*Url[^"]*")
And thanks to the tip from tghw who pointed out the :q shortcut in Visual Studio equates to:
(("[^"]*")|('[^']*'))
I realized I needed to use the first portion to find only the double quoated strings I was looking for.
Both this regex and a standard find with 'Match case' and 'Match whole word' yielded results with some strings I was hoping to not find but eliminated the code with 'Url' in it.
Visual Studio has a "quoted string" operator :q. If you search for :qUrl with 'Use: Regular expressions' and 'Match case' on, it should find all instances of "Url" only in strings.
Update: The above is incorrect. :q just searches for a quoted string, but you can't put anything into it. My testing was just showing cases that looked correct, but were just coincidentally correct. I think instead, you want something like:
^(:q*.*)*(("[^"]*Url[^"]*")|('[^']*Url[^']*'))(:q*.*)*$
If you just quickly want to search for a quoted string you can use the "Use Wildcards" Find Option in Visual Studio.
For example:
"*Url*"
I used the following to search only "whole words" (i mean: appearing with an space before an after or immedately after or before the " ):
(("[^"]*[ ]|")Url([ ][^"]*"|"))
For example this matches "test Url" and "Url test" but don't "testUrl".
"Use this (Url):", then you can replace $1 (or whatever syntax Visual Studio uses). You may need to escape the quotes, and I'm not sure if Visual Studio lets you parenthesize parts of the regex.

Resources