Following lines generates false YES message in CMake. Why?
set(A "YES")
if(${A})
message("true " ${A})
else()
message("false " ${A})
endif()
Related
MSVS_versions = Array _
( _
"VisualStudio.DTE.7", _
"VisualStudio.DTE.7.1", _
"VisualStudio.DTE.8.0", _
"VisualStudio.DTE.9.0", _
"VisualStudio.DTE.10.0", _
"VisualStudio.DTE.11.0", _
"VisualStudio.DTE.12.0", _
"VisualStudio.DTE.14.0" _
)
For each version in MSVS_versions
Err.Clear
Set dte = getObject(,version)
If Err.Number = 0 Then
Exit For
End If
Next
If Err.Number <> 0 Then
Set dte = WScript.CreateObject("VisualStudio.DTE")
Err.Clear
End If
dte.MainWindow.Activate
dte.MainWindow.Visible = True
dte.UserControl = True
dte.ItemOperations.OpenFile filename
if keyword is not nothing then
dte.ExecuteCommand "Edit.Find", """"
end if
I have this vba code. I'm interested in the second last line. I want to find a quotation mark in the current docurnet. When I run the code, Visual Studio tells me
---------------------------
Microsoft Visual Studio
---------------------------
The search pattern is invalid.
---------------------------
OK
---------------------------
How do I search quotation marks?
The parameters that dte.ExecuteCommand accepts are what we can input in Visual Studio's Command Window.
Command Window gives the same error as the OP found.
https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-window#escape-characters states the escape character is ^, thus you have to use dte.ExecuteCommand "Edit.Find", "^""" in order to find ".
As of all parameters of Edit.Find, see https://learn.microsoft.com/en-us/visualstudio/ide/reference/find-command
I am trying to create a sort of list that looks something like this:
echo thing1 thing2
echo.
Then a for loop to list text files in a directory and a bit of information like this:
echo %var% %var1%
echo %var% %var1%
rem and so on
But no matter what length the variable is, there will always be 11 spaces which puts it off a bit with the header.
I know I could make some code to detect the length and save a number of spaces in a variable and then add it on.
But I was just wondering if there is another more simple way.
There's no mention how exactly the strings are taken so I'll leave this to you.
Here's how you can set spaces between two variables and the result will have fixed length.
#echo off
rem http://ss64.org/viewtopic.php?id=424
set max_len=25
set "var11=thing1"
set "var12=thing2"
set "var21=thing1xxxxxx"
set "var22=thing2"
set "var31=thing1xxxxxx"
set "var32=thing2"
call :setSpaces var11 var12
call :setSpaces var21 var22
call :setSpaces var31 var32
goto :eof
:setSpaces var1 var2 [RtnVar]
setlocal EnableDelayedExpansion
set "var1=!%~1!"
set "var2=!%~2!"
call :strlen0 var1 len1
call :strlen0 var2 len2
set /a needed_spaces=%max_len%-%len1%-%len2%
rem echo %needed_spaces%
set "spaces="
for /l %%a in (1;1;%needed_spaces%) do (
set "spaces=!spaces! "
)
set line=%var1%%spaces%%var2%
endlocal&if "%~3" neq "" (set %~3=%line%) else echo %line%
exit /b 0
:strlen0 StrVar [RtnVar]
setlocal EnableDelayedExpansion
set "s=#!%~1!"
set "len=0"
for %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%N,1!" neq "" (
set /a "len+=%%N"
set "s=!s:~%%N!"
)
)
endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len%
exit /b
while clearing doubts one of my junior ask me the question "is it possible to set the text on a command button as " Clear & Exit " ?
i replied that " it is not possible, because for command button's text the '&' is used to set the key board shortcut", is my answer is correct? "is it possible to set the text on a command button as " Clear & Exit " ?
i had tried the following code segments:
Button7.Text = " clear " & "&" & "Exit"
Button7.Text = " clear " & Chr(38) & "Exit"
good responses are appreciated, thanks in advance
yes it is possible to set the text on a command button as " Clear & Exit "
try this
Button7.Text = "clear && Exit"
You can also use "&&" to display a single ampersand. Using this method, you could leave UseMnemonic with a value of True and place a single ampersand before another letter in the Caption to define an access key.
I am trying to uninstall a ClickOnce application programmatically using a VBS script. It works pretty well. But if the uninstall fails I want it to send a response "Application has already been removed".
The below is what I have so far, and it works for the most part. Sometimes the delay is not long enough or another window steals focus and the "OK" for sendkeys does not make it to the window.
--- Full Source Code ---
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "taskkill /f /im TEST.App.UI.exe*"
objShell.Run "rundll32.exe dfshim.dll,ShArpMaintain test.app.ui.application, Culture=neutral, PublicKeyToken=f77d770cef, processorArchitecture=msil"
Do Until Success = True
Success = objShell.AppActivate("Test App")
Wscript.Sleep 500
Loop
objShell.SendKeys "OK"
'Commented out on purpose
'install new
'objShell.Run ""
When tackling problems of logical control flow, it's best to start with a
story/description:
I want to start an uninstall process and wait for it to terminate with
either success or failure (indicated by opening a window with
appropriate title)
Never use comparison against True/False in conditions; that's just error-prone
fat.
Don't rely on VBscript's intelligence to convert non-booleans; use
variables/expressions of appropriate (sub) type in conditionals.
Remember that VBScript doesn't shortcut the evaluation of conditionals:
If This() Or That() Then
will call both functions, even if This returns True (and therefore the
whole clause must be True). So don't be tempted to do:
... Until (objShell.AppActivate("Uninstall - Success") Or _
objShell.AppActivate("Uninstall - Failure"))
When designing a loop, think about when the leave-checking should be done; if
you want to read from a possibly empty file, it makes sense to check early:
Do Until tsIn.AtEndOfStream
sLine = tsIn.ReadLine()
...
Loop
but if you want to get valid input from the user, you have to ask before
you can check:
Do
sInp = ...
Loop While isBad(sInp)
.AppActivate and .SendKeys are every programmer's foes; postpone fighting
against them, until you have the control flow problem solved.
In code:
' Wait Wait Fail Success
' , Array(False, False, True , True ) _ shouldn't happen, but will terminate too
Dim aHappenings : aHappenings = Array( _
Array(False, False, False, True ) _
, Array(False, False, True , False) _
)
Dim aTest
For Each aTest In aHappenings
WScript.Echo Join(aTest)
Dim bOk : bOk = False
Dim bFail : bFail = False
Dim i : i = 0
Do
bOk = aTest(i + 0)
bFail = aTest(i + 1)
WScript.Echo Join(Array(" ", i, bOk, bFail))
i = i + 2
Loop Until bOk Or bFail
WScript.Echo "Done."
WScript.Echo
Next
Output:
False False False True
0 False False
2 False True
Done
False False True False
0 False False
2 True False
Done.
You may exploit the fact, that either success or failure (not both) will happen:
Dim i : i = 0
Dim bDone
Do
bDone = aTest(i + 0)
If Not bDone Then
bDone = aTest(i + 1)
End If
WScript.Echo Join(Array(" ", i, bDone))
i = i + 2
Loop Until bDone
Found this Reboot Vista.vbs script on a number of forums. Seems like the whole post ( text including the code ) was posted on many forums. So I don't know who the original author is. Heres the code here:
Option Explicit
On Error Resume Next
Dim Wsh, Time1, Time2, Result, PathFile, MsgResult, MsgA, AppName, KeyA, KeyB, TimeDiff
MsgA = "Warning! Close all running programs and click on OK."
KeyA = "HKEY_CURRENT_USER\Software\RestartTime\"
KeyB = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr e ntVersion\Run\RestartTime"
AppName = "Boot Up Time"
Set Wsh = CreateObject("WScript.Shell")
PathFile = """" & WScript.ScriptFullName & """"
Result = wsh.RegRead(KeyA & "Times")
if Result = "" then
MsgResult = Msgbox (MsgA, vbOKCancel, AppName)
If MsgResult = vbcancel then WScript.Quit
Wsh.RegWrite KeyA & "Times", left(Time,8), "REG_SZ"
Wsh.RegWrite KeyB, PathFile, "REG_SZ"
Wsh.Run "cmd /c Shutdown -r -t 00", false, 0
else
Wsh.RegDelete KeyA & "Times"
Wsh.RegDelete KeyA
Wsh.RegDelete KeyB
TimeDiff = DateDiff("s",Result,left(Time,8))
MsgBox "Your system reboots in " & TimeDiff & " seconds", VbInformation, AppName
end if
wscript.Quit
It is supposed to reboot Vista, and once it is rebooted, show the time it took to reboot.
It reboots fine and everything, but the dialog box doesn't pop up. I have to manually click on the script again for the time to appear ? I think that defeats the purpose of the script don't you ?
Any help would be much appreciated fellas.
You cannot have spaces in the regpath: Change "Curr e ntVersion" to "CurrentVersion"
This row:
Wsh.RegWrite KeyB, PathFile, "REG_SZ"
will register the script to autostart with windows if the PathFile and KeyB is correct, but with spaces in "Curr e ntVersion" it will not work.
Maybe you are getting an error which is preventing the display of the message box? This line you have at the start of the script will cause it to ignore all errors:
On Error Resume Next
You should simply delete this line, then run it again and see what is happening.