By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,780 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,780 IT Pros & Developers. It's quick & easy.

Create a folder using input from a text box

P: 1
I am trying to create a folder based on inputed text from a text box. I can create the folder without a problem, it is when I add the text box in the mix I am having issues. Can someone please help?
Nov 3 '06 #1
Share this Question
Share on Google+
16 Replies


Expert 5K+
P: 8,434
I am trying to create a folder based on inputed text from a text box. I can create the folder without a problem, it is when I add the text box in the mix I am having issues. Can someone please help?
I just created a new project, threw a textbox and a command button on a form, and inserted this code. It worked.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.   MkDir Text1.Text
  3. End Sub
  4.  
Nov 3 '06 #2

P: 6
Private Sub Command1_Click()
MkDir Text1.Text
End Sub

Hi,
Using the above code, I could be able to create a directory, I need to give path also in the above syntax. can you please help in this regard.

Regards,
P.P.Kumar
Jun 27 '07 #3

Expert 5K+
P: 8,434
...I need to give path also in the above syntax. can you please help in this regard.
Just concatenate the strings together. For example, to create folders under C:\Temp, you'd do something like this...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.   MkDir "C:\Temp\" & Text1.Text
  3. End Sub
Jun 28 '07 #4

P: 6
With the above syntax, it not creating folder in the said path "c:\Temp\"
Instead, it is creating folder with name "Text1.Text" on the current drive.
Jun 28 '07 #5

Expert 5K+
P: 8,434
With the above syntax, it not creating folder in the said path "c:\Temp\"
Instead, it is creating folder with name "Text1.Text" on the current drive.
Nonsense !

For that to happen you'd have to have quotes in the wrong place. Unless, of course, the textbox called Text1 actually has the value "Text1.Text" in it. Um... no, not even then.
Jun 28 '07 #6

P: 6
Hi,

Please chack the below syntax again. It is not working for me.

Private Sub Command1_Click()
MkDir "C:\Temp\" & Text1.Text
End Sub

I have placed quotes in correct place, and there is no value as such "Text1.Text"
but with the above syntax it is creating folder "Text1.Text" in the current directory. Please check above syntax in your system.

Regards,
Pramod
Jun 28 '07 #7

Expert 5K+
P: 8,434
Ok...

I created a new project, with one form. Placed a textbox (Text1) and command button (Command1) on the form. Copied/pasted in the code from your message. Ran. Entered "gkjghsklhg" in the text box, clicked the button. It created folder "C:\Temp\gkjghsklhg".

Perhaps the folder is just left over from before? Or perhaps you have some old code that you haven't removed from your program, which is doing this. But the code as shown here will not create it.
Jun 28 '07 #8

P: 6
Hi Killer42,

Please give me a solution in 'visual basic 2005' for which, I need to move 3 files "a, b, c" from different locations to a folder P. The folder P which is to be created using input from text box. Does concatenation of strings work with move command?

Thanks & Regards,
Pramod
Jul 2 '07 #9

Expert 5K+
P: 8,434
Please give me a solution in 'visual basic 2005' for which, I need to move 3 files "a, b, c" from different locations to a folder P. The folder P which is to be created using input from text box.
I can't provide VB 2005 code, as I only work with Vb6. I plan to start learning the later version soon, but that's no help to you.

Hopefully someone else here can do so, but I believe you should spend some time reading the doco, as creating a folder is a pretty basic (no pun intended) operation. One thing which might be a good idea is to use the FileSystemObject object. This provides lots of great functionality for working with drives, folders and files. Just note that to use it, you have to add a reference to "Microsoft Scripting Runtime" to your project.

Does concatenation of strings work with move command?
That's a much easier question. It doesn't matter what command or statement you're dealing with. When you deal with a "string" in VB, generally this can be absolutely any expression which resolves to a string. It doesn't matter whether this means concatenating strings, invoking functions, or whatever. The string "ABC" is functionally no different from the string Chr(65) & Chr(Asc("B")) & "C".
Jul 2 '07 #10

P: 6
Hi Killer,
In the below VB code I want to input "password" in encripted format using InputBox, please help me in this regard

Expand|Select|Wrap|Line Numbers
  1. Dim Pwd As String = String.Empty
  2. Dim Obj As Object
  3. Pwd = InputBox("Enter the password", "Security")
  4. If Pwd = "Password" Then
  5.     Dim oSettings As New Settings
  6.     oSettings.ShowDialog()
  7.     LoadXml()
  8. ElseIf Pwd = "" Then
  9. Else
  10.     MessageCall("Inavalid password", MessageBoxButtons.OK)
  11. End If
Aug 3 '07 #11

hariharanmca
100+
P: 1,977
Hi Killer,
In the below VB code I want to input "password" in encripted format using InputBox, please help me in this regard


Code: ( vb )
Dim Pwd As String = String.Empty
Dim Obj As Object
Pwd = InputBox("Enter the password", "Security")
If Pwd = "Password" Then
Dim oSettings As New Settings
oSettings.ShowDialog()
LoadXml()
ElseIf Pwd = "" Then
Else
MessageCall("Inavalid password", MessageBoxButtons.OK)
End If
why don't you use a different forum for that?
it will make your UI good.
With the above syntax, it not creating folder in the said path "c:\Temp\"
Instead, it is creating folder with name "Text1.Text" on the current drive.
(LOL........before posting you have to post your Req. Versions.)
Aug 3 '07 #12

Expert 5K+
P: 8,434
why don't you use a different forum for that?
it will make your UI good.
A different forum? This is VB-related, so what's the problem?
Aug 4 '07 #13

Expert 5K+
P: 8,434
(LOL........before posting you have to post your Req. Versions.)
The OP said (or at least implied) in post #9 that they use VB 2005.
Aug 4 '07 #14

Expert 5K+
P: 8,434
... In the below VB code I want to input "password" in encripted format using InputBox ...
Keep in mind that I'm only familiar with VB6, which is much older than your version. But as far as I'm aware, the InputBox function doesn't provide any way to "encrypt" input. I'm assuming that what you actually want is to mask the password on-screen, so others can't look over your shoulder and see what you've typed.

InputBox is really just a "quick and dirty" way to grab some text. I would only recommend using it during development as a shortcut. In a finished application you should develop your own user interface. The simplest way to do so in this case would be to stick a textbox and a couple of buttons on a form, put a bit of logic in there to handle the buttons, then show that modally (in VB 2005 I think that's done by ShowDialog).

Because it's "modal", control doesn't return to the calling code until the form is hidden or unloaded. So you can call it here in place of your InputBox and still use the same logic.
Aug 4 '07 #15

P: 2
I don't know if I am missing something as well but I too am not having any luck creating a new folder. Keep getting the following runtime error

"You can't reference a property or method for a control unless the control has the focus"

Any help.......
Aug 6 '07 #16

P: 2
@Pramodraya
it works in me using vb 2005,

Imports System
Imports System.IO

Public Class Form1

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click


MkDir(TextBox1.Text)


End Sub
End Class
Jan 16 '09 #17

Post your reply

Sign in to post your reply or Sign up for a free account.