this is the last part of my script
MsgBox("text")
vbOK
WScript.Quit
End If
x=MsgBox("text",1,"text")
vbOK
If vbOK Then
do
Loop
vbCancel
If vbCancel Then
WScript.Quit
MsgBox("text")
but somehow it wont work. i use vbsedit, but when i press start it tell me to add 'end',so i do but then it tell me to add'if'. after ive done that it tells me to add 'end' again, and so it goes on.
how can i fix it?
im new to VBS and spent 5h trying to find a solution.
When in doubt, read the documentation:
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
MsgBox(prompt[, buttons][, title][, helpfile, context])
Arguments
[...]
buttons
Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. See Settings section for values. If omitted, the default value for buttons is 0.
As you can see the button layout of VBScript message boxes is controlled via the second parameter, and the function's return value indicates which button was pressed by the user.
If for instance you want to present a user with a yes/no choice you could do something like this:
choice = MsgBox("question", vbYesNo, "title")
Select Case choice
Case vbYes : MsgBox "User pressed 'Yes'."
Case vbNo : MsgBox "User pressed 'No'."
Case Else : MsgBox "Something unexpected happened.", , "Error"
End If
Related
In my vb6 project, I created my own msgbox using a form, due to difficulties in changing
the font/language of in-built msgbox. A search with google gave the idea of own msg-
box rather than trying msgbox of VB. Now the problem is : - when the user exits the
program, 3 options are given: to close, to restart and to cancel exit. The user need not
again go through the process of giving password etc in restart option. If I give cancel =
true in the QueryUnload event, then 2nd option does not work, 3rd option works. If
cancel = true is not given, 2nd option works, but 3rd option does not. It appears that
the main form does not get unloaded if cancel = true. Unless & until the main form
unloads, the program will not work with the fresh data to be given by the user in the
initial Form. Since the code after "msgbox.show" depends on options, it is not possible
to write that code in the same sub, not even in the same form code. Is there any way
to stop the subsequent code after "msgbox.show" and continue the same after getting
option? (like in the in-built msgbox of VB.) I am not an expert in VB, so please correct
if I made some mistake; also help with advice/suggestions.
EDIT:- [Extended explanation]
The 3 forms in my project:
Initial form for password, data etc. This is input Form for user.
Main Form. This Form shows the results after process of input.
frmMsgBox. This is a custom msgbox created using a form.
Main Form code portion. Code for closing the program:
Private Sub Form_QueryUnload(Cancel as.......)
cancel = True
frmMsgBox.Label1.caption = Do you wish to 1.Exit 2.Restart
3.Cancel the exit?
frmMsgBox.Show
End sub
(The above msgbox is almost like an in-built msgbox in VB with
vbYesNoCancel buttons) The message is in regional language,
which was the main reason forced me to use my own msgbox.
After MsgBox appears, the user selects one of the above options
using 3 commandButtons placed in that Form. The code after
clicking these buttons is written in the code portion of frmMsgBox:
Command1_Click 'This is for Exit from the Program.
All Forms.unload, All forms set to nothing, end.
Command2_click 'This is for restarting the Program.
Unload Main Form, set to nothing
Load Initial Form
Initial Fom.show
frmMsgBox.Hide
Command3_Click 'This is for cancelling the exit request.
Main Form.Show
frmMsgBox.Hide
With the above code, I have no problem with options 1 & 3,
i.e; to exit from the program or to start. The frmMsgBox hides,
the initial form shows - these are OK, but the main form does
not unload nor it is removed from memory. Because of this,
whatever new data is given by the user in the initial form now
is not being processed, the main form is struck with the old results.
If cancel = true is removed from the code above, Options 1 & 2
are OK, but option 3 does not work. Then the Main Form loses
all its results (all labels, texts etc in that Form turn blank.)
I'm using Appium with the Cucumber Framework and utilizing the Ruby language.
My scenario is my app has multiple buttons that I want to call with a single Gherkin statement "I press the "*" button" where * is modular. I use it for Save, Back, Cancel, Expand, Yes, No, etc buttons with simple text. Here's an example:
And I press the "Create a Note" FAB button
And I am on the Create a Note Screen
Then I tap Back
>> And I press the "Yes" button
Now currently with my app on android there are multiple versions of the "Back" button and they're not all formatted the same. Some have texts that reads "BACK", some are "Back", and some are "back". I designed a series of if statements to handle this discrepancy until I can get the developers to standardize the text they use for these buttons:
Then(/^I press the "([^"]*)" button$/) do |button_text|
sleep 1
#button_text = button_text
binding.pry
if find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").displayed? == true
find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").click()
else
#button_text.capitalize()
if find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").displayed? == true
find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").click()
else
#button_text.upcase()
if find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").displayed? == true
find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").click()
else
#button_text.downcase()
if find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").displayed? == true
find_element(xpath: "//android.widget.Button[#text='#{#button_text}']").click()
else
fail("Could not find a permutation of that button")
end
end
end
end
sleep 2
end
My thinking is that I'll save the button_text argument to a variable, #button_text, and then use the .displayed? method to check if that version of the button is available. If it is I pass the .click() method, and if it isn't I alter the text of the variable via the .capitalize, .upcase, and .downcase methods. I'm sure that using nested if statements isn't the most ideal way to do this so I would love some assistance on a better way to write that statement.
The issues I receive is I get "An element could not be located using the given search parameters" error whenever I get to this line of code. It seems like the .displayed? method doesn't return a value and triggers appium to stop the test.
I want appium to check if that version of the button is present, then adjust the variable and check the new version for upcase, downcase, and capitalize. Any and all assistance would be greatly appreciated.
When you're finding the elements, try setting their text to all uppercase, and then checking for one version of the word that you're searching for.
I.e. BacK or back or BACK would all become "BACK"
I have a dialog which opens to input and store user input(name).
Upon error (which is is either due to no name entered or the name already exists) i want the dialog to re-open. Finally, if the second attempt fails again, open a dialog which states that and exit.
The problem is, whether the name exists or does not, all 3 dialogs are ALWAYS displayed.
What am i missing?
try
display dialog "Specify a new folder name:" default answer "John The Dog"
set newName to (text returned of result)
on error errorMessage number errorNumber
end try
try
display dialog "Specify a DIFFERENT folder name:" default answer "John The Dog12"
set newName to (text returned of result)
on error errorMessage number errorNumber
end try
try
display dialog "NAME ALREADY EXISTS! The program will now exit." with icon caution buttons {"EXIT"}
end try
Thanks!
Try this. Note I did not test this but it should work. Just put this code in place of your code where you try to get the folder name.
You can basically create as many dialogTexts/defaultAnswers combinations as you want and it will work. Good luck.
-- get the names of all the folders in the targetFolder
tell application "Finder" to set targetFolderNames to name of folders of folder targetFolder
set dialogTexts to {"Specify a new folder name:", "Specify a DIFFERENT folder name:"}
set defaultAnswers to {"John The Dog", "John The Dog12"}
repeat with i from 1 to count of dialogTexts
display dialog item i of dialogTexts default answer item i of defaultAnswers
set newName to (text returned of result)
if newName is not "" and newName is not in targetFolderNames then exit repeat
if i is (count of dialogTexts) then
display dialog "NAME ALREADY EXISTS! The program will now exit." with icon caution buttons {"EXIT"} default button 1
return input
end if
end repeat
-- do something with newName
I'm trying to get simple user authentication going via AppleScript. The goal is to have the passwords check against each other and then continue on with the rest of the script. Right now the script can recognize mis-matched password if password_initial is correct and password_final is incorrect, but if password_initial is incorrect and password_final is correct there is no logic to check against itself.
set user_name to ""
display dialog "Please enter your user name" default answer "firstname.lastname"
set the user_name to the text returned of result
set password_initial to ""
display dialog "Please enter your password:" default answer "" with hidden answer
set password_initial to the text returned of result
display dialog "Please verify your password below." buttons {"OK"} default answer "" with hidden answer
set password_final to text returned of result
considering case
repeat while password_final is not equal to password_initial
display dialog "Passwords do not match, please re-enter your password below." buttons {"OK"} default answer "" with hidden answer
set password_final to text returned of result
end repeat
end considering
--do something
Can anyone point me in the right direction on this? Thanks!
Whoa whoa whoa, handlers and global variables? No need for all that, why not just throw the whole thing into a loop and then break it when we get what we want?
set user_name to text returned of (display dialog "Please enter your user name" default answer "firstname.lastname")
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
#Rest of script here...
The trick with something like this is to use Handlers.
These are bits of code that can be called to run within your script as many times as you want and save on rewriting the same code over again.
They can also help you not use repeat loops like you are doing. Also you should always add the 'cancel' button to your display dialogs. If there is bad logic in a repeat loop or a handler call the user needs a way to exit it.
I have also made some of the display dialog text dynamic. and used some global variables
I have tested this code which has Handles and the calls to them and it works well in my testing. But it is an example and should give you enough to move forward.
set displays to {"Please enter your password:", "Please verify your password below.", "Passwords do not match, please re-enter your password below."}
set user_name to add_user_name() #get user name
set thedisplay to item 1 of displays #set the fisrt dialog for the password display to the first item in displays
global thedisplay, displays, password_initial #global variables
set password_final to setDetails() #Call to start the password dialogs
--your code here ..
#HANDLERS
on setDetails()
set password_initial to add_password() #call to get user password
set password_final to verify_password() #call to get verify password
end setDetails
on add_user_name()
display dialog "Please enter your user name" buttons {"Cancel", "OK"} default answer "firstname.lastname"
set the user_name to the text returned of result
return user_name
end add_user_name
on add_password()
display dialog thedisplay buttons {"Cancel", "OK"} default answer "" with hidden answer
set password_initial to the text returned of result
return password_initial
end add_password
on verify_password()
set thedisplay to item 2 of displays #set the dialog for the password verify display to the second item in displays
display dialog thedisplay buttons {"Cancel", "OK"} default answer "" with hidden answer
set password_final to text returned of result
considering case
if password_final is not equal to password_initial then
set thedisplay to item 3 of displays #set the dialog for the password verify display to the third item in displays
my setDetails() # start over again asking for password as it did not does not match dialog displays will also change accordingly
else
set thedisplay to item 2 of displays #set the dialog for the password verify display to the second item in displays
end if
end considering
return password_final
end verify_password
this script works fine until the commands of the buttons, can someone tell my why i doesent work?
it says "button_pressed is not definded"
display dialog "bla" with icon alias ((path to me) & "Contents:Resources:my.icns" as string) buttons {"blu", "bli", "blaa"} default button 3
if the button_pressed is "blu" then
-- action for 1st button goes here
say "blu"
else if the button_pressed is "bli" then
-- action for 2nd button goes here
say "bli"
else
-- action for 3rd button goes here
say "bla"
end if
The appropriate way to do this is to use button returned:
display dialog "bla" with icon alias ((path to me) & "Contents:Resources:my.icns" as string) buttons {"blu", "bli", "blaa"} default button 3
set theResponse to button returned of the result
if theResponse is "blu" then
-- action for 1st button goes here
say "blu"
else ...
The error occurs because the variable button_pressed is NOT defined. All you have to do is add this line of code before the if block and it should work!
set the button_pressed to the button returned of the result
Variables (i.e. button_pressed) must ALWAYS be defined before they can be uesd. For example, this code will not function...
display dialog greeting --> ERROR
...while this one will:
set greeting to "Hello! I am now a defined variable!"
display dialog greeting