I want to check if extracted word contains English letters - numbers

I'm having a big problem that I cant solve for days. I'm macro newbie and I want to compare Nb_1 i Nb_2 and Nb_3 and Nb_4.
My configuration is iMacros for FF v9.0.3 Firefox 50.1.0 Windows 10
Nb_1 and Nb_2 its numbers and that works.
Nb_3 and Nb_4 are words and there is a problem. I want to check if !EXTRACT word contains a','b','c','d','e','f','g'... and if yes {x=1;} else{x=0;}
When I extract a word, if the word contains English letters and if yes - I want {x=1;}. If not I want {x=0;}.
This is my script
'Extract 1st Number:
SET !EXTRACT NULL
TAG POS=4 TYPE=TD ATTR=CLASS:text-center:* EXTRACT=TXT
SET Nb_1 {{!EXTRACT}}
'>
'Extract 2nd Number:
SET !EXTRACT NULL
TAG POS=5 TYPE=TD ATTR=CLASS:text-center:* EXTRACT=TXT
SET Nb_2 {{!EXTRACT}}
'>
'Extract 3nd Word:
SET !EXTRACT NULL
TAG POS=2 TYPE=H5 ATTR=CLASS:media-heading EXTRACT=TXT
SET Nb_3 {{!EXTRACT}}
SET !EXTRACT NULL
'Extract 4nd Word:
SET !EXTRACT NULL
SET Nb_4 {{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',}}
TAG POS=R1 TYPE=BUTTON ATTR=CLASS:mainButton:* EXTRACT = HTM
SET !VAR1 EVAL("var s = \"{{!EXTRACT}}\"; s = s.split(' ')[1]; s=s.replace('id=', ''); s=s.replace('4045549725', '');s;")
SET Button EVAL("var n1='{{Nb_1}}', n2='{{Nb_2}}', n3='{{Nb_3}}', n4='{{Nb_4}}'; if((n1*1)>(n2*1)) else if(n3=n4) {x=1;} else{x=0;} x;")
WAIT SECONDS=2
TAG POS={{Button}} TYPE=BUTTON ATTR=ID:{{!VAR1}}
SET !VAR5 EVAL("var randomNumber=Math.floor(Math.random()*2 + 1); randomNumber;")
WAIT SECONDS={{!VAR5}}
Nb_1 and Nb_2 are working right, but when I try to check if word Nb_3 contains 'a','b','c','d','e','f','g... and so on, I get this error
expected expression, got keyword 'else', line: 30 (Error code: -1001)
This is working and comparing Nb_1 and Nb_2
SET Button EVAL("var n1='{{Nb_1}}', n2='{{Nb_2}}', n3='{{Nb_3}}', n4='{{Nb_4}}'; if((n1*1)>(n2*1)){x=1;} else{x=0;} x;")
But, when I add Nb_3 and Nb_4 I get and error. Does anyone know what I'm doing wrong?
If someone has an idea how to solve this, please share.
Thanks

And joining two conditions together:
SET Button EVAL("var x = 1; var w = '{{Nb_3}}'.replace(/\s/g, '').toLowerCase(); for (i = 0; i < w.length; i++) {if (w.charCodeAt(i) < 97 || w.charCodeAt(i) > 122) x = 0}; var n1='{{Nb_1}}', n2='{{Nb_2}}'; if((n1*1)>(n2*1)){y=1;} else{y=0;}; (x && y) ? 1 : 0;")
I think the following code should be helpful in your case:
SET Button EVAL("var x = 1; var w = '{{Nb_3}}'.replace(/\s/g, '').toLowerCase(); for (i = 0; i < w.length; i++) {if (w.charCodeAt(i) < 97 || w.charCodeAt(i) > 122) x = 0} x;")
At first you can try try this line:
SET Button EVAL("'{{Nb_3}}'.match(/\D/) ? 1 : 0;")

Related

In neovim, how do I get a file to open at the same line number I closed it at last time?

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
This code is valid in vim. It is the syntax of vimscript. It can also work in neovim's configuration file init.vim. how can I achieve the same effect in init.lua?
Tested on 0.7.2, if not available, the version may be too low.
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = {"*"},
callback = function()
if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
vim.api.nvim_exec("normal! g'\"",false)
end
end
})

Panel doesn't execute )PNTS Section

I'm coding a ISPF Panel with "Point and shoot" elements. The elements say "yes" and "no" and the default cursor have to point to "yes".
1st Case:
Declaration of the fields: + TYPE(INPUT) PAS(ON)
When I use this declaration, the panel closes by pressing [enter] and generating rc = 0. However, the )PNTS section doesn't run.
2nd CASE:
Declaration of the fields: + TYPE (PS)
The )PNTS section runs by pressing [enter]. However, I cannot set the .cursor to the field "yes".
I tryed different ways with different field names (e.g. ZPS00001). I tryed to simulate Point and Shoot with Rexx, but nothing worked really fine.
Pressing enter will cause the point and shoot fields to be processed. However the cursor must be on one of the fields for the )PNTS section to set the value associated with a field. It would sound like panel may have not been coded correctly. PAS should be used for input or output fields and PS should be used for text fields. For instance if you have the following panel:
)ATTR
$ TYPE(PS)
! TYPE(OUTPUT) PAS(ON)
)BODY
+ --------------------- +
+ ===>_ZCMD +
+
$Field1 : _FLD +
$Field2 : _ABC +
$Field3 : !IN1 +
$Field4 : !IN2 +
)INIT
&INV1 = 111
&INV2 = 222
&INV3 = 333
)REINIT
REFRESH(*)
)PROC
)PNTS
FIELD(IN1) VAR(INV1) VAL(ON)
FIELD(IN2) VAR(INV2) VAL(OFF)
FIELD(ZPS00001) VAR(INV3) VAL(1)
FIELD(ZPS00002) VAR(INV3) VAL(2)
FIELD(ZPS00003) VAR(INV3) VAL(3)
FIELD(ZPS00004) VAR(INV3) VAL(4)
)END
With the following REXX exec:
/* REXX */
RCC = 0
INV1 = 0
INV2 = 1
DO WHILE RCC = 0
ADDRESS ISPEXEC 'DISPLAY PANEL(PAS)'
RCC = RC
SAY INV1 '-' INV2 '-' INV3
END
You can test the values of inv1, inv2 and inv3 based on where you put the cursor when you hit enter. You will get 1, 2, 3 or 4 if the cursor in on field1, field2, field3 or field4. If it is on IN1 or IN2 then you get ON or OFF. It all depends on where the cursor is positioned when ENTER is hit. Based on the example you can see point and shoot is not limited to Menus. Hope the example helps.
Marv Knight

