0

我试图在按下按钮时创建和命名文件。但我需要文件名包含文本框中的文本。

代码:

My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text + ".txt", "[" + TimeOfDay + "]" + "Email: " + txtEmail.Text + vbNewLine + "Username: " + txtUser.Text + vbNewLine + "Password: " + txtPass.Text + vbNewLine + "Secuirty: " + txtSecuirty.Text + vbNewLine + vbNewLine, True)

简单代码:

My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text + ".txt", {loads of stuff}, True)

我有很多 if 函数来停止不允许的字符。

我得到的错误是:

Expression does not produce a value
4

1 回答 1

1

试着看看这是否适合你。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text.ToString() + ".txt", "test message", True)
End Sub

或者您可以将代码更改为

Dim strFileText As String = ""
    strFileText =
        "[" & TimeOfDay.ToString() & "] " & vbCrLf &
        "Email: " & txtEmail.Text.ToString() & vbCrLf &
        "Username: " & txtUser.Text.ToString() & vbCrLf &
        "Password: " & txtPass.Text.ToString() & vbCrLf &
        "Security: " & txtSecurity.Text.ToString() & vbCrLf & vbCrLf

    My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text.ToString() + ".txt", strFileText, True)
于 2013-08-31T03:32:06.303 回答