Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Curriculum is an .asmx file which has list of web service methods to return particular values, and this method GetMyEmployeeId is one such webmethod i will be calling from my webform, which returns an array containing current user (homepage) id

VB
Public Function GetMyEmployeeId() As Integer()
            Return New Integer() {Current.HomepageUserId}
End Function


I would like to call this webservice method in my webform and have to get the current employeeID, so that I can pass it to my different method which is DoSomething(here it takes the returned employeeID as parameter)

_curTree is the object of the curriculum class.
VB
Private Function GetEmployeeActual() As Items
  Dim item as Items
  Dim employeeID As Integer()
                  'I am guessing that, am declaring the employeeID wrong ( it should not be an integer datatype may be because the GetMyEmployeeID returns an array of current user ID's)
  employeeID = _curTree.GetMyEmployeeId()
  item = DoSomething(employeeID)
                  'I am getting the error here as"value of type integer cannot be converted to 1-dimensional array"
  Return item
  End Function


DoSomething() function

VB
Public Function DoSomething(ByVal EmployeeIds As Integer()) As Items
            Dim items As Items = New DashboardInfo(EmployeeIds).LevelList()
            items.Sort()
            Return items
        End Function

help me to proceed
Posted
Updated 9-Dec-14 8:50am
v2
Comments
Kornfeld Eliyahu Peter 9-Dec-14 12:47pm    
The problem in DoSomthing() - let see us that method...
BuBa1947 9-Dec-14 14:50pm    
pls see my improved question, have added the function
Robert Ellis 9-Dec-14 15:47pm    
Can you make sure that in your Visual Studio "Exceptions..." settings, all exceptions are being immediately thrown (i.e. make sure you do NOT have it set up to break only on Unhandled exceptions)

If you don't, make the changes, run the code again, and see if the exception is actually occurring somewhere else and bubbling up the stack.

If you had declared employeeID as an "incorrect" type in the way implied by your embedded remarks, I would have thought you would be seeing an exception at the line above (Line 4 rather than Line 5)

A C&P of the full exception might also help to diagnose.
BuBa1947 9-Dec-14 16:17pm    
The exception is because the web method GetMyEmployeeId() returns an array containing the user ID's but i am trying to return the method's array of user ID's as integer. Pls suggest instead of integer what should I declare the property employeeID?

It was hard to spot as it is very unusual...
You use Integer() everywhere instead Integer...
Integer() defines an array of integers - read here: http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx[^]
 
Share this answer
 
This means:
VB
'Function to return the array of integers
Public Function GetMyEmployeeId() As Integer()
            'seems, you're trying to return single value as an array
            Return New Integer() {Current.HomepageUserId}
End Function


To be honest, you need to get back to basics: Arrays in VB[^]

If you want to return single value, your function should looks like:
VB
Public Function GetMyEmployeeId() As Integer
            Return DashboardInfo(EmployeeIds).LevelList().Where(Function(x) x=Current.HomepageUserId).Select(Function(x) Convert.ToInteger(x.HomepageId))
End Function

where Where(Function(x) x.HomepageUserId=Current.HomepageUserId) is Linq function which searches the list of EmployeeIds to return HompageId

Note: i do not know your entity model, so you need to change it to your needs.

For further information, please see:
Convert.ToInt32 Method (String)[^]
Introduction to LINQ in Visual Basic[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900