函数'fnc'不返回值 [英] Function 'fnc' doesn't return a value

查看:161
本文介绍了函数'fnc'不返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有人能告诉我为什么我会收到此警告以及如何解决此问题。

代码工作正常但我想知道如何以后要避免这样的警告。



Hello to all,
Could someone tell me why I am getting this warning and how to solve it.
Code works fine but I would like to know how to avoid warnings like this in the future.

Public Function GetPropertyValue(objBlockRef As AcadBlockReference, propName As String) As Object
        Dim iProp As Long
        Dim dybprop As Object

        If objBlockRef.IsDynamicBlock Then '<--| if the passed block reference is a dynamic block one
            dybprop = objBlockRef.GetDynamicBlockProperties '<--| get its dynamic properties
            For iProp = LBound(dybprop) To UBound(dybprop) '<--| iterate through them properties
                With dybprop(iProp)
                    If .PropertyName = propName Then '<--| if the current property matches the passed name
                        GetPropertyValue = .Value '<--| return its value
                        Exit Function
                    End If
                End With
            Next
        End If

    End Function





我的尝试:



我什么都不知道。我试图在函数名称上使用return。



What I have tried:

I don't have any idea. I have tried to use "return" on the name of the function.

推荐答案

你没有一个返回任何地方的声明。这不是VB6或VBScript。



实际的Return语句必须在那里,并在适当的地方。如果使用Return语句替换 GetPropertyValue = .Value ,则会出现另一个错误,并非所有代码路径都返回值。



所以,重写函数

You don't have a single Return statement anywhere. This isn't VB6 or VBScript.

An actual Return statement has to be in there, and in an appropriate place. If you replace the GetPropertyValue = .Value with the Return statement, you'll get another error, "Not all code paths return a value."

So, rewrite the function
Public Function GetPropertyValue(objBlockRef As AcadBlockReference, propName As String) As Object
    Dim iProp As Long
    Dim dybprop As Object
    Dim returnValue As Object = Nothing

    If objBlockRef.IsDynamicBlock Then '<--| if the passed block reference is a dynamic block one
        dybprop = objBlockRef.GetDynamicBlockProperties '<--| get its dynamic properties
        For iProp = LBound(dybprop) To UBound(dybprop) '<--| iterate through them 
properties
            ' The With was completely unnecessary.
            If dybprop(iProp).PropertyName = propName Then '<--| if the current property matches the passed name
                returnValue = dybprop(iProp).Value '<--| return its value
                Exit For
            End If
        Next
    End If

    Return returnValue
End Function

这篇关于函数'fnc'不返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