返回值时的功能问题

时间:2016-06-22 15:34:05

标签: vb.net function

所以,我试图使一个Function方法工作,但是出现了一些问题,我无法解决它们。我使用断点,我发现这是一个循环,并且没有调用其中一个代码行。这是方法:

Private Function SendToRecycle(filename As String) As Boolean
    If MsgBox("Are you sure you want to sent it to recycle bin?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        Return "True"
        My.Computer.FileSystem.DeleteFile(filename, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
    ElseIf MsgBox("Are you sure you want to sent it to recycle bin?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
        Return "False"
    End If
    Return SendToRecycle
End Function

它的作用很简单,如果用户选择选项是,它应该返回true并将该文件发送到回收站并写入我的数据库,否则它将返回true并写入我的数据库而不删除添加的文件。 但是发生了什么,如果我单击是,它将返回True但不调用删除文件的操作...

你有什么想法我怎样才能解决我的问题?

1 个答案:

答案 0 :(得分:0)

尝试:

Private Function SendToRecycle(filename As String) As Boolean
    If MsgBox("Are you sure you want to sent it to recycle bin?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        My.Computer.FileSystem.DeleteFile(filename,FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
        Return True
    ElseIf MsgBox("Are you sure you want to sent it to recycle bin?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
        Return False
    End If
End Function