I need to do
if WinExist(%window%) {...}
however this doesnt work
%window% is set earlier to be equal to %3% which is a command line argument that should be only of type string pointing the AHK script to the window of intrest.
I tried replacing %window% with %3% however the code inside never gets run. Why?
Since WinExist() accepts a string parameter for the window title, you don't need to enclose the variable in %.
If you set window to the value of the 3rd command parameter then the following code should work.
window = %3%
if WinExist(window)
{
Msgbox, Exists.
}
else
{
Msgbox, Does not exist.
}
Note: windowor %3% must exactly match the window title, or you must use SetTitleMatchMode, 2
(see SetTitleMatchMode).
If WinExist(window)
is an expression, any variable names in its parameter should not be enclosed in percent signs.
By contrast, literal strings should be enclosed in double quotes:
If WinExist("Untitled - Notepad")
Related
What is the output of an InputBox command that is left empty
Is there a good way to check if the feild was left empty
like if OutputVar = "" { goto, restart }
i've tried the solution above and it didn't work for me any help is appreciated
This is what I use:
InputBox, text, Enter Text
if(text)
MsgBox Something was inputed
else{
MsgBox Nothing was inputed
goto restart
}
The output of an empty InputBox is not a value, so you can just check whether or not the variable you store the output as has a value or not through an if(variable) statement.
Edit responding to comment:
AHK is special in that you do not need a boolean value (i.e. True or False) within an if statement in order for it to work (in contrast to traditional programming languages). In ahk, if the value inside the parenthesis of an if statement is a non-boolean data type (i.e. a number), the program will treat it as true if the value is non-zero. This can be seen with the following code:
text:=0 ; Alternatively: text:=""
if(text)
MsgBox True was triggered!
else
MsgBox False was triggered!
Another Edit after I noticed something:
The idea behind the code you had above also works, provided that you move the curly braces/ content to the next line.
So either
if (text = "")
{
MsgBox hello
}
or
if (text = "")
MsgBox hello
is also fine.
I have
myVar.value = 123521#machine OK
now I'm using this variable with system command as it's an argument passed to a binary .exe
so I have to add quotes to myVar.value as it caontains spaces
I tried :
'''myVar.value''' but this will give 'myVar.value', whereas I just want to have the result equal to "123521#machine OK"
how could I use the quotes in this case ?
Try this:
x = ['"' myVar.value '"']
I think you can use double quote characters within strings demarcated by single quotes. Within a string demarcated by single quotes characters by doubling up:
x = ['''' myVar.value '''']
Help My Balloon finding macro is not working with input box, it works only when i manually add the balloon number.. please tell me what i m missing ...Ferdo m expecting you
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set selection1 = drawingDocument1.Selection
result = InputBox("Ballon Number ?", "Title") 'The variable is assigned the value entered in the InputBox
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= result ,all"
End Sub
I don't know what you are doing but the last line looks wrong. I don't know what the docs are for your function but you are passing the string result rather than the value of the variable result because it is in quotes. Assuming your line is otherwise right ...
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= " & result & ",all"
I am using an input box to request a string from the user that has the form "sometext5". I would like to separate this via regexp into a variable for the string component and a variable for the number. The number then shall be used in a loop.
The following just returns "0", even when I enter a string in the form "itemize5"
!n::
InputBox, UserEnv, Environment, Please enter an environment!, , 240, 120
If ErrorLevel
return
Else
FoundPos := RegExMatch(%UserEnv%, "\d+$")
MsgBox %FoundPos%
retur
n
FoundPos, as its name implies, contains the position of the leftmost occurrence of the needle. It does not contain anything you specifically want to match with your regex.
When passing variable contents to a function, don't enclose the variable names in percent signs (like %UserEnv%).
Your regex \d+$ will only match numbers at the end of the string, not the text before it.
A possible solution:
myText := "sometext55"
if( RegExMatch(myText, "(.*?)(\d+)$", splitted) ) {
msgbox, Text: %splitted1%`nNumber: %splitted2%
}
As described in the docs, splitted will be set to a pseudo-array (splitted1, splitted2 ...), with each element containing the matched subpattern of your regex (the stuff that is in between round brackets).
I have stdout feeding to a variable when I use literal filepaths in my comspec line, but why can I not use a variable in place of the filename I want to be analyzed?
Note that mediainfo already (successfully) uses the % symbol in its own arguments. So how do I make comspec treat %LongPath% as a real variable?
I already tried adding an extra pair of quotes around %Longpath% as well, but no luck.
Loop %0%
{
Path := %A_Index%
Loop %Path%, 1
LongPath = %A_LoopFileLongPath%
SplitPath LongPath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(comspec " /c C:\MediaInfo.exe --Inform=Video;%FrameRate% %LongPath%")
framerate := ""
while, !objExec.StdOut.AtEndOfStream
framerate := objExec.StdOut.ReadAll()
msgbox %framerate%
}
Thanks for some expertise.
The key was the enclose the appname and arguments in quotes, (and make sure to leave an extra space before the last quote) and then not to include your final variable in the quotes.