I'm new to autoit, and I'm wondering how to deal with some things. The code is simply this line :
$input = InputBox("game : +/-", "Write a number:")
If I write a number in the section, the program goes normaly.
If I click the cancel button, an error is thrown and so I dealt with it with :
If (#error = 1) Then
$End = True
Is what I ve done okay?
And :
Could you please explain what is going on here and what exactly is happening if I enter no value or if I press cancel?
If I close the windows, what happens ? I'd like the program to end.
Thank you very much ! Sorry if my question is easy or useless, I'll help me a lot
with a couple of ternary ops you can see that the cancel button sets the error flag and it does =1 or ==1 or =True (because True evaluates to 1)
$input = InputBox("game : +/-", "Write a number:")
$result = (#error == 1) ? 'cancel was pressed' : $input
msgbox(0, '' , $result = '' ? 'empty string' : $input)
When you call the InputBox function values are returned to indicate the result of the process these are:
Success: the string that was entered.
Failure: "" (empty string) and sets the #error flag to non-zero.
#error: 1 = The Cancel button was pushed. 2 = The Timeout time was
reached. 3 = The InputBox failed to open. This is usually caused by
bad arguments. 4 = The InputBox cannot be displayed on any monitor. 5
= Invalid parameters width without height or left without top.
So essentially that means that if it returns a non-empty string, the "success" case, you don't have to worry about #error. If any non-zero value is returned, the value of #error will indicate what has happened. So if in the case of an error you just want to return, you should use this if statement:
If (#error <> 0) Then
$End = True
This works because we know if #error == 0 then the input box has been successful and a value has been returned, otherwise we know it's thrown one of the errors listed above. I would anticipate that closing the window has the same effect as pressing cancel, i.e. #error == 1 but I haven't checked.
Further to this, if you wanted to you could switch on the value of #error and use that to give the user an error message along the lines of "please enter a value" or "command timed out" but that seems more than is required in this instance.
Here's the relevant documentation: https://www.autoitscript.com/autoit3/docs/functions/InputBox.htm
Good luck!
Related
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/Index.asp, line 216
and line 216--
<%ip=0
set rsEx=conn.execute("select * from products where featured=1")
while not rsEx.eof
ip=ip+1
set rsMasSku=conn.execute("select top 1* from productSkus where masterid="&rsEx("id")&" order by price")
dprice=rsMasSku("dprice")
price=rsMasSku("price")
if cDbl(dprice) > 0 then
finalPrice=cDbl(price)-cDbl(price)*cDbl(dprice)/100
else
finalPrice=price
end if
%>
It is likely that the source of your error is this code block:
set rsMasSku=conn.execute("select top 1* from productSkus where masterid="&rsEx("id")&" order by price")
dprice=rsMasSku("dprice")
price=rsMasSku("price")
What happens now is that if the second rsMasSku recordset does not return data for the given rsEx("id") value, the references to rsMasSku("dprice") or rsMasSku("price") do not exist at all, and an error is returned.
So the solution would be to add an EOF check (similar to the while not rsEx.eof after the instantiation of the rsMasSku recordset:
set rsMasSku=conn.execute("select top 1* from productSkus where masterid="&rsEx("id")&" order by price")
if not rsMasSku.EOF then
' ... now you can access the rsMasSku fields et cetera ...
else
' ... do nothing ... or maybe think of something else to do ...
end if
The program is about finding factors and if the user enters a special character or an alphabet it will show an error and I wanted to ask the user to try again "Invalid input please try again" after the error shows and also after the program shows the factors I wanted the user to have the chance to find another factor again "Try again? Yes/No"
I've tried the
while True:
if input("Try Again? (Yes/No)").strip().upper() == 'No':
break
but i don't know how to make it work.
Any other solutions will do
def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
try:
num = int(input("Enter a number: "))
print_factors(num)
except ValueError:
print("Sorry, I didn't understand that.");
The program works and I just wanted to put some add ons
while True:
try:
num = int(input("Enter an integer (0 to exit): "))
if num == 0:
break
print(num)
except ValueError:
print("Sorry, you must enter an integer")
Trying to return a message through rkafka library in R.
Followed the same rkafka documentation # https://cran.r-project.org/web/packages/rkafka/vignettes/rkafka.pdf
Output returns "" without the actual message in it. Kafka tool confirms that the message is sent by the producer.
CODE:
prod1=rkafka.createProducer("127.0.0.1:9092")
rkafka.send(prod1,"test","127.0.0.1:9092","Testing once")
rkafka.closeProducer(prod1)
consumer1=rkafka.createConsumer("127.0.0.1:2181","test")
print(rkafka.read(consumer1))
Output:
[1] ""
Desired Output would return "Testing once".
In order to read the messages of a topic that have already been written to the topic (before the consumer has been started) you need to set offset value to the smallest possible (equivalent to --from-beginning). According to rkafka docs autoOffseetReset argument defaults to largest
autoOffsetReset
smallest : automatically reset the offset to the
smallest offset largest : automatically reset the offset to the
largest offset anything else: throw exception to the consumer
Required:Optional Type:String default:largest
In order to be able to consume messages you need to set autoOffsetReset to "smallest".
consumer1=rkafka.createConsumer("127.0.0.1:2181","test", autoOffsetReset="smallest")
Update: This Code Works:
library(rkafka)
prod1=rkafka.createProducer("127.0.0.1:9092")
rkafka.send(prod1,"test","127.0.0.1:9092","Testing once")
rkafka.send(prod1,"test","127.0.0.1:9092","Testing twice")
rkafka.closeProducer(prod1)
consumer1=rkafka.createConsumer("127.0.0.1:2181","test",groupId = "test-consumer-
group",zookeeperConnectionTimeoutMs = "100000",autoCommitEnable = "NULL",
autoCommitInterval = "NULL",autoOffsetReset = "NULL")
print(rkafka.read(consumer1))
print(rkafka.readPoll(consumer1))
rkafka.closeConsumer(consumer1)
The key is to restart Kafka after deleting the logs it generates.
Due to short circuit rules I can't write something like the this:
message = "nada"
if message != "success" || message != "login successful"
error("get_response() failed with message returned of: $message")
end
Instead I've had to write the something like this to get it working:
message = "nada"
if message != "success" ? message != "login successful" : false
error("get_response() failed with message returned of: $message")
end
The second way seems ... "clunky", so I feel like I've missed something when going through the julia manual. Is there a standard way to write multiple OR conditions? (or a better way to write multiple OR conditions than what I have).
Assume the message could be any string, and I only want to do something if it isn't "success" or "login successful".
This simply seems to be a mistake in the use of or/and vs negations. I guess that what you wanted was
message = "nada"
if !(message == "success" || message == "login successful")
error("get_response() failed with message returned of: $message")
end
or equivalently
message = "nada"
if message != "success" && message != "login successful"
error("get_response() failed with message returned of: $message")
end
which both work for me. The original condition
message != "success" || message != "login successful"
is always true since any message has to be unequal to at least one of the strings "success" and "login successful".
I'm trying to make a program that asks the user to enter a length and then set the equipament for this length.
Could someone help me? This is what I did:
function [] = config_length (gpib, loop_l)
loop.length = loop_l;
loop.noiseA=0;
loop.noiseB=0;
[err]=DLS414_SetupLoop (gpib,loop)
endfunction
getLength = x_dialog(['Loop Length';'Enter the length of loop:'],'');
config_length (14, getLength)
I do not understand why the function config_length is not reading the value of getLength. And when I press cancel, the program gives me an error.
Thanks,
You could also use getvalue. I think this looks better than a multiline dialog
Working example
function [] = config_length (gpib, loop_l)
loop.length = loop_l;
loop.noiseA=0;
loop.noiseB=0;
printf('Config_length called with gpib %f and loop_l %d', gpib, int(loop_l));
endfunction
[ok,loop_length]=getvalue("Enter the length of loop",["loop_length"],list("vec",1),["0"]);
config_length(14, loop_length);