if word found play macro - if-statement

var ret;
while (ret=1) {
ret = iimPlay("macro.iim");
if (ret == -921)
iimPlay("macro2.iim");
}
it works amazing but sometimes the session ends but I don't know exactly how much the session last, do you know if there is a way to login if you are in "specific url" or something like that?
RuntimeError: element IMG specified by WIDTH:100 was not found, line 20(-921)"
as you can see I'm already using -921 to do another macro but is there any way to do something if that specific tag is not found?
Maybe a new js file can be created and it will be my new "macro2" with something like this "if word is found play macro3 if not play oldmacro2""

Whenever I test for a tag I usually extract some part of it and test the extracted text for "#EANF#". If the tag is not found you will get the string "#EANF#" and you can route your program to do something else. Here is an example:
var macro, returnCode;
macro="CODE: ";
macro+="URL GOTO=http://www.google.com/\n";
macro+="TAG POS=1 TYPE=BUTTON FORM=ID:gbqf ATTR=ID:gbqfba EXTRACT=TXT\n";
returnCode = iimPlay(macro);
lastExtract = iimGetLastExtract();
if (lastExtract.localeCompare("#EANF#") !== 0)
{
alert("Tag Found");
} else
{
alert("Tag not found");
}
macro="CODE: ";
macro+="URL GOTO=http://www.google.com/\n";
macro+="TAG POS=1 TYPE=BUTTON FORM=ID:gbf ATTR=ID:gbqfba EXTRACT=TXT\n";
returnCode = iimPlay(macro);
lastExtract = iimGetLastExtract();
if (lastExtract.localeCompare("#EANF#") !== 0)
{
alert("Tag Found");
} else
{
alert("Tag not found");
}

Related

How do I make an interactive command line interface?

I am trying to write a tool to compare my files but I found it difficult to interactive with. I want to support 2 operations: 1) load my files into memory 2) compare the files already loaded.
The idea is like below
while (true) {
getline(&line, &linesize, stdin);
if (strlen(line) < 2) continue;
token = strtok(line, DELIM);
if (!strcmp(token,"load")) {
puts("you want to load something");
} else if (!strcmp(token, "compare")) {
puts("you want to compare something");
} else if (!strcmp(token, "exit")) {
puts("exiting...");
exit(1);
} else {
puts("Cannot parse, try again");
}
}
In terminal, if I want to compare some MyVeryLongFileNameFile.foo and AnotherVeryLongFileNameFile.bar, I can just type diff My\tab Ano\tab \enter and it will auto completes the filenames for me.
I would like to also have these kind of features in my program, like using tab to autocomplete, using up/down to choose from previous commands, etc. How should I achieve this?
Using the ncurses.h library help you accomplish this.

c# windows form - How received a tag value data into my textbox1?

<input name="chkFile" value="2062223616_7147073260_1440589192619132.WMA" type="checkbox">
from this code I want only the value data
Example:
2062223616_7147073260_1440589192619132.WMA
below my code not working so please help me.
My code
HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl)
{
if (bEl.GetAttribute("name").Equals("chkFile"))
showaudiourl.Text = bEl.OuterHtml.Split('"')[3];
}
Use webBrowser2.GetAttribute("value") to get the value you want.
HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl) {
if (bEl.GetAttribute("name").Equals("chkFile")) {
showaudiourl.Text = bEl.GetAttribute("value"); //Changes here
}
}
All you need is add a piece of code telling the app to wait until the web browser document gets initialized:
webBrowser2.Navigate(#"C:\tmp.html"); // Use your own URL here
while (webBrowser2.ReadyState != WebBrowserReadyState.Complete) // Without it,
Application.DoEvents(); // the document will be null
HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl)
{
if (bEl.GetAttribute("name").Equals("chkFile"))
showaudiourl.Text = bEl.GetAttribute("value");
}
The value should be accessed with bEl.GetAttribute("value").
Alternatively, you could use a webBrowser2_DocumentCompleted event to process the HTML document there.

How do I test an image's .RawFormat against a List<string> of extensions from Web.Config?

