creating a file of particular extension

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravindarjobs
    New Member
    • May 2007
    • 86

    creating a file of particular extension

    i am using ms access 2003, vb6.

    i want to create a file of extension ".gms"(if not, any particular extension)
    how can i do this?

    also after creating it, i want to open the file with default viewer(default opening application for .gms extenision files).

    how can i do this?

    thanq
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Do you have any idea how to create a file at all, yet?

    Comment

    • ravindarjobs
      New Member
      • May 2007
      • 86

      #3
      --- Do you have any idea how to create a file at all, yet?



      no i dont have knowledge of it.

      i have searched for file creation examples over net,
      i have this code

      Dim file As System.IO.FileS tream
      file = System.IO.file. Create("c:\test .txt")




      but it is giving error in Dim statement as compiler error, user -defined type not defined.

      this error might be due to missing referene. but i couldnt figure out which one is missing.


      thanq

      Comment

      • cyberdaemon
        New Member
        • Jul 2007
        • 38

        #4
        Originally posted by ravindarjobs
        --- Do you have any idea how to create a file at all, yet?



        no i dont have knowledge of it.

        i have searched for file creation examples over net,
        i have this code

        Dim file As System.IO.FileS tream
        file = System.IO.file. Create("c:\test .txt")




        but it is giving error in Dim statement as compiler error, user -defined type not defined.

        this error might be due to missing referene. but i couldnt figure out which one is missing.


        thanq
        The reason for the error is in Visual Basic .NET most everything is an object and thus an Instance must be made of said object. Using the NEW keywork you can accomplish this task.

        the statement:
        Code:
        Dim file As System.IO.FileStream
        does not work

        however:

        Code:
        Dim file As NEW System.IO.FileStream (<path>, <mode>)
        does work
        also it could have written as
        Code:
        Dim file as System.IO.FileStream = System.File.Create("c:\test.txt")
        I also noticed you used the word "file" as your file stream. file is a class of the namespace system.IO, I find it bad practice to use class names as variable names, even if the compiler lets you. The code below is an example of how to write a file with a few lines of text in it.

        Code:
        ' Create the File stream for the ability to read and write to a specified file
                Dim NewFile As New IO.FileStream("C:\somefile.txt", IO.FileMode.Create)
        
                ' Create a writer object,  and have it use the stream created above
                Dim writer As New IO.StreamWriter(NewFile)
        
                ' Write the file
                writer.WriteLine("Hello Filesystem World!!!")
                writer.WriteLine("This is my first text document written with Visual Basic!")
        
                ' VERY IMPORTANT:  Close the file
                writer.Close()
        You question was to create a custom file extention, this is done byt simply changeing the file extention on creation

        Dim NewFile As New IO.FileStream(" C:\somefile.xyz ", IO.FileMode.Cre ate)

        or

        Dim NewFile As New IO.FileStream(" C:\somefile.flo b", IO.FileMode.Cre ate)

        keep in mind that the contents of the file are what you write to them, if you write "Happy birthday susie" and saved it as susie.jpeg extension. you will confuse any image reading software and if opened in notepad will read "Happy birthday susie"

        there are encoding formats built into the .NET framwork (i.e. Unicode UTF-32, Unicode UTF-16, Unicode UTF-8, ASCII, and ANSI/ISO) but that is for a different question.

        I hope this information helps you, good luck and happy coding

        I do apologize for the length, I felt it adaquate to answer your question

        Cyberdaemon

        EDIT: When I read your original post I though you said using Visual Studio 2003...this is .NET suff. Most of the information still applies. I do apologize for the mistake.

        Comment

        • cyberdaemon
          New Member
          • Jul 2007
          • 38

          #5
          General file access in VB6:

          open "C:\somefile.tx t" for output as #1

          print #1, "Hello FileSystem World!!"

          close #1

          everything else still applies concerning the file extension

          Cyberdaemon

          Comment

          • ravindarjobs
            New Member
            • May 2007
            • 86

            #6
            thanq frnds.

            a similar question.
            suppose i have a word file a.doc file. when i click the button the file should be opened with the default viewer(here the default viewer is ms word),
            and the same way how to open a partuicular file with default viewer of its?

            Comment

            Working...