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.

Recommended Answers

All 6 Replies

What are the errors?

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.

commented: Thanks +0

Could you show me an example?

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.

Example:

MyDirectory typed in will create these directories:
M
My
MYD
MYDi
...

commented: Thanks +0

Thanks. It works fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.