Hello there!

This forums has helped me a lot to learn programming now I need your help again. I'm try to figure out a way to create a folder based on users input in Textbox on desktop.

Public Class Form1

    Dim username As TextBox

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim USERPROFILE As String
        USERPROFILE = Environ("HOMEPATH")
        Dim oShell : oShell = CreateObject("WScript.shell")
        IO.Directory.CreateDirectory(USERPROFILE & "\Desktop\"username)
    End Sub
End Class

It giving me errors. Can someone correct me and give a sample code for this?

Any help in appreciated.

Nothing actually. It's not even compiling. Error at this line IO.Directory.CreateDirectory(USERPROFILE & "\Desktop\"username)

You need a symbol to concatenate the "\Desktop\" and username. Also, you should be referencing the Text property of the TextBox username, not the TextBox itself.

IO.Directory.CreateDirectory(USERPROFILE & "\Desktop\"username) 

I see an error. There is no & between "\Desktop\" and username

IO.Directory.CreateDirectory(USERPROFILE & "\Desktop\" & username)

You should also place all the calls outsite that event handler. You will be taking a memory hit. The event will fire everytime the text changes. So, as you type a directory, it will be creating a directory for every typed character.


MyDirectory typed in will create these directories:

Edited 4 Years Ago by Maligui

This article has been dead for over six months. Start a new discussion instead.