vb6 - 如何从函数返回值

标签 vb6 return-value

如何从函数返回值

代码

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

如何从上述代码中返回值。

需要 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

这是一个link对于理解 VB6 中的函数,这是一本很好的读物

编辑

阅读您的评论后,我将创建一个类来存储您的值。

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

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

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

关于vb6 - 如何从函数返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8710623/

相关文章:

C++ - 何时为使用但未分配的对象调用析构函数?

.net - VB6 在 .NET WinForm 上编写了 ocx?

vb6 - 如何立即退出程序?

multithreading - 预定任务-VB6和线程

c++ - 在 C 和 C++ 中 main() 应该返回什么?

c - 多次调用 char[] 立即返回函数 fprint

bash - 如何在有条件的情况下使用 bash 返回码?

python - 不推荐 python 中的 `return None`。如何绕过?

vb6 - 运行时错误 '70' VB6 中的权限被拒绝

vb6 - 添加 Microsoft Rich Textbox Control 6.0 (SP6) 时出现 "Object library not registered"