call a toolbar button click from another form - vb6

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

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.

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.

Tabbing between radio buttons in VB6

I have a form which consists of six radio buttons within a frame which are mutually exclusive and one command button.
I already gave different tab-index to each radio button but at the run time by pressing tab focus skipped out of the radio buttons.
so how to give focus to another radio button by pressing TAB?
As others have said above this is intended behaviour. If you really wish to achieve this then the only way I can think to do this is place each radio button on a separate picture box (BorderStyle = None, TabStop = False). This will then work but you won't be able to use arrow keys to move between the radio buttons, only tabbing.
Private Sub Option1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Option2.SetFocus
End If
End Sub
KeyAscii=9 is the code for the Tab key. But you must do it for all of your radio buttons.
If you add your radio buttons belonging to the same radio button having indices 0, 1, 2 you can do it like this:
Private Sub Option1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 9 Then
If Index < Option1.Count - 1 Then
Option1(Index + 1).SetFocus
Else
Option1(0).SetFocus
End If
End If
End Sub

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