How to run program with variable command line arguments? - command-line

I have the following script:
For $alpha = 1 to 10
For $beta = 1 to 10
Run('"C:\Users\MyProg.exe ' & alpha/10 & ' ' & beta/10 & ' 200 2 0.5'
;some other actions follow
Next
Next
I have checked many times that the string is well-formed, thus I have no idea why the script wouldn't run the program. Could you help me please?

Just replace the ending ' with "') and use proper variable names including the $... like $alpha instead of just alpha. Your syntax check in SciTE should have told you.
For $alpha = 1 to 10
For $beta = 1 to 10
Run('"C:\Users\MyProg.exe ' & $alpha/10 & ' ' & $beta/10 & ' 200 2 0.5"')
;some other actions follow
Next
Next

Related

Updating my current script which modifies multiple lines into a single one

My current script copies text like this with a shortcut:
:WiltedFlower: aetheryxflower ─ 4
:Alcohol: alcohol ─ 3,709
:Ant: ant ─ 11,924
:Apple: apple ─ 15
:ArmpitHair: armpithair ─ 2
and pastes it modified into a single line
Pls trade 4 aetheryxflower 3 alcohol 11 ant 15 apple 2 armpithair <#id>
As you can see there are already two little problems, the first one is that it copies only the number/s before a comma if one existed instead of ignoring it. The second is that I always need to also copy before hitting the hotkey and start re/start the script, I've thought of modifying the script so that it uses the already selected text instead of the copied one so that I can bind it with a single hotkey.
That is my current script, it would be cool if anyone can also tell me what they used and why exactly, so that I also get better with ahk
!q::
list =
While pos := RegExMatch(Clipboard, "(\w*) ─ (\d*)", m, pos ? pos + StrLen(m) : 1)
list .= m2 " " m1 " "
Clipboard := "", Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
If the pattern of your copied text dont change, you can use something like this:
#Persistent
OnClipboardChange:
list =
a := StrSplit(StrReplace(Clipboard, "`r"), "`n")
Loop,% a.Count() {
b := StrSplit( a[A_Index], ": " )
c := StrSplit( b[2], " - " )
list .= Trim( c[2] ) " " Trim( c[1] ) " "
}
Clipboard := "Pls trade " list " <#951737931159187457>"]
ToolTip % Clipboard ; just for debug
return
With your example text, the output will be:
Pls trade aetheryxflower ─ 4 alcohol ─ 3,709 ant ─ 11,924 apple ─ 15 armpithair ─ 2 <#951737931159187457>
And this will run EVERY TIME your clipboard changes, to avoid this, you can add at the top of the script #IfWinActive, WinTitle or #IfWinExist, WinTitle depending of your need.
The answer given would solve the problem, assuming that it never changes pattern as Diesson mentions.
I did the explanation of the code you provided with comments in the code below:
!q::
list = ; initalize a blank variable
; regexMatch(Haystack, regexNeedle, OutputVar, startPos)
; just for frame of reference in explanation of regexMatch
While ; loop while 'pos' <> 0
pos := RegExMatch(Clipboard ; Haystack is the string to be searched,
in this case the Clipboard
, "(\w*) ─ (\d*)" ; regex needle in this case "capture word characters
(a-z OR A-Z OR 0-9 OR _) any number of times, space dash space
then capture any number of digits (0-9)"
, m ; output var array base name, ie first capture will be in m1
second m2 and so on.
, pos ? pos + StrLen(m) : 1) ; starting position for search
"? :"used in this way is called a ternary operator, what is saying
is "if pos<>0 then length of string+pos is start position, otherwise
start at 1". Based on the docs, this shouldn't actually work well
since 'm' in this case should be left blank
list .= m2 " " m1 " " ; append the results to the 'list' variable
followed with a space
Clipboard := "" ; clear the clipboard.
Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0 ; wait zero seconds for the clipboard to change
If ErrorLevel ; if waiting zero seconds for the clipboard to change
doesn't work, give error msg to user.
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
Frankly this code is what I would call quick and dirty, and seems unlikely to work well all the time.

How to break a long code line into multiple lines in NetLogo?

In Python, we break a long line of code into multiple code lines with backslash like this.
a = 5
b = 11
print(str(a) + " plus " + \
str(b) + " is " + \
str(a + b))
# prints "5 plus 11 is 16"
How do we do that in NetLogo?
NetLogo doesn't care about multiple lines except for comments (the comment marker ; only lasts to the end of the line). All of these are the same:
to testme
; single line
let a 25 print a
; command per line
let b 20
print b
; unreadable
let
c
15
print
c
end

In a QLikView script generate code dependent of parameters in function call

