vb6 – 如何从函数返回值

前端之家收集整理的这篇文章主要介绍了vb6 – 如何从函数返回值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何从函数返回值

Private Function LeaveCheck(empid As String)
    Dim rdoRs1 As rdoResultset
    Dim desc As String
    Dim ssql As String
    ssql = "Select name from table1 wher empcode = '" & empid & "'"
    Set rdoRs1 = Rdoconn.OpenResultset(ssql,rdOpenStatic)
    If rdoRs1.RowCount > 0 Then
    desc = rdors1!name        
    return desc 'Showing error in this line    
    End If
    rdoRs1.Close
End Function@H_404_4@ 
 

如何从上面的代码返回值.

需要Vb6代码帮助

您需要指定返回类型.
Private Function LeaveCheck(empid As String) As String ' Notice the As String
    Dim rdoRs1 As rdoResultset  
    Dim desc As String  
    Dim ssql As String  
    ssql = "Select name from table1 wher empcode = '" & empid & "'"  
    Set rdoRs1 = Rdoconn.OpenResultset(ssql,rdOpenStatic)  
    If rdoRs1.RowCount > 0 Then  
        desc = rdors1!name          
    End If  
    rdoRs1.Close  

    LeaveCheck = desc ' This will be blank or populated
End Function@H_404_4@ 
 

这是一个很好的阅读,用于理解VB6中的函数

编辑

阅读完评论后,我会创建一个类来存储您的值.

Public Class MyClass
    Dim name As String
    Dim dept As String
    Dim country As String
End Class@H_404_4@ 
 

然后,您可以在代码中实例化此类的新实例:

Private Function LeaveCheck(empid As String) As MyClass
    Dim myClass As New MyClass
    Dim rdoRs1 As rdoResultset
    Dim ssql As String   
    ssql = "Select name,dept,country from table1 wher empcode = '" & empid & "'"   
    Set rdoRs1 = Rdoconn.OpenResultset(ssql,rdOpenStatic)   
    If rdoRs1.RowCount > 0 Then   
        myClass.name = rdors1!name           
        myClass.dept = rdors1!dept
        myClass.country = rdors1!country
    End If   
    rdoRs1.Close   

    LeaveCheck = myClass
End Function@H_404_4@
原文链接:https://www.f2er.com/vb/255057.html

猜你在找的VB相关文章