whats the quickest way to get this program done

eclass

Active member
Joined
Jul 6, 2011
Messages
27
Programming Experience
Beginner
ok heres my problem that Im working on I know its supposed to be parallel arrays. Im creating a directory that shows employees names in a list box on the main form. When the user selects a name from the list box, the only thing is the app has to display the employee ID number, dept name, and telepjhone number on another form. The app should store all employee ID numbers in seperate arrays.


VB.NET:
ok cool so how does this look so far [COLOR=black][FONT=inherit]
[COLOR=blue][FONT=inherit]Public[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Class[/FONT][/COLOR] frmEmployeeDirectory [COLOR=blue][FONT=inherit]Dim[/FONT][/COLOR] mstrEmployeeNames() [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]String[/FONT][/COLOR] = {[COLOR=#A31515][FONT=inherit]"Anthony"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Billy"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Ashley"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"David"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Brittany"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Vanessa"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Craig"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Bria"[/FONT][/COLOR]} [COLOR=blue][FONT=inherit]Dim[/FONT][/COLOR] mintEmployeeID() [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Integer[/FONT][/COLOR] = {[COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2562"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2172"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2679"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2204"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2901"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2331"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2463"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"27072"[/FONT][/COLOR])} [COLOR=blue][FONT=inherit]Dim[/FONT][/COLOR] mstrDeparmentName() [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]String[/FONT][/COLOR] = {[COLOR=#A31515][FONT=inherit]"Legal"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Engineering"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Accounting"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"R&D"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]" Manager"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Help Desk"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Programmer"[/FONT][/COLOR], [COLOR=#A31515][FONT=inherit]"Legal"[/FONT][/COLOR]} [COLOR=blue][FONT=inherit]Dim[/FONT][/COLOR] mintPhoneNumber() [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Integer[/FONT][/COLOR] = {[COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"773-651-9087"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"773-342-3997"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"312-892-5420"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"708-430-3877"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"773-543-7943"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"312-692-1288"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"2463"[/FONT][/COLOR]), [COLOR=blue][FONT=inherit]CInt[/FONT][/COLOR]([COLOR=#A31515][FONT=inherit]"708-389-9090"[/FONT][/COLOR])} [COLOR=blue][FONT=inherit]Private[/FONT][/COLOR] Names [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Integer[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Private[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Sub[/FONT][/COLOR] frmEmployeeDirectory_Load([COLOR=blue][FONT=inherit]ByVal[/FONT][/COLOR] sender [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] System.Object, [COLOR=blue][FONT=inherit]ByVal[/FONT][/COLOR] e [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] System.EventArgs) [COLOR=blue][FONT=inherit]Handles[/FONT][/COLOR] [COLOR=blue][FONT=inherit]MyBase[/FONT][/COLOR].Load [COLOR=blue][FONT=inherit]End[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Sub[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Private[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Sub[/FONT][/COLOR] lstEmployeeNames_SelectedIndexChanged([COLOR=blue][FONT=inherit]ByVal[/FONT][/COLOR] sender [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Object[/FONT][/COLOR], [COLOR=blue][FONT=inherit]ByVal[/FONT][/COLOR] e [COLOR=blue][FONT=inherit]As[/FONT][/COLOR] System.EventArgs) [COLOR=blue][FONT=inherit]Handles[/FONT][/COLOR] lstEmployeeNames.SelectedIndexChanged Names = [COLOR=blue][FONT=inherit]CType[/FONT][/COLOR](lstEmployeeNames.SelectedItem, Employees).Names [COLOR=blue][FONT=inherit]Me[/FONT][/COLOR].Text = Names.ToString [COLOR=blue][FONT=inherit]End[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Sub[/FONT][/COLOR][COLOR=blue][FONT=inherit]End[/FONT][/COLOR] [COLOR=blue][FONT=inherit]Class[/FONT][/COLOR][COLOR=green][FONT=inherit]'Private Sub btnChooseName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChooseName.Click[/FONT][/COLOR][COLOR=green][FONT=inherit]'user chooses name to get their employee ID, Dept Name and Phone number[/FONT][/COLOR][COLOR=green][FONT=inherit]'End Sub[/FONT][/COLOR][COLOR=green][FONT=inherit]'End Class[/FONT][/COLOR][/FONT][/COLOR]
 
Last edited:
np, so following up with the code you already have, your listbox already contains Employee objects. So when the button is clicked get the SelectedItem and check to see if it is of type Employee, then convert it to an Employee type and you can either send that to your new form or you can just send the string from the Details method.

It's just like the lstEmployeeNames_SelectedIndexChanged method i posted in #23, do the same thing in a button click event. If you want you can create a property/variable on the second form that is of type Employee and just pass that to the second form instead of passing the string from the Details Method.

ok so your talking about the whole first example in number 23 and put it into my button call display info on the first form correct
 
sorry i meant the second one on that post. To avoid confusion, i mean do something like this

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Emp As Employee = CType(lstEmployeeNames.SelectedItem, Employee)
 
    Dim frm2 As New Form2
    frm2.Label1.Text = Emp.Details
    
    'or if you created a property/variable that is of type Employee in Form2
    'you can just pass that to the form and then in the form write some code to display the info properly
    'frm2.EmployeeInfo = Emp
 
    frm2.ShowDialog()
End Sub
 
VB.NET:
Private Sub btnDisplayInformation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayInformation.Click
        Dim showEmployeeInformation As New frmEmployeeInformation
        Dim Emp As Employee = CType(lstEmployeeNames.SelectedItem, Employee)


        frmEmployeeInformation.lblEmployeeData.Text = Emp.Details


        frmEmployeeInformation.ShowDialog()
    End Sub
End Class

how is this, flipped, just tested it out it worked to

im actually going to let my aunt see......thanks so much is there I a way I can add to your rep or something
 
Last edited:
i think it looks fine... typically i think its a good idea to check the type before converting or use a try catch block, but since your just doing exercises and you know exactly whats going to be in the listbox, and you know there will only be Employee type objects in there i think this is fine.
 
no problem. Glad to be of help. :)

There's a button on the bottom left of this post that looks like a black 6pt Star, on mouse over it says "Add to this user's reputation". Thanks
 
Last edited:
Back
Top