What is the return value for the x button in VBScript? - vbscript

What is the return value for the big red "X" button commonly found in dialog boxes like MsgBox? That is commonly used for closing out of the program.
So, how can I call upon the x button in VBScript?

It all depends. After reading the docs for MsgBox, InputBox, and Popup, you need to experiment/test.
The return value of MsgBox after clicking X depends on the buttons in the dialog:
>> WScript.Echo MsgBox("no cancel, X returns 1 (ok)")
>> WScript.Echo MsgBox("with cancel, X returns 2 (cancel)", vbOkCancel)
>>
1
2
I think, that Popup works similarly; you should test carefully.
InputBox returns Empty if you press X or Cancel:
>> WScript.Echo TypeName(InputBox("just X me"))
>>
Empty

Related

how to handle condtion in VBScript Loop

I've two Input Fields and Two Submit Button on a page.
InputField1 "Code"
InputField2 "Amount"
Button1 "Save"
Button2 "Save And Add Another"
Having trouble writing the logic. i should only hit save when i've only one item item and move on. if mutltiple then i need to hit button2 and follow the process and at the end i need to hit save. Any help will be highly apreciated. I'm just not sure how do i handle the save button.
sCode="100:500"
sAmount="500:500"
arrCCode=Split(sCode,":")
arrAmount=Split(sAmount,":")
For i = 0 To UBound(arrCCode)
If i > UBound(arrCCode) Then
Exit For
Else
MsgBox arrCCod(i)
MsgBox arrAmount(i)
End If
Next
I think i got it,,,
sCode="100:500"
sAmount="500:500"
arrCCode=Split(sCode,":")
arrAmount=Split(sAmount,":")
For i = 0 To UBound(arrCCode)
'If i > UBound(arrCCode) Then
'Exit For
'Else
MsgBox arrCCod(i)
MsgBox arrAmount(i)
If i = UBound(arrCCod) Then
msgbox "Save"
Exit For
Else
Msgbox "Save and add"
End
'End If
Next

Not able to select WpfMenu Button inside WpfTable

I need to perform Right Click in the Middle of WpfTable, then WpfMenu appears and I want to select a particular Option from it.
See the Screenshot for more details:-
Here is Code I am trying:-
Function IncidentCancellAllActions()
Dim Rowcnt
Rowcnt = SwfWindow("VisionCommandClient").SwfObject("VisionCC_Incident_ActionsTab_SWO").WpfWindow("VisionCC_Incident_ActionsTab_WpfWin").WpfTable("VisionCC_Incident_ActionsTab_WpfTable").RowCount
If Rowcnt > 0 Then
SwfWindow("VisionCommandClient").SwfObject("VisionCC_Incident_ActionsTab_SWO").WpfWindow("VisionCC_Incident_ActionsTab_WpfWin").WpfTable("VisionCC_Incident_ActionsTab_WpfTable").ActivateCell
SendFromKeyboard("1-SHFT-F10")
wait 5
'SwfWindow("VisionCommandClient").WpfWindow("VisionCC_ResourceStatusList_WpfWin_2").WpfMenu("VisionCC_Action_WPM").Select "Cancel All"
msgbox SwfWindow("VisionCommandClient").WpfWindow("VisionCC_ResourceStatusList_WpfWin_2").WpfMenu("VisionCC_Action_WPM").ShowContextMenu
SwfWindow("VisionCommandClient").WpfWindow("VisionCC_ResourceStatusList_WpfWin_2").WpfMenu("VisionCC_Action_WPM").Select "Cancel All"
wait 2
Else
Exit Function
End If
End Function
After right Click, It is not clicking on WpfMenu option "Cancell All".
Had this problem and currently working around the problem using '.Type' method:
WpfWindow("MyWindow").WpfButton("Item-Menu").ShowContextMenu
WpfWindow("MyWindow").WpfMenu("List-Menu").Exist(1)
menuItems = WpfWindow("MyWindow").WpfMenu("List-Menu").GetVisibleText
menuItems = replace(menuItems, chr(13),"")
for each menuItem in split(menuItems,chr(10))
WpfWindow("SAP Work Manager").WpfMenu("List-Menu").Type micDwn
Wait 0,400
If instr(1, menuItem, "MenuItemToClick") > 0 Then 'replace MenuItemToClick with the menu item text.
Exit for
End If
next
WpfWindow("SAP Work Manager").WpfMenu("List-Menu").Type micReturn
This works as long as the order of menu items doesn't change. Waits are included because ive noticed HP-UFT doesn't check that the object is fully loaded before doing the next task.

AppleScript less than number or greater than number

I am having an error in AppleScript when I use less than or greater than operators consecutively. I probably didn't explain that very well, so I will post the code.
**set good to false**
**repeat until good = true**
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number
if oneTen is less than 0 then
display dialog "below" buttons {""} default button 1
else if oneTen is greater than 10 then
display dialog "above" buttons {""} default button 1
else
set good to true
end if
**end repeat**
I am trying to take the input from the prompt, and keep the user from entering anything below 0 or above 10. Could you post some code to do this well?
I want something similar to this.
**set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number**
**if oneTen is less than 0 or greater than 10 then**
**-- make them do the prompt again**
**end if**
Try:
repeat
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number
if oneTen is less than 0 then
display dialog "below" buttons {""} default button 1
else if oneTen is greater than 10 then
display dialog "above" buttons {""} default button 1
else
exit repeat
end if
end repeat

Set bounds property for "choose from list" in AppleScript?

I'm making an applet that prompts users to choose from a list, and my list currently has 169 items. When the list is generated, the window extends from the top of the display to the bottom, a bit overwhelming for a user.
I'm wondering if anyone knows of a way to edit the bounds property of the window generated by "choose from list?"
Here's the code I'm using (not including separate code to compile the list and store it in "pkgList"):
set userChoice to (choose from list pkgList with title "Title" with prompt "Choose file:" OK button name "OK" cancel button name "Cancel" without empty selection allowed) as string
I'm very new to AppleScript, so detailed explanations and analogies are much appreciated. :)
You might use CocoaDialog instead:
set l to {"a a", "b"}
set l2 to ""
repeat with i in l
set l2 to l2 & quoted form of i & " "
end repeat
do shell script "/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog \\
standard-dropdown --title Title --text Text --items " & l2
set {button, answer} to paragraphs of result
if button is 1 then return
item {answer + 1} of l

How do I mimic pressing the "down" arrow in vb6?

I made a form and created a command button control. I would like to make it so that when the user presses the command button it sends a keystroke to a listbox of my choice.
Specifically, I want the command button to send a "down" arrow keystroke to a listbox (which will have focus) so that it goes from the current item to the next item.
How do I do this?
Let's say the name of my listbox is "lstFruits". I gave it focus, then tried SendKey.
Form.lstFruits.SetFocus.
SendKeys.Send ("{DOWN}")
Got the error "Argument not optional".
There is no need to emulate a keystroke, you can control the listbox in code;
lstFruits.SetFocus
if ((lstFruits.listindex + 1) < lstFruits.listcount) then
lstFruits.listindex = lstFruits.listindex+ 1
endif
Edit
Dim strName As String
strName = "lstFruits"
Dim lst As VB.ListBox: Set lst = TheForm.Controls(strName)
lst.SetFocus
If ((lst.ListIndex + 1) < lst.ListCount) Then
lst.ListIndex = lst.ListIndex + 1
End If

Resources