Count Instance of text and run bat if a number is reached - jscript

I am using indexOf to count "200" in a string, I need to find a way to count the 200 as 1 instead of (if string was "200") 3. is there a way to do this? here is what i have so far...
var objIE = new ActiveXObject("InternetExplorer.Application");
WshShell = new ActiveXObject("WScript.Shell");
objIE.Navigate("URL of site");
WScript.Sleep(2000);
var str = objIE.Document.documentElement.innerHTML;
var n = str.indexOf("200");
if (n = 3){
WshShell.Run("killexplorer.bat");
}
else {
WshShell.Run("domanual.vbs")
}
note: the internalHTML has a total of one (2) and five zero's.

Related

Get Last Column in Visible Views Index - Excel - Office-JS

I'm trying to filter the last column on a worksheet but I can't seem to get the Index of the column. To be clear, I need the index relative to the worksheet, no the range. I used VisibleView to find the Column, but there may be hidden rows, so my plan is to then load that column via getRangeByIndexes but I need the relative columnIndex to the worksheet.
I've tried a bunch of variations of the below, but I either get Object doesn't support 'getColumn' or columnIndex is undefined
Note: In the below example I've hardcoded 7 as that will be the last column relative to the VisibleView (Columns and rows are already hidden), but I'd like this to by dynamic for other functions and just returnthe "last visible column index".
var ws = context.workbook.worksheets.getActiveWorksheet()
var visible_rng = ws.getUsedRange(true).getVisibleView()
visible_rng.load(["columnCount", "columnIndex"])
await context.sync();
console.log('visible_rng.columnIndex')
console.log(visible_rng.getCell(0,7).columnIndex)
console.log(visible_rng.getColumn(7).columnIndex)
Well this method seems a bit hacky, please share if you know a better way! But, first thing I found was that getVisibleView only metions rows in the Description.
Represents the visible rows of the current range.
I decided to try getSpecialCells and was able to load the address property. I then had to use split and get the last column LETTER and convert this to the Index.
I also wanted the columnCount but this wasn't working w/ getSpecialCells so I polled that from getVisibleView and return an Object relating to Visible Views that I can build on the function later if I need more details.
Here it is:
async function Get_Visible_View_Details_Obj(context, ws) {
var visible_rng = ws.getUsedRange(true).getSpecialCells("Visible");
visible_rng.load("address")
var visible_view_rng = ws.getUsedRange(true).getVisibleView()
visible_view_rng.load("columnCount")
await context.sync();
var Filter_Col_Index = visible_rng.address
var Filter_Col_Index = Filter_Col_Index.split(",")
var Filter_Col_Index = Filter_Col_Index[Filter_Col_Index.length - 1]
var Filter_Col_Index = Filter_Col_Index.split("!")[1]
if (Filter_Col_Index.includes(":") == true) {
var Filter_Col_Index = Filter_Col_Index.split(":")[1]
}
var Filter_Col_Index = Get_Alpha_FromString(Filter_Col_Index)
var Filter_Col_Index = Get_Col_Index_From_Letters(Filter_Col_Index)
var Filter_Col_Index_Obj = {
"last_col_ws_index": Filter_Col_Index,
"columnCount": visible_view_rng.columnCount,
}
return Filter_Col_Index_Obj
}
Helper Funcs:
function Get_Alpha_FromString(str) {
return str.replace(/[^a-z]/gi, '');
}
function Get_Col_Index_From_Letters(str) {
str = str.toUpperCase();
let out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out - 1;
}

Simple Longest Word problem.. but for some reason code not working and need help debugging

This was the question: Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty.
Examples
Input: "fun&!! time"
Output: time
Input: "I love dogs"
Output: love
This is my code: I am pretty sure I'm doing everything right... but I'm not getting the right answer.
function LongestWord(sen){
var sen = sen.toLowerCase()
var string = "abcdefghijklmnopqrstuvwxyz"
var alphabet_array = string.split("")
//loop thru the sen.
var currentWord = ""
var maxWord = ""
var currentCount = 0
var maxCount = 0
for (let i = 0; i < sen.length; i++){
var currentChar = sen[i]
if (currentChar !== " "){
//we are in the middle of a word
if (alphabet_array.includes(currentChar)){
currentWord += currentChar
currentCount++
}
// console.log(currentWord)
}
// if not in the middle, we at the end
else{
if (currentCount > maxCount){
maxCount = currentCount
maxWord = currentWord
}
console.log(maxWord)
//HAVE TO RESET YOUR CONDITIONS
currentWord = ""
currentCount = 0
}
} //end of for loop
return maxWord
}
You need to store the max value in a list and then compare those values outside of the loop.
The script is currently only comparing the first word it sees and not waiting for it to compares max length of all the other words.
Hope it helps :)

How to split a string into multiple strings if spaces are detected (GM:Studio)

