A Confirmation Box On Exit - vbscript

I want to have hta code such that:
When the user clicks on the "Close" button, it pops up a confirmation box.
If the user confirms "Yes", then it will quit otherwise it keeps running.
Thanks in advance.

In HTML, you need a close button, it can be an input with button type (but in fact, any part of an HTML page can get a 'onclick' property, like a in a table)
<input type="button" value="Close" onclick='F_closeConfirm'>
then the VB code should contain a function F_closeConfirm with something like this
Public Function F_closeConfirm()
'one way to ask
If MsgBox("Are you sure you want to quit?", vbYesNo, "Confirmation") = vbYes Then
'another way
iAnswer = MsgBox("Like, really quit?", vbYesNo, "Confirmation")
If iAnswer = vbYes Then
'method to close parent windows or tab, can differ but it's another topic
Window.Parent.Close
End If
End If
End Function

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

Programatically click a row in a listbox

When I click the a command button to close the form, the code requery's a cbo and listbox, moves the focus to the lstbox and a particular row. What I need to do is add some code that "clicks" the current row in the listbox that has the focus.
Here is the code I have on the click event.
If Forms![frmmain]![txtHidden] = "addok" Then
Forms![frmmain]![cboAuthor].Requery
Forms![frmmain]![LstAuthor].Requery
Forms![frmmain]![LstAuthor] = Me.AuthorID
Forms![frmmain]![txtHidden] = "AddDone"
DoCmd.Close acForm, "frmAddAuthorFly"
Forms![frmmain]![cboAuthor].Requery
Forms![frmmain]![LstAuthor].Requery
Forms![frmmain].[LstAuthor].SetFocus
<NEED TO INSERT SOMETHING HERE TO CLICK THE ROW"
Else
MsgBox "txt hidden is not addok"
DoCmd.Close acForm, "frmaddauthorfly"
End If
A click does nothing by itself, but you may have some OnClick code that runs. To do so, just call the OnClick event.
But all this requiring - and indeed "clicking" - shouldn't be needed; it seems as if you need to rethink your concept.

Different message on the message box

Private Sub btnEval_Click(sender As Object, e As EventArgs) Handles btnEval.Click
If cbAbuse1.Checked Or cbAbuse2.Checked Then
If cbBullied1.Checked Or cbBullied2.Checked Then
If cbDeprsn1.Checked Or cbDeprsn2.Checked Then
If cbGrief_Loss1.Checked Or cbGrief_Loss2.Checked Then
If cbSH1.Checked Or cbSH2.Checked Then
If cbStrsd1.Checked Or cbStrsd2.Checked Then
Else
End If
End If
End If
End If
End If
End If
End Sub
So this is my code, after I click the "btnEval" button it should show a message box with a different message depending on what check box is checked.
Not sure what you are asking but if you just wanted to know how to display a message box (I am assuming you are using VB.NET here) the code is:
Messagebox.Show("This is the content of my message box", "Message box title")
Hope that helps :)

return a value when a button is clicked in shoes ruby

I have an app using shoes. In the model, I have
def run()
query = get_queries
executeQuery(query)
run()
end
Then this get_queries will append some buttons to stack, say
button "do 1"
button "do 2"
button "do 3"
button "do 4"
If the user clicks on the button, get_queries should return the corresponding query (Sometimes it may ask the user for more info, so basically, it returns an array containing query and info). And then the buttons are removed.
However, I am confused as to how to let the buttons return value for that function. I thought of using a variable and check if the variable is updated by busy waiting, but I don't think that is the efficient/right way to do it.
Any suggestions? Or is there another way to this?
I think you need to make your program work somewhat differently. Make get_queries append the buttons to the stack, as it does now, but move the other things from the run method into another method that is called only after the button receives a click-event.
def on_click(button_number)
executeQuery(button_number)
run()
end
button "do 1" do
on_click 1
end
button "do 2" { on_click 2 }
button "do 3" { on_click 3 }
...

call a toolbar button click from another form

In VB6 I need to know how to call a button click event on anther form. The another form part is easy but how to pass the click event the proper method to "click" the right button on the toolbar is the real issue.
Here is the vent on the main form - i need to call the click event case "Copyfrom".
MainForm
Public Sub tbrMain_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case ToolBarItem.tbPrint
'(some code)
Case ToolBarItem.tbSave
'(some code)
Case ToolBarItem.tbCopyFrom
'(some code)
Case ToolBarItem.tbNEW
'(etc)
I tried
Mainform.tbrMain_ButtonClick()
and even tried passing the index number and key - no dice.
The event handler is expecting to receive a reference to an actual toolbar button, so you have to pass the toolbar button itself, not it's Caption or Key, e.g.:
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons(1)
Or, using the Call statement:
Call Form1.tbrMain_ButtonClick(Form1.tbrMain.Buttons(1))
If you set the Key properties on your toolbar buttons, you can use the Key property of the desired button in place of the (1):
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons("PrintButton")
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
If ButtonMenu.Key = "A" Then
MsgBox "Button-1"
ElseIf ButtonMenu.Key = "B" Then
MsgBox "Button -2"
ElseIf ButtonMenu.Key = "C" Then
MsgBox "Button -3"
ElseIf ButtonMenu.Key = "D" Then
MsgBox "Button -4"
ElseIf ButtonMenu.Key = "E" Then
MsgBox "Button -5"
End If
End Sub

Resources