Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

dealing with cumbo box and textbox

hi, i'm deena

i'm working with VB 6.0. I have a combo box. when i select an item from the combo box, i want the system that i'm developing, to generate automatically an output in a textbox, with respect to the current item that i have selected in the combo box. The next time that I select another item from the combo box, the system should generate another output into the textbox, with respect to the new item that i have selected. The name of my cumbo box is 'cboStaffName' and the name of my textbox is 'txtStaffName'.
I was thinking about using the 'Select Case'. what is the piece of code to relate the item chosen in the cumbo box so as to display an output in the textbox. Where should i include the code? i have been using 'list' for the cumbo box.

thanks
[841 byte] By [deena2209] at [2007-11-11 9:58:08]
# 1 Re: dealing with cumbo box and textbox
No need to any select cases it's simple :

In the combobox click event [cboStaffName_Click] put this :

txtStaffName = cboStaffName.List(cboStaffName.ListIndex)

To have more effcient code put it again in the event "GotFocus"

.listindex gives you the index of the selected item so you assign to the text the
.list(index_of_the_selected_item)
Amahdy at 2007-11-11 17:23:32 >
# 2 Re: dealing with cumbo box and textbox
hi,
i'm deena

I'm using VB 6.0. Infact, what i want is that when i select a name in my cumbo box, the software should automatically generate what is the type of staff the person i selected in the cumbo box is and display it in a textbox. For example, if i select 'Tom' in the cumbo box, then 'engineer' should be displayed in the textbox. Another time when i select 'Jane' in the cumbo box, then 'secretary' should be displayed in my textbox. The name of my cumbo box is 'cboStaffName' and the name of my textbox is 'txtStaffType'. i'm thinking about using the 'ListIndex' from the cumbo box and the 'select case' statement' . Can you please, provide me with the exact code. Where should i placed the code? I don't want to use a database because i do not have much information to processed.

Thanks
deena2209 at 2007-11-11 17:24:28 >
# 3 Re: dealing with cumbo box and textbox
Sol 1:
Make another combobox that contains their jobs successivley and when you select an item from the first combo box [click event] display in the textbox the same index of the selected item from the second combo box .

Sol 2:
Select case isn't very good idea but if u wanna use it it sould be like this :

Select case combobox.listindex
case 1
textbox = "job1"
case 2
textbox = "job2"
.
.
.
end select
Amahdy at 2007-11-11 17:25:27 >
# 4 Re: dealing with cumbo box and textbox
Ok, it's comboBox not cumboBox. Also it would depend on where the other information is stored. If it is in a database the you will need to open a connection to the database and then open a recordset for the user table that returns the additional info based on the criteria where user = selected user. Then from the recordset you can get the data from the staff field and set the textBox to that value. Make sure to close the recoredset and connection; as well as setting the object variables to Nothing when the form is closed.
Ron Weller at 2007-11-11 17:26:32 >