I made a console program, but the problem is that it doesn't allow parameters to be inserted. So I'm wondering how would I split a single string into multiple strings to achieve what I need. E.g.: text="msg Hello" would be split into textA="msg" and textB="Hello"
This is the main console code so far (just to show the idea):
if (keyboard_check_pressed(vk_enter)) {
text_console_c = asset_get_index("scr_local_"+string(keyboard_string));
if (text_console_c > -1) {
text_console+= "> "+keyboard_string+"#";
script_execute(text_console_c);
text_console_c = -1;
}
else if (keyboard_string = "") {
text_console+= ">#";
}
else {
text_console+= "> Unknown command: "+keyboard_string+"#";
};
keyboard_string = "";
}
I cant recommend spliting string with iteration by char, because when u try split very very very long string, then time to split is very long and can freeze thread for a short/long time. Game maker is single threaded for now.
This code is much faster.
string_split
var str = argument[0] //string to split
var delimiter = argument[1] // delimiter
var letDelimiter = false // append delimiter to each part
if(argument_count == 3)
letDelimiter = argument[2]
var list = ds_list_create()
var d_at = string_pos(delimiter, str)
while(d_at > 0) {
var part = string_delete(str, d_at , string_length(str))
if(letDelimiter)
part = part + delimiter
str = string_delete(str, 1, d_at)
d_at = string_pos(delimiter, str)
ds_list_add(list, part)
if(d_at == 0 && str != "")//last string without delimiter, need to add too
ds_list_add(list, str)
}
return list;
Dont forget ds_list_destroy after you iterate all strings
for example:
var splited = string_split("first part|second part", '|')
for(splited) {
//do something with each string
}
ds_list_destroy(splited)
Something like this may help, haven't tested it out but if you can follow what is going on its a good place to start.
Text = "msg Hello"
counter = 0
stringIndex = 0
for (i = 0; i < string_length(text); i++)
{
if string_char_at(text,i) == " "
{
counter++
stringIndex = 0
} else {
string_insert(string_char_at(text,i),allStrings(counter),stringIndex)
stringIndex++
}
}
allStrings should be an array containing each of the separate strings. Whenever a " " is seen the next index of allStrings starts having it's characters filled in. stringIndex is used to add the progressive characters.

Foreach loop per item fill document

I have got a list and I want to go through each item condition and insert it into a document. The issue is that I don’t know how to find an item and go through each condition till the item changes then start again.
Item Condition Total
Bag New 3
Bag Old 5
Jacket New 2
Racket New 1
Racket old 3
Racket unknown 8
This is what I do:
foreach (DataGridViewRow row in tracker.dataGridView1.Rows)
{
if (row.Cells[0].Value != null)
{
string template = #"C:\ document.pdf";
string newFile = #"c:\"+ row.Cells[0].Value.ToString() +".pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
******************************************************************************
// set values for fields
if (row.Cells[1].Value.ToString() == "New")
{
pdfFormFields.SetField("Condition", row.Cells[2].Value.ToString());
}
else if (row.Cells[1].Value.ToString() == "Old")
{
pdfFormFields.SetField("Condition2", row.Cells[2].Value.ToString());
}
***************************************************************************************
pdfStamper.FormFlattening = true;
pdfStamper.Close();
}
else
break;
}
I want the code between the stars to fill the same document till row.cells[0].value changes then start the foreach again.
Just store the value of row.cells[0].value in a variable and compare it during each iteration of the foreach loop.
You also have to distinguish the first row from the rest, since only then a comparison of two values makes sense.
Example code:
string previousValue = null;
string currentValue = null;
bool firstRow = true;
foreach (DataGridViewRow row in tracker.dataGridView1.Rows)
{
currentValue = row.Cells[0].Value.ToString();
if (currentValue != null)
{
string template = #"C:\ document.pdf";
string newFile = #"c:\"+ currentValue +".pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
// Compare previous with current value
if (!firstRow && previousValue != currentValue)
{
// Difference, start new document
....
}
else
{
// Same Value
}
// When row is handled, update previous with current value, and set firstRow to false
previousValue = currentValue;
firstRow = false;
...

number of rows of an ft searched view

I've a view on which I performed a search. I would like to know how many rows this view has after this search. I tried with rows = view1.getEntryCount();
But this gives the number of lines of the "original" view, not the result of my search.
edit
The following works but isn't verry efficient.
Any better idea ?
productTest=sessionScope.get("product");
landTest=sessionScope.get("country");
var length = view1.getEntryCount();
var entries = view1.getAllEntries();
var i = 0;
var rows = 0;
var currentEntry = entries.getFirstEntry();
while(i < length){
land = currentEntry.getColumnValues().elementAt(0);
prod = currentEntry.getColumnValues().elementAt(1);
if (land == landTest & prod == productTest)
{
rows++;
}
currentEntry = entries.getNextEntry();
i++;
}
viewScope.queryString = rows; `
I found this on my blog. Try if if it still works:
var entryCount = viewData.getEntryCount();
var viewControl = getComponent( 'viewControlId' );
var rowCount = viewControl.getRowCount();
// If search is active -> rowcount, else entrycount
var count = ( viewControl.getDataSource().getSearch() ) ? rowCount : entryCount;
please try
rows = view1.getrowlines

Resources