如何解决代码转换问题?

时间:2015-05-12 11:23:05

标签: vb.net vb6

Public Function SaveCommentsTreeComments(ByRef f As System.Windows.Forms.Form) As Integer
    Dim IsNewSubComment As Boolean
    Dim IsNewCommentWithSub As Boolean
    Dim sql As String
    Dim rs As New ADODB.Recordset
    Dim CommentID As Short
    Dim SubCommentID As Short
    Dim Index As Short
    'WMB 1/28/2004 nextval
    Dim cSql As String
    Dim cRs As New ADODB.Recordset
    Dim cSeq As Double

    On Error GoTo SaveCommentsTreeCommentsError

    SaveCommentsTreeComments = -1

    If Not ValidateCommentsTreeComments(f) Then
        SaveCommentsTreeComments = -2
        Exit Function
    End If


    If f.CommentsText(CommentsTextAbbreviation).Enabled And f.CommentsText(SubCommentsTextDescription).Enabled Then
        IsNewCommentWithSub = False

从vb6升级到vb.net时,我从上面的代码中得到以下错误。我不知道缺少哪个课程。

  

' CommentsText'不是System.Windows.Forms.Form'

的成员

1 个答案:

答案 0 :(得分:0)

你应该改变:

Public Function SaveCommentsTreeComments(ByRef f As System.Windows.Forms.Form) As Integer

要:

Public Function SaveCommentsTreeComments(f As YourFormClassName) As Integer

这改变了两件事,首先f现在是正确的类型,并且具有CommentsText属性,字段或函数。其次,当传递参数时,VB6的默认值是ByRef,当VB.NET开发时,他们意识到这是一个错误并纠正它,但是转换不进行必要的分析来确定是否需要ByRef。由于在这种情况下不需要,因此应将其删除或更改为ByVal。