String Letter转换为0

时间:2015-03-15 00:54:48

标签: vb.net

我想制作一个程序(在VB上)从USB复制特定文件夹,但无论我使用什么(TextBox,ComboBox,ListBox),总是将DriveR Letter(C:for test)转换为0 ,所以te程序不起作用。如果我使用另一个Dim ...... As ..,就像Integer一样,我得到了" 一个未处理的类型' System.InvalidCastException'发生在Microsoft.VisualBasic.dll "错误

这是我的代码:

Private Sub RespJ_Click(sender As Object, e As EventArgs) Handles RespJ.Click
    Dim CarpetaI, CarpetaL, ID As String
    Dim Letra As Integer
    Letra = Val(combobox1.Text)
    ID = Val(IDTB.Text)
    CarpetaI = Letra + ":\WPSystem\AppData\" + ID
    CarpetaL = "C:\RespaldoWP\WPSystem\AppData\" + ID
    Label1.Text = CarpetaI
    'My.Computer.FileSystem.CreateDirectory(CarpetaL)
    'My.Computer.FileSystem.CopyDirectory(CarpetaI, CarpetaL, True)
End Sub

*最后2行被评论,因为我想测试代码(使用标签查看路径是否正确),然后才能在真实/测试文件上复制/过去

1 个答案:

答案 0 :(得分:1)

这里有两个问题:

您的变量应为String

Dim Letra As String

请勿使用Val function读取组合框中的驱动器号:

Letra = combobox1.Text