I'm writing a program that requires opening a file based on what is entered into a text box, ie if 12345 is entered in the text box, 12345.txt will be opened. how would this be accomplished?
Printable View
I'm writing a program that requires opening a file based on what is entered into a text box, ie if 12345 is entered in the text box, 12345.txt will be opened. how would this be accomplished?
You could use the ShellExecute api function.
Or the regular Shell function:Code:Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal _
lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal _
nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
ShellExecute Me.hwnd, vbNullString, Text1.text, vbNullString, "c:\", SW_SHOWNORMAL
Code:Shell "Notepad.exe " & Text1.text, vbNormalFocus
first, thank you for your reply. Looking at your example, would that open the 12345.txt in notepad? i was more going for opening the file for input into my program, so Open "C:\ (strinputtext) .txt" for Iput as #1. Is this possible?
To read files into a text box:
Is this what you wanted?Code:Open "C:\12345.txt" For Input As #1
Text1.Text = Input$(LOF(1), 1)
Close #1
my bad my bad. First I appreciate your patients, I can be quit unclear sometimes. I want to open a file for input, the name of the file to be opened being determined by what is entered in the text box. thank you much this might help
(purely an example)
Which is exactly what I showed you. If someone enters something in a textbox, and clicks a command button, the file will be loaded.
Code:Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, Text1.text, vbNullString, "c:\", SW_SHOWNORMAL
End Sub
Doughboy: Try this
That's all there is to it...Code:Open Text1.Text & ".txt" For Input as #1