How to make a simple loop in .vbs [duplicate] - vbscript

This question already has answers here:
Looping VBScript
(2 answers)
Closed 1 year ago.
I have this simple code that creates a message box. I to make a loop that loops the code that creates the message box until a certain variable value is met.
Here is the code I want to loop:
do x=msgbox ("some text" ,2+16, "text") loop
I want to loop the code until variable i equals 10. I am new to .VBS and don't know how to implement that. Any help is appreciated!

I guess you just want a simple while loop like
Dim x
x=1
Do While x<>10
x=msgbox ("some text" ,2+16, "text")
Loop
For more syntax, refer here: https://www.guru99.com/vbscript-looping.html#2

Related

Comparing values "in the different" in VBscripting Photoshop [duplicate]

This question already has answers here:
Compare two values
(3 answers)
Closed 1 year ago.
In VB Script in Photoshop, is it possible to implement conditionals such as:
if A<>B Then
....code....
End if
I can compare equals, i.e. "if A=B etc etc", but I cannot find the syntax for comparing in the "different".
I have tried different combinations of syntax in line with what I know of coding (aka batting in the dark) to no avail. BTW, this apparent limitation would not matter except that there is no GOTO avalibale here statements that I know of.
Regards,
Of course that VBScript can use both equals and differents.
Example you showed is correct :
if (string<>"") then
...
end if
Can you show a sample of code you used ? Maybe the issue is somewhere else, like comparaison different kind of values (string vs number).

In a C Make script, how to increment a variable? [duplicate]

This question already has an answer here:
How to increment variable
(1 answer)
Closed 4 years ago.
I was expecting a function like "increment(VAR)" but couldn't find any.
MATH(EXPR VAR "${VAR}+1")
Review this
How to increment variable
https://cmake.org/cmake/help/v2.8.8/cmake.html#command%3amath
The proffered solution won't work in every context, but only in the context of an ACTION that corresponds to a given target.
Also, not sure what all this MATH jazz is, how about using backticks (prefer $()-notation, but that's ksh-specific):
`expr ${VAR} + 1`
You can barely see the backticks before the 'e' and after the '1', but they're there.

In C#, what does using a dollar sign do in Console.WriteLine [duplicate]

This question already has answers here:
What does $ mean before a string?
(11 answers)
Closed 6 years ago.
thank you for looking at my question, to verify what i mean
Console.WriteLine($"Hello {variable}");
I am curious to the effect that the $ has on the output from Console.WriteLine
Console.WriteLine($"Hello {variable}");
Is I think equal to:
Console.WriteLine(string.Format("Hello {0}", variable));
It just moves the parameter into the index position as if you were formatting it.
It is a new feature to use in addition to string.Format
It's called Interpolated Strings

How to call i in a for loop? [duplicate]

This question already has answers here:
What is the difference between $(command) and `command` in shell programming?
(6 answers)
Closed 7 years ago.
So, this question seems a-specific. It is, because I'm not a BASH-programmer, rather a Biologist-turned-writing-some-useful-scripts-for-my-daily-work-scripter. Anyway. Say, I have a for loop, like so:
for CHR $(seq 1 22); do
echo "Processing chromosome ${CHR}";
done
I used to write `seq 1 22` but now I've learned to write $(seq 1 22). Clearly there is a difference in terms of the way you write it. But what is the difference in terms in computer language and interpretation? Can someone explain that to me?
The other thing I learned by simply doing on the command line on our computer cluster, was to call "i" differently. I used to do: $CHR. But when I'd have a file name sometext_chr to which I'd like to add the number (sometext_chr$CHR) that wouldn't work. What does work is sometext_chr${CHR}. Why is that? Can someone help me explain the difference?
Again, I know the question is a bit a-specific - I simply didn't know how to otherwise frame it - but I hope someone can teach me the differences.
Thanks and best!
Sander
The $(...) can be nested easily, as the parentheses clearly indicate where an expression starts and ends. Using `, nesting is not so simple, as the start and end symbols are the same.
Your second example is probably from memory, because it's incorrect. sometext$chr and sometext${chr} would both work the same way. Perhaps what you really meant was a situation like this:
$chr_sometext
${chr}_sometext
The key point here is that _ is a valid character in a variable name. As a result, $chr_sometext is interpreter as the value of the variable chr_sometext. In ${chr}_sometext the variable is clearly chr, and the _sometext that follows it is a literal string value. Just like if you wrote $chrsometext you wouldn't assume that the chr is somehow special. This is the reason you have to add the clarifying braces.

Specify for in loop type [duplicate]

This question already has answers here:
Type casting in for-in loop
(7 answers)
Closed 8 years ago.
I would like to specify the type for item in the for in loop below.
for item in items {
}
Currently it is AnyObject but I would like to set it to NSString.
Yes, this is a common problem. The solution is to cast:
for item in items as [NSString] {
It is perhaps a little surprising that you have to cast the array (items) rather than explicitly declaring the type of the loop variable (item). But that's the syntax, and you'll quickly get used to it.

Resources