none
Returning a single value using Linq is fine but need help in enabling it to be parameter driven RRS feed

  • Question

  • 	Private Function getPhoneExtentionFromCboGridStaffNameEditValue() As String
    
    		' take the edit (numeric) value in the Internal Staff cbo and return 
    		' string of Staff phone nr
    		Dim xtNumber = From staff In staffList.STAFFs _
    		 Where staff.Number = CInt(Val(cboGridStaffName.EditValue)) _
    		 Select Strings(Trim(staff.Phone))
    
    		Return xtNumber.Single.ToString()
    	End Function
    I am using the above code to extract and return a phone number from my STAFF Table

    Next is to extract and return their email and then after that their address and then etc etc...

    I don't want to have to write a function for each but do not have the knowledge of VB.NET and Linq to figure it out for myself

    I expect I should be able to pass a parameter into the function which tells the code which field I am wanting back something like...

    MsgBox("Staff phone is: " & getStaffInfoFromCboGridStaffNameEditValue(staff.phone) )

    and for emails...

    MsgBox("Staff phone is: " & getStaffInfoFromCboGridStaffNameEditValue(staff.email) )

    etc.

    I'd be grateful for some pointers, better a still a few lines of code?

    Thanks

    Sunday, June 7, 2009 6:00 PM

Answers

  • Hi,

    If would be easier if you return your Staff object from the function like this:
    Private Function getStaffInfoCboGridStaffNameEditValue() As Staff
    
    	' take the edit (numeric) value in the Internal Staff cbo and return 
    	' a Staff object
    	Dim xtNumber = From staff In staffList.STAFFs _
    	 Where staff.Number = CInt(Val(cboGridStaffName.EditValue)) _
    	 Select staff
    
    	Return staff.Single()
    End Function
    
    
    Then you could refer to the individual properties of the data-object like this:
    MsgBox("Staff phone is: " & getStaffInfoFromCboGridStaffNameEditValue().Phone) )
    
    MsgBox("Staff email is: " & getStaffInfoFromCboGridStaffNameEditValue().Email) )
    

    Hope that helps.

    Regards,

    Syed Mehroz Alam
    My Blog | My Articles
    • Marked as answer by Laughing Sam Tuesday, June 9, 2009 8:23 AM
    Monday, June 8, 2009 5:27 AM

All replies

  • Hi,

    If would be easier if you return your Staff object from the function like this:
    Private Function getStaffInfoCboGridStaffNameEditValue() As Staff
    
    	' take the edit (numeric) value in the Internal Staff cbo and return 
    	' a Staff object
    	Dim xtNumber = From staff In staffList.STAFFs _
    	 Where staff.Number = CInt(Val(cboGridStaffName.EditValue)) _
    	 Select staff
    
    	Return staff.Single()
    End Function
    
    
    Then you could refer to the individual properties of the data-object like this:
    MsgBox("Staff phone is: " & getStaffInfoFromCboGridStaffNameEditValue().Phone) )
    
    MsgBox("Staff email is: " & getStaffInfoFromCboGridStaffNameEditValue().Email) )
    

    Hope that helps.

    Regards,

    Syed Mehroz Alam
    My Blog | My Articles
    • Marked as answer by Laughing Sam Tuesday, June 9, 2009 8:23 AM
    Monday, June 8, 2009 5:27 AM
  • Hi Syed,

    Your reply and contents were spot on!

    Many thanks for your help on this, it's given me a big step further down the road of understanding
    Tuesday, June 9, 2009 8:25 AM