Results 1 to 5 of 5

Thread: How do you get a file to start in Visual Basic 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    2

    How do you get a file to start in Visual Basic 6

    Lets say you made a command button that when pressed would open some type of file. How do you do that?

  2. #2
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: How do you get a file to start in Visual Basic 6

    If you want to just open a text file, for example, just use the open statement.

    If your file is located at C:\MytextFile.txt then your statement would be as simple as:

    Open "C:\MytextFile.txt" for input as #1

    Then to get the first line of the text, if you had dimensioned MyLine as a string, you'd simply have:

    Input #1, MyLine

    Everytime you repeat that, you'll read the next line. When you're done, have the command:

    Close #1

    In Visual Basic just run help and look at OPEN. There are different ways you can open something, such as for input, for append, for output, etc. Data can be sequential or random. And so on.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do you get a file to start in Visual Basic 6

    also you may not want to hard code in the file path so using a CommonDialog control will allow the user to browsae for the desired file to open.

    File Open FAQ:
    http://www.vbforums.com/showthread.php?t=342619
    http://www.vbforums.com/showthread.php?t=405051

    CommonDialog ex:

    Code:
    Option Explicit
    'Add a CommonDialog control to your form.
    'Project > Components > Controls tab > "Microsoft Common Dialog control" > OK
    Private Sub Command1_Click()
        On Error GoTo MyError
        With CommonDialog1
            .CancelError = True
            .DialogTitle = "Common Dialog Example"
            .Filter = "Text files only (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt Or cdlOFNPathMustExist
            .InitDir = App.Path
            .ShowSave 'or .ShowOpen
        End With
        'Do your save/open stuff here
        'Use the CommonDialog1.FileName property to get the full path and file name selected
        '
        Exit Sub
    MyError:
        If Err.Number <> cdlCancel Then
            MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "Save"
        End If
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How do you get a file to start in Visual Basic 6

    I think, exe files can be opened using shell function...
    Code:
    Shell App.path & "\game.exe", vbnormalfocus

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How do you get a file to start in Visual Basic 6

    App.path & "\game.exe"
    is the complete path of the exe file.
    vbnormalfocus
    is the type of display (for maximized, minimize, normal, etc...)

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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