Results 1 to 7 of 7

Thread: Opening a specified file

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    13

    Exclamation

    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?

  2. #2
    Guest
    You could use the ShellExecute api 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
    Or the regular Shell function:

    Code:
    Shell "Notepad.exe " & Text1.text, vbNormalFocus

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    13
    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?
    Pie, I'm just going to go like this and if you get eaten, it's your own fault.- Homer Simpson

  4. #4
    Guest
    To read files into a text box:

    Code:
    Open "C:\12345.txt" For Input As #1 
    Text1.Text = Input$(LOF(1), 1) 
    Close #1
    Is this what you wanted?

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    13
    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)


    Pie, I'm just going to go like this and if you get eaten, it's your own fault.- Homer Simpson

  6. #6
    Guest
    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

  7. #7
    Guest
    Doughboy: Try this

    Code:
    Open Text1.Text & ".txt" For Input as #1
    That's all there is to it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width