I have a script in QLikView to extract and check my data. It has to perform a data extraction for 12 separate times. I made a function that works properly but some things are hardcoded and I want to call the same function 12 times with different parameters. The question that I have is about code generation dependent of the parameters in the function.
A part of my code is :
SUB SplitsenOpMiddel(middel, eersteVraag, laatsteVraag)
Temp_Middel_$(middel):
LOAD
Veldzoeknaam AS ZoekNaam,
VeldP_id AS $(middel)_VeldP_id,
Middel AS $(middel)_Middel,
MATEnr AS $(middel)_MATE,
IF(Vraagnr=1, VeldWaarde) AS $(middel)_Vraag001,
IF(Vraagnr=2, VeldWaarde) AS $(middel)_Vraag002,
IF(Vraagnr=3, VeldWaarde) AS $(middel)_Vraag003,
IF(Vraagnr=4, VeldWaarde) AS $(middel)_Vraag004,
IF(Vraagnr=5, VeldWaarde) AS $(middel)_Vraag005,
IF(Vraagnr=6, VeldWaarde) AS $(middel)_Vraag006,
IF(Vraagnr=1, VeldTypeGrp) AS $(middel)_Vraag001Type,
IF(Vraagnr=2, VeldTypeGrp) AS $(middel)_Vraag002Type,
IF(Vraagnr=3, VeldTypeGrp) AS $(middel)_Vraag003Type,
IF(Vraagnr=4, VeldTypeGrp) AS $(middel)_Vraag004Type,
IF(Vraagnr=5, VeldTypeGrp) AS $(middel)_Vraag005Type,
IF(Vraagnr=6, VeldTypeGrp) AS $(middel)_Vraag006Type
RESIDENT Data2
WHERE Vraagsort = '$(middel)';
In this case, the function call is :
CALL SplitsenOpMiddel('A', 1, 6)
So far, the numbers 1 to 6 are hardcoded but what I want is generate this code dependent of the second and third parameter.
My second function call will be :
CALL SplitsenOpMiddel('B', 7, 10)
And automatically the code needs to be :
Temp_Middel_$(middel):
LOAD
Veldzoeknaam AS ZoekNaam,
VeldP_id AS $(middel)_VeldP_id,
Middel AS $(middel)_Middel,
MATEnr AS $(middel)_MATE,
IF(Vraagnr=7, VeldWaarde) AS $(middel)_Vraag007,
IF(Vraagnr=8, VeldWaarde) AS $(middel)_Vraag008,
IF(Vraagnr=9, VeldWaarde) AS $(middel)_Vraag009,
IF(Vraagnr=10, VeldWaarde) AS $(middel)_Vraag010,
IF(Vraagnr=7, VeldTypeGrp) AS $(middel)_Vraag007Type,
IF(Vraagnr=8, VeldTypeGrp) AS $(middel)_Vraag008Type,
IF(Vraagnr=9, VeldTypeGrp) AS $(middel)_Vraag009Type,
IF(Vraagnr=10, VeldTypeGrp) AS $(middel)_Vraag0010Type
RESIDENT Data2
WHERE Vraagsort = '$(middel)';
Is there a way in QlikView to perform this?
Another part of my code where I need the same type of code generation is :
Check_Middel_$(middel):
NOCONCATENATE LOAD
ZoekNaam,
$(middel)_VeldP_id,
$(middel)_Middel,
$(middel)_MATE,
IF(ISNULL($(middel)_Vraag001),
IF(ISNULL($(middel)_Vraag002) AND
ISNULL($(middel)_Vraag003) AND
ISNULL($(middel)_Vraag004) AND
ISNULL($(middel)_Vraag005) AND
ISNULL($(middel)_Vraag006), 'G', 'F'))
AS $(middel)_Leeg_Check,
IF($(middel)_Vraag001 = 0,
IF($(middel)_Vraag002 = 0 AND
$(middel)_Vraag003 = 0 AND
$(middel)_Vraag004 = 0 AND
$(middel)_Vraag005 = 0 AND
$(middel)_Vraag006 = 0, 'G', 'F'))
AS $(middel)_0_Check,
IF(($(middel)_Vraag001 <> 0 AND NOT ISNULL($(middel)_Vraag001)),
IF(ISNULL($(middel)_Vraag002) OR
ISNULL($(middel)_Vraag003) OR
ISNULL($(middel)_Vraag004) OR
ISNULL($(middel)_Vraag005) OR
ISNULL($(middel)_Vraag006), 'F',
IF(($(middel)_Vraag002 = 0) AND ($(middel)_Vraag003 = 0) AND ($(middel)_Vraag004 = 0) AND ($(middel)_Vraag005 = 0) AND ($(middel)_Vraag006 = 0), 'M', 'G')))
AS $(middel)_Vol_Check,
$(middel)_Vraag001,
$(middel)_Vraag002,
$(middel)_Vraag003,
$(middel)_Vraag004,
$(middel)_Vraag005,
$(middel)_Vraag006
RESIDENT Middel_$(middel);
DROP TABLE Middel_$(middel);
You need to "build" the script on the fly. The code below shows how this can be achieved for the first function SplitsenOpMiddel can look. Calling this function like this call SplitsenOpMiddel('A', 1, 6) will generate the table with the required fields.
You can have a look at the sample qvw here. Tried to cover both cases but might not work as you expected but will give you an idea.
sub SplitsenOpMiddel(middel, eersteVraag, laatsteVraag)
let Temp_Middel = 'Temp_Middel_' & '$(middel)' & ':' & chr(13) & 'Load' & chr(13);
for b = $(eersteVraag) to $(laatsteVraag)
let Temp_Middel = '$(Temp_Middel)' & 'IF(Vraagnr=' & $(b) & ', VeldWaarde) AS' & ' $(middel)' & '_Vraag00' & $(b) & ',' & chr(13) &
'IF(Vraagnr=' & $(b) & ', VeldTypeGrp) AS' & ' $(middel)' & '_Vraag00' & $(b) & 'Type,' & chr(13);
next
let Temp_Middel = '$(Temp_Middel)' & 'Veldzoeknaam AS ZoekNaam,' & chr(13) &
'VeldP_id AS ' & '$(middel)' & '_VeldP_id,' & chr(13) &
'Middel AS ' & '$(middel)'& '_Middel,' & chr(13) &
'MATEnr AS ' & '$(middel)' & '_MATE ' & chr(13) &
'Resident Data2' & chr(13) &
'WHERE Vraagsort =' & chr(39) & '$(middel)' & chr(39) & ';';
$(Temp_Middel);
end sub
If your question is if it could work, I would answer yes. Variables in QlikView are handled as text to be replaced when invoked, so I see to reason why it shouldn't work.

