Results 1 to 8 of 8

Thread: How to open files using dialog box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Question How to open files using dialog box

    VB Code:
    1. Const forreading = 1, Forwriting = 2
    2. Dim fs, f
    3.  
    4. Private Sub Form_Load()
    5. CommonDialog1.Filter = "All Files(*.*)|*.*|Text files(*.*)|*.txt"
    6. CommonDialog1.FilterIndex = 2
    7. CommonDialog1.ShowOpen
    8. If CommonDialog1.FileName <> "" Then
    9. Set f = fs.opentextfile(CommonDialog1.FileName, forreading)
    10. Text1.Text = f.readall
    11. f.Close :confused:
    12. End If
    13. End Sub
    The above code is not working.Please correct errors if any

    P.S It should prompt a dialog box and open a text file .
    Last edited by vbanswers; Sep 13th, 2006 at 11:00 PM. Reason: code missing

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

    Re: How to open files using dialog box

    What exactly are you trying to do? You can not open either of those files in runtime. Are you using VBA?
    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

  3. #3
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: How to open files using dialog box

    if you are trying to open a form, do
    VB Code:
    1. Form1.Show
    where Form1 is the form you want.

    If you want to open files, then you'll need a Command Dialog component. Right click on the toolbar, select components, and look for Microsoft Common Dialog 6.0, and tick it and then press ok. Insert it into your project and put the following into your code
    VB Code:
    1. commondialog1.Filter = "All|*.exe" ' Replace this with extensions you want
    2. commondialog1.ShowOpen

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

    Re: How to open files using dialog box

    If this is VBA then there is no commondialog control. VBA does give you some built in functions for displaying a "commondialog" box though. It differs depending on the office app your using.
    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

  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: How to open files using dialog box

    ...although you can add the common dialog component to VBA if you have vb6 installed as well.


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

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

    Re: How to open files using dialog box

    Yes, but then you would also have to distribute the ocx along with the document or workbook etc.
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: How to open files using dialog box

    I am trying to open a text box by using commondialog control. I am using vb 6.

  8. #8
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: How to open files using dialog box

    What do you exactly mean by "open a text box"?

    If you mean trying to load a form file into your VB project in run time, then you are going to have problems. What RoboDog888 said (in 4th post) was correct. You can't just load it!

    I don't know how to explain it any better, but if you're trying to do the above, short answer is no.

    If it's anything else, explain!!!

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