JES f==None not working - jes

I'm using JES version 5.010. I'm trying to do this assignment for school:
For the first part of the assignment, you are going to write a
function that will select, using pickAFile(), a picture file to be
opened. If cancel is pressed in the pickAFile() dialogue box, then you
must ask the user if it was a mistake. If it was a mistake, open the
pickAFile() dialogue again, and repeat until it is either not a
mistake, or a picture file was selected. If a picture file is
selected, return the 'made' picture, otherwise (i.e. cancel was pushed
and the user indicated that it was NOT a mistake) return an error
message. NOTE: the JES function requestString (see JES
Functions-->Input/Output) should be used when asking the user if the
pressing of 'cancel' was a mistake.
For some reason my if statement, if f==None, isn't working properly and I have no clue why. My code is below
def assign3PartA():
noFile = True
while noFile:
f = pickAFile()
if f==None: #This is what isn't working
noFile=mistake()
noFile = False
print "Invalid option, you must select a picture to continue!"
else: #Working fine
pic = makePicture(f)
show(pic)
break
def mistake():
ask = requestString("Did you press cancel by mistake? Enter yes or no. ")
if ask == "yes" or ask == "Yes":
return True
elif ask == "No" or ask == "no":
return False
else:
print "Try again. Please enter either yes or no."
mistake()
I have also tried if f is None as well and that didn't work.
Any help you can give is appreciated.

I found my error sigh. I get needed to put None in quotation marks.
if j == "None":

Related

Prevent user from Enter-pressing on MESSAGE type I?

Is there any way to disable the enter key when a MESSAGE TYPE I is displayed? The users are just pressing away the note without reading it.
We want to force them to actually click the green button to confirm the message instead (Yes, I know it's dumb, but I was tasked to implement this so wcyd).
SELECT SINGLE text
FROM ZWM_MATVERMERK
INTO lv_verm
WHERE matnr = <lf_main>-matnr
AND werk = <lf_main>-werks.
IF lv_verm IS NOT INITIAL.
MESSAGE | Note: { lv_verm } | TYPE 'I'.
CLEAR lv_verm.
ENDIF.
You can use the function module POPUP_TO_CONFIRM to create a modal dialog which gives you more control than the standard MESSAGE TYPE 'I'.
Among others, this function module has the parameter default_button which decides which button is the one highlighted when the popup appears and thus will be considered clicked when the user just presses enter.
DATA lv_answer TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Are you sure?'
default_button = 2
IMPORTING
answer = lv_answer.
" lv_answer will be '1' for yes, '2' for no and 'A' for canceling the dialog.
If you want to make really really sure that the user read the message, then one option is to use POPUP_TO_GET_ONE_VALUE to make the user confirm that they read the message by reciting something from it.
DATA lv_answer TYPE c.
DATA lv_value TYPE pvarfield.
CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
EXPORTING
titel = 'Safety check'
textline1 = |This operation will affect { lv_count } items.|
textline2 = |When you are aware of that, please enter "{ lv_count }" below:|
valuelength = 20
IMPORTING
answer = lv_answer
value1 = lv_value.
IF lv_answer = 'J' and lv_value = lv_count.
"...proceed...
ENDIF.
This will look like this:
By the way: There are a lot more standard function modules starting with POPUP_* which cover a wide variety of common use-cases for modal dialogs. Some of those can be really useful.

Mirc script to find exact match in customer list

I am using this to find customer name in text file. Names are each on a separate line. I need to find exact name. If searching for Nick specifically it should find Nick only but my code will say found even if only Nickolson is in te list.
On*:text:*!Customer*:#: {
if ($read(system\Customer.txt,$2)) {
.msg $chan $2 Customer found in list! | halt }
else { .msg $chan 4 $2 Customer not found in list. | halt }
}
You have to loop through every matching line and see if the line is an exact match
Something like this
On*:text:*!Custodsddmer*:#: {
var %nick
; loop over all lines that contains nick
while ($read(customer.txt, nw, *nick*, $calc($readn + 1))) {
; check if the line is an exact match
if ($v1 == nick) {
%nick = $v1
; stop the loop because a result is found
break;
}
}
if (%nick == $null) {
.msg $chan 4 $2 Customer not found in list.
}
else{
.msg $chan $2 Customer found in list!
}
You can find more here: https://en.wikichip.org/wiki/mirc/text_files#Iterating_Over_Matches
If you're looking for exact match in a new line separate list, then you can use the 'w' switch without using wildcard '*' character.
From mIRC documentation
$read(filename, [ntswrp], [matchtext], [N])
Scans the file info.txt for a line beginning with the word mirc and
returns the text following the match value. //echo $read(help.txt, w,
*help*)
Because we don't want the wildcard matching, but a exact match, we would use:
$read(customers.txt, w, Nick)
Complete Code:
ON *:TEXT:!Customer *:#: {
var %foundInTheList = $read(system\Customer.txt, w, $2)
if (%foundInTheList) {
.msg # $2 Customer found in list!
}
else {
.msg 4 # $2 Customer not found in list.
}
}
Few remarks on Original code
Halting
halt should only use when you forcibly want to stop any future processing to take place. In most cases, you can avoid it, by writing you code flow in a way it will behave like that without explicitly using halting.
It will also resolve new problems that may arise, in case you will want to add new code, but you will wonder why it isn't executing.. because of the darn now forgotten halt command.
This will also improve you debugging, in the case it will not make you wonder on another flow exit, without you knowing.
Readability
if (..) {
.... }
else { .. }
When considering many lines of codes inside the first { } it will make it hard to notice the else (or elseif) because mIRC remote parser will put on the same identification as the else line also the line above it, which contains the closing } code. You should almost always few extra code in case of readability, especially which it costs new nothing!, as i remember new lines are free of charge.
So be sure the to have the rule of thump of every command in a new line. (that includes the closing bracket)
Matching Text
On*:text:*!Customer*:#: {
The above code has critical problem, and bug.
Critical: Will not work, because on*:text contains no space between on and *:text
Bug: !Customer will match EVERYTHING-BEFORE!customerANDAFTER <NICK>, which is clearly not desired behavior. What you want is :!Customer *: will only match if the first word was !customer and you must enter at least another text, because I've used [SPACE]*.

