Lists box manipulation on button click in VB 6.0 - vb6

Hello
I am doing a small I.T assignment where we have to create a database library type borrowing system and I have two list boxes listbox 1 is where all the games are listed and you can chose to borrow them the other one is where the games go to after you click the button that transfers them to listbox 2.
Aso how can I add a button that when you click it adds a new Item (game) to the first listbox and so you can borrow that one two
Thank you for your help.

Assuming two list boxes (listbox1 and listbox2) and a command button (cmd1) on a VB 6 form named Form1
private sub Form_Load()
listbox1.AddItem "game 1"
listbox1.AddItem "game 2"
listbox1.AddItem "game 3"
end sub
Private Sub cmd1_click ()
If listbox1.listindex >-1 then
'Add the selected item from listbox1 to list box 2
listbox2.AddItem listbox1.List(listbox1.ListIndex)
'Remove selected item from listbox1
listbox1.removeitem(listbox1.listindex)
End If
End Sub

Related

What can I do for displaying 1 to 1000 numbers in combo box in VB6.0 using coding?

I have tried a coding that contains a loop to display 1 to 1000 numbers in combo box. I am just a learner to Visual Basic. So I can't able to make that through coding. The coding is as follows:
Private Sub Combo1_change()
Dim a As Integer
While (a <= 1000)
Combo1.AddItem(a, [1]) = a
a=a+1
Wend
End Sub
I have experienced "no error" but none of the number is displayed in the combo box while running. Please, help me by modifying the above code or redirecting me to any other method of inserting elements in combo box.
The Combo1_Change event is definitely not the place you should be looking. That event is fired when the text in the combo is changed. Try the Form_Load event instead:
Private Sub Form_Load()
Dim a As Integer
For a = 1 To 1000
Combo1.AddItem a
Next
End Sub
Please note, a combo with 1000 items isn't the best user experience.

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

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

Creating A Menu programmatically DevExpress

How to create a menu dynamically?
In detail I want to:
Create a new ribbon page (tab, I think it's called ribbon page)
Next create a title for the page
Next add 2 ribbon groups and add titles to them
Next add 3 bar button items to the first ribbon group
How to accomplish this?
Dim menu As New RibbonControl
Dim aPage As New RibbonPage("Nicks Page")
'groups
Dim aGroup1 As New RibbonPageGroup("1st Group")
'ADD BUTTONS TO RIBBON GROUP HERE
Dim i As New DevExpress.XtraBars.BarButtonItem()
i.Caption = "Nicks Button"
aGroup1.ItemLinks.Add(i)
Dim i2 As New DevExpress.XtraBars.BarButtonItem()
i2.Caption = "Nicks Other Button"
aGroup1.ItemLinks.Add(i2)
aPage.Groups.Add(aGroup1)
menu.Pages.Add(aPage)
Me.Controls.Add(menu)

How to display data in one form upon double-clicking an item in another form's listview

I have 2 forms (2 windows). In first window,I have a tree view (the children are the tables in DB.). On click of a any child, a list view (the data present in the table ) will be displayed on the right side of the tree view.
On double clicking on any row in the list view, another form will be opened. The current requirement is to display the data in the list-view in form2 opened on double clicking a single record.
Private Sub LV_DblClick()
Dim a As New Form2
Display_Temp_DATA
a.Show vbModal
End Sub
LV_DblClick() is in the form1 and it opens the form2. Now, Display_Temp_DATA has SQL query, which
fetches the record from the table and should be displayed in a list view in form2.
Private Sub Display_Temp_DATA()
On Error GoTo errHandler
'Dim liItem As ListItem
'Set liItem = a.ListView1.ListItems.Add(, , "Abcd")
Display_List_Two_Data "Select start, stop FROM tblsignal"
Exit Sub
errHandler:
MsgBox Err.Description
End Sub
I am able to open the form2, but I am finding difficult to display the data in the form2 list view. Any ideas on how to resolve this?
you can add module and variable to it and assign the value to that variable access it on the target form.
not sure but you can also use FormName.VariableName for static variable on the form.

Resources