【问题标题】:Compile error byref argument type mismatch编译错误 byref 参数类型不匹配
【发布时间】:2017-06-26 18:00:05
【问题描述】:

我在传递ByRef 变量方面已经有经验了。我知道我必须在调用过程和被调用过程中声明它们(当然是同一类型)。我这样做了,但仍然出现编译错误。

这是失败的调用:

transition = reply_manager(CommentfirstJSON, a_b_c_d) 

标记了变量a_b_c_d。它是一个字符串,被调用的函数需要一个字符串。那我做错了什么?

Function comment_manager(ByVal CommentJSON As Object, ByRef defects_of_cat As Dictionary)
    Dim CommentobjJSON As Object
    Dim comment_date As Date
    Dim comment_statusJSON As Object
    Dim comment_Closed As Boolean
    Dim comment_author, comment_author_displayname As String
    Dim comment_severity As String
    Dim comment_status_ask_answer_fix_reject As String
    Dim comment_resolvedFriendlyDate As Date
    Dim comment_resolvedUser As String
    Dim a_b_c_d, abcd As String
    Dim red_blue_amber_green As String
    Dim comment_avatarURL As String
    Dim comment_resolved_by_dangling As Boolean
    Dim comment_resolved_user As String
    Dim resolved_type As String
    Dim writen_lines_this_comment As Integer

    writen_lines_this_comment = 0

    comment_author = CommentJSON.authorUserName
    comment_author_displayname = CommentJSON.authorDisplayName

    comment_avatarURL = CommentJSON.authorAvatarUrl
    Call register_avatar(comment_author, site_URL & comment_avatarURL)
    Call register_avatar(comment_author_displayname, site_URL & comment_avatarURL)

    comment_original = CommentJSON.body

    comment_original = Replace(comment_original, "<p>", "")

    a_b_c_d = "D" ' default if author cannot be bothered to classify then its probably not important

        If InStr(Left(comment_original, 1), "A") > 0 Then a_b_c_d = "A"
        If InStr(Left(comment_original, 1), "B") > 0 Then a_b_c_d = "B"
        If InStr(Left(comment_original, 1), "C") > 0 Then a_b_c_d = "C"

        'If InStr(Left(comment_original, 1), "D") > 0 Then a_b_c_d = "D"

        comment_target = CommentJSON.originalSelection
        comment_id = CommentJSON.id
        comment_date = date_convert_to_date(CommentJSON.lastModificationDate)

        comment_URL = base_URL & CommentJSON.commentDateUrl

        Set comment_statusJSON = GetObjectProperty(CommentJSON, "resolveProperties")

        'comment_avatarURL = CommentJSON.authorAvatarUrl

        comment_Closed = comment_statusJSON.resolved

        If comment_Closed Then

            comment_resolvedFriendlyDate = date_convert_to_date(comment_statusJSON.resolvedFriendlyDate)

            comment_resolvedUser = comment_statusJSON.resolvedUser

            'comment_avatarURL = comment_resolvedUser

            comment_resolved_by_dangling = comment_statusJSON.resolvedByDangling

            red_blue_amber_green = "Green"

            If comment_resolved_by_dangling Then red_blue_amber_green = "Pink"

        Else

            red_blue_amber_green = "Red"

        End If

        If red_blue_amber_green = "Pink" Then

            Call writeline("", 0, 0, CDate("01-01-2066"), CDate("01-01-2066"), "", "", comment_date, "Green", "", a_b_c_d, comment_original, comment_target, comment_URL, site_URL & comment_avatarURL)  'The comment birth
            writen_lines_this_comment = writen_lines_this_comment + 1
        Else

            Call writeline("", 0, 0, CDate("01-01-2066"), CDate("01-01-2066"), "", "", comment_date, red_blue_amber_green, "", a_b_c_d, comment_original, comment_target, comment_URL, site_URL & comment_avatarURL)  'The comment birth
            writen_lines_this_comment = writen_lines_this_comment + 1
        End If

    httprequest = "https://csc-ejendom.atlassian.net/wiki/rest/inlinecomments/1.0/comments/" & comment_id & "/replies"

    ask_confluence

    Set CommentobjJSON = TestJSONParsingWithVBACallByName()

    Dim length As Integer
    length = GetProperty(CommentobjJSON, "length")

    For reply_no = 1 To length

        'Dim firstJSON As Object
        Set CommentfirstJSON = GetAtIndex(CommentobjJSON, reply_no - 1)

    '  Dim keys() As String
    '  keys = GetKeys(firstJSON)

        transition = reply_manager(CommentfirstJSON, a_b_c_d)

        writen_lines_this_comment = writen_lines_this_comment + 1

            If transition <> "NO_TRANSITION" Then comment_status_ask_answer_fix_reject = transition

            If red_blue_amber_green <> "Green" Then

                If comment_status_ask_answer_fix_reject = "FIX" Then red_blue_amber_green = "Amber"

                If comment_status_ask_answer_fix_reject = "REJECT" Or comment_status_ask_answer_fix_reject = "ANSWER" Then red_blue_amber_green = "Red"

                If comment_status_ask_answer_fix_reject = "ASK" Then red_blue_amber_green = "Blue"

            End If

    Next reply_no

    If a_b_c_d <> "X" Then

        If comment_Closed Then

            resolved_type = "Resolved"

            If comment_resolved_by_dangling Then resolved_type = "Resolved by dangling"

            Call writeline("", 0, 0, CDate("01-01-2066"), CDate("01-01-2066"), "", "", comment_resolvedFriendlyDate, resolved_type, "", "", "", "", "", comment_resolvedUser) 'gigi

            writen_lines_this_comment = writen_lines_this_comment + 1

            defects_of_cat(a_b_c_d & red_blue_amber_green) = defects_of_cat(a_b_c_d & red_blue_amber_green) + 1

        End If

        Call writeline("", 0, 0, CDate("01-01-2066"), CDate("01-01-2066"), "endofreplies", "", CDate("01-01-2066"), "", "", "", "", "", "", "") 'gigi

    Else

        rollback (writen_lines_this_comment)

    End If

