VBA代码:错误按钮复制表

时间:2018-05-03 09:13:07

标签: asp.net vb.net

我的老板让我在vb.net中编写一个小程序,所以我正在学习这种语言是如何工作的,但现在我不知道我的错误在哪里。 我的目标是:

  • 通过文本框中的文件夹链接(此步骤正常)
  • 创建一个按钮来阅读此链接并选择所选文件夹中的所有文件并将文件放在可见表中(此步骤也可以)
  • 创建第二个按钮,将每个文件复制/过去到新文件夹(我在这里)

    我的问题是当我把msgBox放在这个按钮里看我的内容时我什么也没有。此外,当我这样做时,我的桌子消失了。 你能看出我的问题是什么吗?我相信这是愚蠢的事情,或者我不会理解某些事情。 非常感谢您的帮助

  

这是我的代码

Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim Link As String = Me.TextBox1.Text
End Sub

Protected Sub ButtonImport_Click(sender As Object, e As EventArgs) Handles ButtonImport.Click
Try
        path = TextBox1.Text
        Dim FileSystem = Server.CreateObject("Scripting.FileSystemObject")
        CreateTable(FileSystem.GetFolder(path))

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Protected Sub ButtonShipment_Click(sender As Object, e As EventArgs) Handles ButtonShipment.Click
    CopyFile()
End Sub

Sub CreateTable(ByRef Folder As Object)

    Dim File As Object
    Dim RepLivraison As String = Folder.Path
    Dim SubFolder As Object

    For Each SubFolder In Folder.SubFolders
        CreateTable(SubFolder)
    Next

    For Each File In Folder.Files

        Dim tRow As New TableRow()
        table1.Rows.Add(tRow)

        'Création d'une colonne avec le nom du fichier
        Dim tCell As New TableCell()
        tRow.Cells.Add(tCell)
        tCell.Text = File.Name

        'Colonne de la zone de texte pour la destination du fichier
        Dim tCell2 As New TableCell()
        tRow.Cells.Add(tCell2)

        'Mettre l'ID de la textbox ici pour chaque textbox !
        Dim txtbox As New TextBox
        tCell2.Controls.Add(txtbox)
        Dim FilePath As String = Replace(File.Path, path, "")
        txtbox.Text = Replace(FilePath, File.Name, "")

        'Colonne de la zone de texte pour la destination du fichier
        Dim tCell3 As New TableCell()
        tRow.Cells.Add(tCell3)

        Dim ListAddRemove As New ListBox
        ListAddRemove.Items.Add("Ajouter")
        ListAddRemove.Items.Add("Supprimer")
        ListAddRemove.Items.Add("N/A")
        ListAddRemove.SelectedIndex = 0
        tCell3.Controls.Add(ListAddRemove)
    Next

End Sub



Public Sub CopyFile()
    MsgBox(Table1.Rows.Count)

    Dim targetPath As String
    'If CheckBox1.Checked Then
    'targetPath = "\\" & CheckBox1.Text & "\Wellview-10.1\Appli"
    'End If
    'Dim sourcePath As String = path
    If CheckBox1.Checked Then
        targetPath = "C:\Local\test\" & CheckBox1.Text
    End If

    ' Use Path class to manipulate file And directory paths.
    ' Dim sourceFile As String = System.IO.Path.Combine(sourcePath, fileName)

    'Dim destFile As String = System.IO.Path.Combine(targetPath, fileName)

    ' To copy a folder's contents to a new location:
    ' Create a New target folder, if necessary.
    ' If (System.IO.Directory.Exists(targetPath)) Then

    'System.IO.Directory.CreateDirectory(targetPath)
    'End If


    ' To copy a file to another location And 
    ' overwrite the destination file if it already exists.
    'System.IO.File.Copy(sourceFile, destFile, True)


    For Each row As TableRow In table1.Rows
        Dim PathTarget As String = targetPath & table1.Rows.Item(2).ToString
    Next


End Sub

0 个答案:

没有答案