I want to put the allowed extensions for an image upload in the web.config for easy modification later. what I have here currently works but is hard-coded.
if (!img.RawFormat.Equals(ImageFormat.Png)
&& !img.RawFormat.Equals(ImageFormat.Gif)
&& !img.RawFormat.Equals(ImageFormat.Jpeg)
&& !img.RawFormat.Equals(ImageFormat.Bmp))
{
ViewBag.Message = "Wrong Image Type. Please use an image one with the following extenstions:<br /><b>.jpeg, .gif, .png, or .bmp</b>";
return View(location);
}
This is what I was trying, but I need to pass in an ImageFormat not a string... How do I accomplish this?
bool isAcceptedType = false;
List<string> AcceptedImageTypes = System.Configuration.ConfigurationManager.AppSettings["AcceptedImageTypes"].Split('|').ToList();
foreach (string s in AcceptedImageTypes)
{
if (img.RawFormat.Equals(s))
{
isAcceptedType = true;
}
}
if (!isAcceptedType)
{
ViewBag.Message = "Wrong Image Type. Please use an image one with the following extenstions:<br /><b>.jpeg, .gif, .png, or .bmp</b>";
return View(location);
}
I have found the answer here on this page..

Hide product description

How can I hide product description when the description is long in Opencart (product page) to reduce the load product page, but after clicking on the detail link then came out a full description.
In image you can see Example, Sorry for my bad english, Thanks!
Here is a link to example image example
Why not just truncate it? It will force it to be the right length for you every time!
Go to catalog/controller/product/category.php and when you see
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = false;
}
Add this next:
function truncate($description, $tLimit="20", $break=" ", $pad="...")
{
if(strlen($string) <= $tlimit) return $string;
if(false !== ($breakpoint = strpos($string, $break, $tlimit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $description;
}
Feel free to change the variables:
$tLimit is how many letters you want to allow it.
$break is where you want it to cut off, right now it is set to cut off at the next space. You can have it interrupt words if you like by putting $break=""
$pad is what you want it to show after it cuts off the text.
If you really want no description to show at all Then I recommend still doing something similar to the original script.
function getDescriptionLength($description, $tLimit="20")
{
if(strlen($string) <= $tlimit) return $string;
else {
$description = NULL;
}
return $description;
}

Vote Restriction Coding Error by Programmer

I am not able to properly launch my site at http://www.enbloc.sg
This is because my programmer is not able to figure out a problem. Any help would be much appreciated.
Visitors vote by clicking on one colour on the traffic light. They are supposed to only have one vote.
The site first checks for cookies and then ip address of voter. If the 2 are identical to a previous visitor, then voting is not allowed. If only one of the 2 are repeated, then voting is permitted.
The idea of having a double restriction is to allow different voters behind a fixed IP to vote. E.g. the employees of a company would not be able to vote since they are likely to be accessing the site via a fixed IP address.
However, currently, visitors are able to click on ALL 3 colours to register 3 votes on their first visit to the site. My coder is not able to resolve this issue and has abandoned me.
I would be most grateful if someone can help. I believe the relevant codes are appended below.
Apologies if my posting is wrongly formatted.
Thanks very much,
Lin En
Extracted from http://www.enbloc.sg/js/functions.js
//update dashboard when vote by user
function vote_update(ip_address, issue_num, vote_status){
var vote_cookie = document.getElementById('vote_cookie').value;
if(vote_cookie != '')
{
if(document.getElementById('thanks').style.display == "none")
{
$("#multi_error").fadeIn("slow");
}
else
{
document.getElementById("thanks").style.display = "none";
$("#multi_error").fadeIn("slow");
}
}
else
{
if(ip_address != ' ' && issue_num != ' ')
{
http.open("POST", "update_vote.php"); // true
http.onreadystatechange = update_vote;
http.setRequestHeader("Content-Type", "application/x-www-form- urlencoded;charset=UTF-8");
http.send("ip="+ ip_address +"&issue_num="+ issue_num + "&vote_status=" + vote_status);
}
else
{
alert("Occur Error for IP or ISSUE!");
}
}
}
// ajax response function
function update_vote(){
if (http.readyState == 4)
{
if (http.status == 200)
{
var xmlDoc = http.responseXML;
var listElements = xmlDoc.getElementsByTagName("list");
var result = listElements[0].getElementsByTagName("total") [0].childNodes[0].nodeValue;
if (result == 1)
{
var issue_num = listElements[0].getElementsByTagName("issue")[0].childNodes[0].nodeValue;
var vote = listElements[0].getElementsByTagName("vote") [0].childNodes[0].nodeValue;
$("#thanks").fadeIn("slow");
load(issue_num, vote);
}
else if (result == 'Multi')
{
if(document.getElementById('thanks').style.display == "none")
{
$("#multi_error").fadeIn("slow");
}
else
{
document.getElementById("thanks").style.display = "none";
$("#multi_error").fadeIn("slow");
}
}
else
{
alert("error");
}
}
}
}
These changes will help:
var already_voted = false;
function vote_update(ip_address, issue_num, vote_status)
{
if(alread_voted) return;
already_voted = true;
// rest of the code
}
This will make sure that only one vote can be cast during a single visit. The cookies take care of the rest and are already working fine.