VBscript - multiline IF statement yielding error [duplicate] - date

This question already has answers here:
VBS using LIKE to compare strings "Sub or Function not defined"
(4 answers)
Closed 2 years ago.
I have a basic script that was working no problem for a year. Recently, I've tried to add an IF statement to it, so if the current date is a particular day of the year i.e. January 18, then do not Msgbox. I thought it would be fairly straight forward, but ran into Sub or Function not defined on the first line of the IF statement that I cannot seem to resolve on my own:
If Not CStr(Date()) Like "1/18/*" _
And Not CStr(Date()) Like "2/15/*" _
And Not CStr(Date()) Like "12/31/*" Then
MsgBox "perform task"
Else
MsgBox "do not perform task"
End If
Can someone tell me what I am missing?

There is no Like operator in VBScript. One way to achieve what you are trying to do would be:
MonthAndDay = Month(Date) & "/" & Day(Date)
If MonthAndDay <> "1/18" _
and MonthAndDay <> "2/15" _
and MonthAndDay <> "12/31" Then
MsgBox "perform task"
Else
MsgBox "do not perform task"
End If

Related

Activate variable inside user input [duplicate]

This question already has answers here:
Expanding variables in file contents
(3 answers)
Powershell reevaluate string to array
(1 answer)
Closed 2 months ago.
Task: make PowerShell 5 to read/activate user input that contains any variable. This doesn't work on both script defined and environment variables. E.g.:
$H=4
$testParA=Read-Host "Try to input enviroment variable `$Env:windir :" #user input is $H
$testParB=Read-Host "Try to input variable `$H :" #user input is $H
Write-Host $testParA
Write-Output $testParA
Write-Host $testParB
Write-Output $testParB
Result:
> $Env:windir
> $Env:windir
> $H
> $H
Expectation:
> C:\Windows
> C:\Windows
> 4
> 4
Original task: In a text generator PowerShell script, let users to customize text, and where to place the serial counter variable "$serial". E.g., "some text $serial some other text"
No-duplication: This question has been marked as duplicate from "https://stackoverflow.com/questions/1667023/expanding-variables-in-file-contents", but not really. The answer is surely duplicated, but the question part is very different (You have to know "expand variables" to be able to find this question from searching, which is why I was unable to get answers before posting this question), and could have other methods to achieve the same or a better result. In general, on closing this question will only cause more people who never heared of "expand variables" to further create similar questions. There is probably a better method than simply closing this question.

How can I use dot sourcing to run code from a variable in the same instance? [duplicate]

This question already has answers here:
Are these alternatives to Invoke-Expression really any safer? And why?
(1 answer)
Powershell reevaluate string to array
(1 answer)
Closed 4 months ago.
I have a variable that stores a command that I would like to execute.
ex:
$C = "echo 'test'"
I have one way to execute this by using the following:
powershell .($C)
however this opens a new instance of powershell. How can I go about executing that code in the same instance? I can't seem to find a way to use dot sourcing without opening that second instance.
EDIT: I can not use IEX

I need to change the format of the date [duplicate]

This question already has answers here:
How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?
(30 answers)
Closed 1 year ago.
i am using batch and i need help formatting this one thing, on saved file the date changes everyday but the "yyyy" is just put down as "yy"
Example: if the year was "2021" the name would be "21"
I havent found anything that could get me the last 2 numbers on the year.
Please help as i need this for work.
Sincerely,
Kythe
You might cut out the part you do not need:
set DT=%date%
set dd=%DT:~0,2%
set mm=%DT:~3,2%
set yy=%DT:~8,2%
echo %dd%
echo %mm%
echo %yy%
echo "day: %dd%, month: %mm%, year: %yy%"
pause
set variable=%date:~start,length% assigns to the variable all the the characters of date indexed between start (counting from 0) and (start + length-1)
EDIT:
On other machine date might be formatted differently, as #Squashman pointed out.
To properly cut out the part you need, try:
echo %date%
Now set dd, mm and yy in the correct way you need them to be set

How to include "" in a String in swift [duplicate]

This question already has answers here:
How to print double quotes inside ""?
(3 answers)
Closed 2 years ago.
I have a really simple question and I bet the answer is as simple..
I want to create a String which include the symbol " twice, such as (Hello "" World !) or (Hello "new" World !), without breaking my String (for comprehension purpose, I've put my sentences inside of parentheses instead of said symbol ").
I can't remember the name of the symbol ("), so I can't google anything, because (" ") is not clear enough for searching motor..
I hope I'm being clear, thank you for your help !
You can use hashtag before and after the double quotes to allow any special character to be added inside your string:
let string = #"Hello "" World !"#

Problems with append using a for loop involving lists in Python 2

I'm a beginner with python 2 and I've got two problems with 'append' command using a for loop.
I'trying to make run this piece of code, but it doesn't work properly:
def pole():
fish_pole = []
fish_elements = ['stick', 'liana', 'worm', 'bended needle']
pick_choice = raw_input()
if pick_choice == "pick up":
print "Good boy. You start picking up your 'tools'"
for element in fish_elements:
fish_pole.append(element)
fish_elements.remove(element)
print "You've found a %s and then" % element
if not element in fish_elements:
print "Ok you have the tools you need."
print "Now you can go to the river."
river()
else:
print "Come on. The sun is dying."
pole()
Ok, my problems are these:
I can't figure out why it prints the "You've found a %s and then" string only for the element 'stick' and the element 'worm';
if I write simply "if not fish_elements:" I have the first problem I've just mentioned above plus this one: as soon as the script finishes printing the two strings for 'stick' and 'worm', it goes straight for the 'else' option and it restarts the entire pole() definition from the beginning.
Please help me. Thanks guys!
Since you're iterating through all the elements of fish_elements you can consider removing fish_elements.remove(element) as it may be the main problem.
for element in fish_elements:
fish_pole.append(element)
print "You've found a %s and then" % element