首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请问一个函数返回值的有关问题

2012-04-15 
请教一个函数返回值的问题代码如下,传入一个System.Object的参数,返回System.Object,请问这个函数的返回值

请教一个函数返回值的问题
代码如下,传入一个System.Object的参数,返回System.Object,请问这个函数的返回值是?
SocketSendRecv = Nothing 这个是什么意思,类里面没声明这个变量。

VB.NET code
 Public Function SocketSendRecv(ByRef requestObj As System.Object, Optional ByRef lblText As Label = Nothing) As System.Object        '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [Start]        checkCmd()        '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [End]        If UI_ROOT_FORM IsNot Nothing Then            UI_ROOT_FORM.Cursor = Cursors.WaitCursor        End If        SocketSendRecv = Nothing        Try            Dim strLogId As String = getId()            Dim strTrxName As String = CType(requestObj, MsgBaseIn).trx_name            CType(requestObj, MsgBaseIn).user_id = USER_INFOR.EmployeeNo            CType(requestObj, MsgBaseIn).log_id = strLogId            '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [Start]            'To define variables to store these parameters such as IP and SessionId that generated dynamically is FASTER than generating them each time.            'However, it is more reliable because users' SessionId could change without closing OPI.            CType(requestObj, MsgBaseIn).ip_address = strLocalIP            CType(requestObj, MsgBaseIn).opi_version = Application.ProductVersion            CType(requestObj, MsgBaseIn).session_type = getSessionType(PROCESS_INFOR.SessionId)            CType(requestObj, MsgBaseIn).reply_queue = _qMailboxQueueName            '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [End]            'Send xml and get return message            Dim rtnMsgXml As String = SocketSendRecv(strTrxName, PackMsg(requestObj), strLogId)            If String.IsNullOrEmpty(rtnMsgXml) Then                Return Nothing            End If            'Xfer return message to OutMsg Object            Dim rtnMsgObjName As String = requestObj.GetType.ToString            rtnMsgObjName = rtnMsgObjName.Substring(0, rtnMsgObjName.Length - 1) & "O"            Dim rtnMsgObjType As Type = mdlTools._asm.GetType(rtnMsgObjName)            SocketSendRecv = ParseMsg(rtnMsgObjType, rtnMsgXml)            If SocketSendRecv IsNot Nothing Then                Dim objMsgBaseOut As MsgBaseOut = CType(SocketSendRecv, MsgBaseOut)                If checkReturnCode(objMsgBaseOut.rtn_code, objMsgBaseOut.rtn_msg, strTrxName, lblText) Then                Else                    SocketSendRecv = Nothing                End If            End If            '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [Start]        Catch aex As AppException            showMsgBox(aex.MsgCode, aex.Message, aex.FieldString, lblText)        Catch ex As Exception            'showMsgBox("9999999", "Unknown Error", ex.Message, lblText)            showMsgBox("MSG1200215", "Error occurred in communicating with MCMQ.", ex.Message)            '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [End]        End Try        If UI_ROOT_FORM IsNot Nothing Then            UI_ROOT_FORM.Cursor = Cursors.Default        End If        '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [Start]        checkCmd()        '#MES v1.7.1 [UR01885.13]: Establish connection to MCMQ directly. [End]    End Function

SocketSendRecv = Nothing

[解决办法]
http://dev.21tx.com/2005/05/05/11476.html
[解决办法]
SocketSendRecv是函数名,在vb里,给函数名赋值就相当于返回值

SocketSendRecv=nothing
相当于下面的写法
object ret=nothing
...

return ret

vb.net里建议不要用上面的形式,用return比较规范些

热点排行