gpt4 book ai didi

vb6 - 如何从函数返回值

转载 作者:行者123 更新时间:2023-12-01 18:03:12 25 4
gpt4 key购买 nike

如何从函数返回值

代码

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com