VBScript to detect Facebook IE window, press Like and close the window

I tryed to make a script to detect the IE window that is opened on Facebook and hit the Like button.
Let's say I have 10 IE opened. Only one of them is on a page on Facebook.
I want my script to detect that IE window, click this button:
IE.Document.getElementById("pagesHeaderLikeButton")
(The above button is the Like button)
and close that IE window.
I tryed to get that IE window by:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
But this will only set my VBscript to the first opened IE and it will not find the Facebook window.
I tryed this:
Dim objInstances, item
Set objInstances = CreateObject("Shell.Application").windows
For Each item In objInstances
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
IE.Document.getElementById("pagesHeaderLikeButton").Click
End If
Next
But I get "Sub or function not defined"
Next code snippet could help:
Set shApp = CreateObject( "shell.application")
With shApp
For Each wnd In .Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
If InStr(1, wnd.document.URL, "facebook.com", vbTextCompare) > 0 Then
Wscript.Echo "THIS:"
End If
Wscript.Echo Left( wnd.document.URL, 70)
End If
Next
End With
Output example (with more facebook.com matches):
==>cscript D:\VB_scripts\SO\30717779a.vbs
http://www.msn.com/?ocid=iehp
THIS:
https://www.facebook.com/login.php?api_key=127760087237610&skip_api_lo
THIS:
https://www.facebook.com/literarnifestival1
THIS:
https://cs-cz.facebook.com/mgvsetin
http://www.bing.com/search?q=Xmaster+Official&qs=n&form=QBRE&pq=xmaste
http://www.bing.com/search?q=%22Xmaster+Official%22&qs=n&form=QBRE&pq=
==>
The following code will search for open IE windows that have "facebook.com" in its URL and save them in a collection:
Dim getIE As New Collection
For Each Item In CreateObject("Shell.Application").Windows
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
getIE.Add Item
End If
Next
Then you can loop through the collection and do what you want with the IE items:
For Each itemIE In getIE
itemIE.Document.getElementById("pagesHeaderLikeButton").Click ' For example
Next itemIE
Hope this does what you wanted! ;)
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(wnd.Name,"Internet") Then
if InStr(wnd.Document.URL,"facebook.com") Then
Set IE2 = wnd
Exit For
End If
End If
Next
So to press the button will be like this:
Set Butlike = IE2.Document.getElementsByTagName("button")
For Each btn In Butlike
If btn.type = "submit" Then btn.Click()
Next

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

why is this vbscript not fetching any value?

i am trying to write a vbscript that extracts the value from src attribute of an <img> tag that has a class attribute as this cs-poster-big
here is the code i have tried so far,
'Initializing object with Internet Explorer Application
set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
'setting properties of Internet Explorer to the newly create object
with IE
.Visible = 0
.navigate "http://www.roku.com/channels/#!details/12" 'INSERT WEBPAGE HERE
end with
'waiting for IE to load the page
'tried using IE.busy or IE.readyState <> 4 also
while IE.busy
wScript.sleep 500
wend
wScript.sleep 500
'getting all image tags from the webpage
Set imgTags = IE.document.getElementsByTagName("IMG")
'iterating through the image tags to find the one with the class name specified
For Each imgTag In imgTags
'tried imgTag.className also
If imgTag.getAttribute("class") = "cs-poster-big" Then MsgBox "src is " & imgTag.src
next
IE.quit
set IE= Nothing
MsgBox "End of script"
and it is not displaying any value but you can view the source of the page here and you can see it has an <img> tag with class cs-poster-big
i don't understand why it is not displaying in my script
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 500
Loop
Wait until page is completely loaded.
EDIT - While this works in IE10, IE8 fails to locate the image. Not tested in other versions.
In this case, try to change your url to
http://www.roku.com/channels?_escaped_fragment_=details/12/netflix#!details/12/netflix
to avoid problems with the dynamic generate content.
Also, in IE8, code needs to be changed to get class name of the image. It should be
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 100
Loop
Set imgTags = IE.document.getElementsByTagName("IMG")
For Each imgTag In imgTags
imgClass = imgtag.getAttribute("class")
If IsNull( imgClass ) Then
imgClass = imgTag.className
End If
If imgclass = "cs-poster-big" Then
MsgBox "src is " & imgTag.src
End If
Next
But not a solution, just a workaround.