Why is this block of code producing runtime error 91

This block of code is causing runtime error 91 or with block not set error
this code is for opening reports in crystal report in vb6
For DocCodeCount = 0 To cboDoctorsCode.ListCount - 1
strReportTitle = "DOCTOR'S TRANSMITTAL COPY"
strSqlStatement = "PFMS '" & cboControlCode.Text & "', '" & cboDoctorsCode.List(DocCodeCount) & "', '" & sCurrentUserName & "'"
strFilename = App.Path & "\Reports\ClaimsBillProc\PF MS.rpt"
newRpt.OpenReport vADOConnection, strSqlStatement, strFilename, strReportTitle, 3, False
Set newRpt = Nothing
Next
When used in 1 time opening of report it runs fine but when it is used in this manner in the loop it causes error.
The answer is quite clear: You destroy your object within the loop.
This line is the obvious reason for your one time wonder:
Set newRpt = Nothing

Using a for loop to access Command Prompt

I want to call a function Christian.exe to the command line to act of a series of files that are indexed as "reentrant_008.sif" (8 is an example number).
"Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000 is the text that needs to be fed into the command prompt for the program to execute (num is an arbitrary number)
There are approximately 400 files, so I want to create a vbs code that calls the command prompt for each file until all the files have been accessed so far this is my code:
For
Dim cmdpath
num = CStr(i)
Set wshShell = WScript.CreateObject ("WSCript.shell")
If i < 10 Then
cmdpath = "Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000
Else
If i < 100 Then
cmdpath = "Christian.exe reentrant_0" & num & ".sif reentrant_0" & num & ".pgm" 0 2000
Else
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & ".pgm" 0 2000
End If
End If
wshshell.run cmdpath
Next
Problem is that a new command prompt is being called for each file, which is slowing down my computer. How do I ensure that only one command window that addresses all my files is called?
If you look at the documentation for Run you will see two option arguments [intWindowStyle], [bWaitOnReturn]. If you want your EXE to wait before proceeding on the script change your call to this
wshshell.run cmdpath, 0, True
Where 0 will hide the window and True will wait for the program to finish before proceeding in the script. Depending on your needs you could change the number or remove it.
wshshell.run cmdpath,, True
Since you tagged your question with both vbscript and powershell I'm adding a PowerShell solution:
foreach ($i in 1..400) {
$num = "{0:d3}" -f $i
& Christian.exe "reentrant_${num}.sif" "reentrant_${num}.pgm" 0 2000
}
& is the call operator. I recommend using it whenever you run external commands in PowerShell, because otherwise you'll be in for a surprise when you try to run a command from a variable for the first time:
$christian = "Christian.exe"
$christian ... # <-- throws an error, because $christian contains a
# string, which is NOT automagically interpreted
# as a command by PowerShell
& $christian ... # <-- works
-f is the formatting operator, that allows you to create formatted string output. Since your command lines only differ by the zero-padding of the input and output files it's better to build the file names with pre-padded number strings.
I recommend doing the pre-padding in VBScript as well:
For i = 1 To 400
num = Right("000" & i, 3)
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & _
".pgm" 0 2000
wshshell.run cmdpath, 0, True
Next