How do I perform an action on a field for Swift UI Tests based on the contents/state of the field?

I have a usernameField. On initial state, the field is empty. If I log in successfully, and log back out, it remembers my username for me.
Trying to create a test case for iOS (in swift) that will clear out the field (use the clearText button) if the field has content and then enter a desired string. If it's empty, it needs to skip the clearText button action (since it doesn't exist when the field value is nil) and go straight to entering the username.
It always skips the if statement, even when it's true. Looks for the clearText button, and fails. Works if there's a value in the field, though.
Tried lots of different approaches, but here's my best current working code. Open to any suggestions, as I have no one to really help me learn this stuff. I'm sure I'm just missing something fundamental:
let staffusernameloginfield = app.scrollViews.otherElements.textFields["staffUsernameLoginField"]
staffusernameloginfield.tap()
func checkUsernameFieldContents() {
if staffusernameloginfield == (Content:nil) {
staffusernameloginfield.typeText("owner")
}
else {
elementsQuery.buttons["Clear text"].tap()
staffusernameloginfield.typeText("owner")
}
}
checkUsernameFieldContents()
Have also tried:
if staffusernameloginfield == ("") {
staffusernameloginfield.typeText("owner")
}
else {
elementsQuery.buttons["Clear text"].tap()
staffusernameloginfield.typeText("owner")
}
}
I know that I could hack it by having it always enter a value into the field and then clear it out and enter the desired value, but in this test case, I'm not trying to test for that.
I would compare the value (raw attribute of the element). This type can vary so I always do it as a string:
if staffusernameloginfield.value as! String == "" {
staffusernameloginfield.typeText("owner")
}
else {
elementsQuery.buttons["Clear text"].tap()
staffusernameloginfield.typeText("owner")
}
Now it should enter 'owner' if it sees there is no value in staffusernameloginfield.
to check if the textfield is empty:
app.textFields["signInEmailAddressTextFieldLabel"].value as? String == ""
if the textfield is empty, then that's true
I usually use an assert to check if the value is empty or not, in this example the value is equal to a variable incorrectPassword:
XCTAssertEqual(app.textFields["\(passwordSecureTextFieldLabel)"].value as? String, incorrectPassword)

Is there a way to store message box settings to be used repetitively in Powershell?

I'd like to use the same message box repetitively in a Powershell script, without having to reiterate all the settings each time. I initially thought that I would store it as a variable:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
But as I found out this simply stores the user's response to the message box in the variable.
What I would like to do is something similar to the following pseudo-code:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
While(true){
If(condition){
$StandardMessage
}
If(condition2){
$StandardMessage
}
}
Where the conditions would be time-based. This is essentially displaying a message at specified times during the day.
Asked another way (and perhaps more clearly): Is it possible to 'define' a messagebox without actually 'showing' it?
You need to use a Function my good man!
Function Show-MyMessage{
[System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
}
While(true){
If(condition){
Show-MyMessage
}
If(condition2){
Show-MyMessage
}
}
Edit: Personally I have this function on hand for several of my scripts to use as needed:
Function Show-MsgBox ($Text,$Title="",[Windows.Forms.MessageBoxButtons]$Button = "OK"){
[Windows.Forms.MessageBox]::Show("$Text", "$Title", [Windows.Forms.MessageBoxButtons]::$Button, [Windows.Forms.MessageBoxIcon]::Information) | ?{(!($_ -eq "OK"))}
}
Then I can just call it as needed, like:
Show-MsgBox -Title "You want the truth?" -Text "You can't handle the truth!"
And I've got a pop up with the text and title I want, and an OK button.
Buttons can be specified (there's a pop-up for it in the ISE to give options), and title can be excluded if I am feeling lazy. Only thing I really have to feed it is the message.

How to know that the navigate function didnt work [VBA]

How do I prove that navigate function worked? I have this code:
Dim oBrowser As InternetExplorer
Set oBrowser = New InternetExplorer
oBrowser.Visible = True 'oBrowser.Silent = True
oBrowser.navigate "www.google.com"
I tried looking here but I don't get it: the return value is a long type? I tried:
Dim test as long
test = oBrowser.navigate "www.google.com"
msgbox test
'to see the value of the return
But it wont work
To add to the other answer: You could just use the below code, and not worry at all about the return of navigate. You could use MsgBox (as I have below to match your question), you could use a Boolean Success = True / False where relative, or just an old Debug.Print("Success/Error") where needed.
Then add the error handling into that.
Sub ie_open()
On Error Goto MyErrorCode
Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.google.com"
ie.Visible = True
MsgBox "Hurray this worked!"
MyErrorCode:
MsgBox "An error Occured!" & Err
End Sub
If I understood you properly you want to know whether the code snippet works or not? Right? If that's the case you simply do some error handling and if there's an error then you will know that there's some error. An example is below
If IsError(write statement you want to test) Then
goto errorMessage
Else
'do something if there is a match
End If
errorMessage:
'The handling of the error