End Function

Function reply_manager(ByVal ReplyJSON As Object, ByRef ab_cd As String) As String
    Dim reply_date As Date
    Dim reply_author_display_name, reply_author_user_name, reply_author_avatar_url, reply_author, reply_text, passed_abcd  As String

    reply_author_display_name = ReplyJSON.authorDisplayName
    reply_author_user_name = ReplyJSON.authorUserName
    reply_author_avatar_url = ReplyJSON.authorAvatarUrl

    Call register_avatar(reply_author_display_name, site_URL & reply_author_avatar_url)
    Call register_avatar(reply_author_user_name, site_URL & reply_author_avatar_url)

    reply_text = ReplyJSON.body
    reply_text = Replace(reply_text, "<p>", "")

    reply_date = date_convert_to_date(ReplyJSON.lastModificationDate)

    reply_manager = "NO_TRANSITION"

    If InStr(Left(reply_text, 3), "FIX") > 0 Then reply_manager = "FIX"
    If InStr(Left(reply_text, 3), "ASK") > 0 Then

    reply_manager = "ASK"

    End If
    If InStr(Left(reply_text, 6), "REJECT") > 0 Then reply_manager = "REJECT"
    If InStr(Left(reply_text, 6), "ANSWER") > 0 Then reply_manager = "ANSWER"

    passed_abcd = ab_cd

    If InStr(Left(reply_text, 2), "A ") > 0 And InStr(Left(reply_text, 2), "AN") = 0 And InStr(Left(reply_text, 2), "AS") = 0 Then ab_cd = "A"
    If InStr(Left(reply_text, 2), "B ") > 0 Or InStr(Left(reply_text, 2), "B:") > 0 Then ab_cd = "B"
    If InStr(Left(reply_text, 2), "C ") > 0 Or InStr(Left(reply_text, 2), "C:") > 0 Then ab_cd = "C"
    If InStr(Left(reply_text, 2), "D ") > 0 Or InStr(Left(reply_text, 2), "D:") > 0 Then ab_cd = "D"
    If InStr(Left(comment_original, 1), "X") > 0 Then a_b_c_d = "X"

    If passed_abcd <> ab_cd Then

        passed_abcd = ab_cd

    Else

        passed_abcd = ""

    End If

    reply_text = "9  " & reply_text

    Call writeline("", 0, 0, CDate("01-05-2066"), CDate("01-05-2066"), "", "", reply_date, reply_manager, "", passed_abcd, reply_text, "", "", site_URL & reply_author_avatar_url) 'gigi

End Function

【问题讨论】:

  • 您需要将相关代码添加到问题中,而不是要求人们下载包含文件的随机脚本。

标签: vba excel compilation pass-by-reference


【解决方案1】:

问题是你认为你已经将它声明为String

Dim a_b_c_d, abcd As String

与 VB.Net 不同,它们都将被声明为 String,在 VBA 中只有第二个,即 abcd 将被声明为 String。第一个,即a_b_c_d 将被声明为Variant

你必须明确声明两者。

Dim a_b_c_d As String, abcd As String

【讨论】:

  • 很棒,也很喜欢@AlexK。提到,将相关代码添加到问题中,而不仅仅是放置链接或图像:) 由于您是新来的,所以我为您做了,但下次您将不得不自己做出努力
猜你喜欢
  • 2017-10-17
  • 2016-03-03
  • 1970-01-01
  • 2021-11-24
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多