Create a File Extension

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • I Hate My Computer
    New Member
    • Mar 2007
    • 44

    Create a File Extension

    I am looking to create a file extension that I can use with my first VB project. I want it to save text like a .txt file but I want it to be a custom file extension like .bttf. I also need to know how to save the text in the textbox to that file in my program. If this is possible I would love to know how.

    Thanks
  • ansumansahu
    New Member
    • Mar 2007
    • 149

    #2
    Originally posted by I Hate My Computer
    I am looking to create a file extension that I can use with my first VB project. I want it to save text like a .txt file but I want it to be a custom file extension like .bttf. I also need to know how to save the text in the textbox to that file in my program. If this is possible I would love to know how.

    Thanks

    You can infact use any extension that you like whenh you save the file. Just for example have .txt file created on your machine. Open this file in notepad and enter some texts and save it.Then manually go and change the extension of the file from .txt to .bttf. Then again try to open the file. It will ask you in which program to open it. Use notepad once again and see whats happening.
    Regarding saving the text from the text box it should be the same procedure that you would have followed for writing the text to a text file.

    good luck
    -ansuman sahu

    Comment

    • ChillUmesh
      New Member
      • Feb 2007
      • 20

      #3
      Originally posted by I Hate My Computer
      I am looking to create a file extension that I can use with my first VB project. I want it to save text like a .txt file but I want it to be a custom file extension like .bttf. I also need to know how to save the text in the textbox to that file in my program. If this is possible I would love to know how.

      Thanks
      u cant save text which is in textbox for dat use rich text box

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by ChillUmesh
        u cant save text which is in textbox for dat use rich text box
        If I might elaborate slightly, I think what ChillUmesh is trying to say is that the textbox control doesn't include a method to save the text, as is the case for the RichTextBox control.

        That does not mean that you can't save the text, of course - it simply means that your code must do the file-access work itself rather than relying on the control to handle it. This is not difficult.

        Comment

        • I Hate My Computer
          New Member
          • Mar 2007
          • 44

          #5
          Originally posted by ansumansahu
          You can infact use any extension that you like whenh you save the file. Just for example have .txt file created on your machine. Open this file in notepad and enter some texts and save it.Then manually go and change the extension of the file from .txt to .bttf. Then again try to open the file. It will ask you in which program to open it. Use notepad once again and see whats happening.
          Regarding saving the text from the text box it should be the same procedure that you would have followed for writing the text to a text file.

          good luck
          -ansuman sahu
          I understand this, but I want it to open with my program and not have to choose a program to open with every time you open it. Can I do this?

          Comment

          • I Hate My Computer
            New Member
            • Mar 2007
            • 44

            #6
            Originally posted by ChillUmesh
            u cant save text which is in textbox for dat use rich text box
            I have a rich textbox, how do I save the data/text in the textbox?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by I Hate My Computer
              I understand this, but I want it to open with my program and not have to choose a program to open with every time you open it. Can I do this?
              If you want this to happen on other computers, you'll have to set up an installation procedure to register the file extension. Not sure how you do that. But on your own PC, when it asks, just tick the "always use this program" option so it won't ask again next time.

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                #8
                Originally posted by I Hate My Computer
                I have a rich textbox, how do I save the data/text in the textbox?
                You must truly hate your computer:-)

                I think I got an idea that might work. We'll start by helping you save to .txt and we'll discuss the rest. Everyone please throw your hat, I am not sure hw far I can go with this:

                (1) When you load text to say 'Text1.Text', have it saved on your machine as .txt

                Code:
                Private Sub STORE_ME_Click()
                
                Open App.Path + "\SaveThisFile.txt" For Append As #1
                
                                Write #1, , Text1.Text
                                
                                Close #1
                                
                Text1.Text = ""
                
                End Sub
                Have your Form_Load look for this text in that file. When file loads back to your application:

                (2) Tell Form_Load to add it in Text1.Text

                Form_Load Code

                Code:
                Private Sub RETURN_ME_Click()
                
                Dim FileLine As String
                
                Open App.Path + "\SaveThisFile.txt" For Input As #1
                                
                                    Do While Not EOF(1)                                                         
                                            Input #1, FileLine
                                            If FileLine$ <> "" Then
                                            Text1.Text = FileLine
                                            End If
                                    Loop
                                    Close #1
                
                
                End Sub
                Now if that works, and you can see data in Text1.Text. You can try saving and retrieving as bttf. Here's the problem, you can modify the code to save as the file extension of your choice, but Windows does not seem to know how to open the file as bttf. Unless you tell VB:

                (3) SaveThisFile.tx t = SaveThisFile.bt tf, therefore to load the file

                Hence:

                Code:
                Open App.Path + "\SaveThisFile.bttf" For Append As #1

                Form_Load (Step 2)


                Code:
                Private Sub RETURN_ME_Click()
                
                Dim FileLine As String
                
                Open App.Path + "\SaveThisFile.bttf" For Input As #1
                
                [B]SaveThisFile.bttf = SaveThisFile.txt[/B]
                               
                                    Do While Not EOF(1)                                                         
                                            Input #1, FileLine
                                            If FileLine$ <> "" Then
                                            Text1.Text = FileLine
                                            End If
                                    Loop
                                    Close #1
                
                
                End Sub
                I am not sure how this makes logical sense or whether, it can work, VB is not installed here cannot run it. Give me sometime to look through it again on my notebook. Please throw your hat in, Scripts Members.

                Dököll

                Comment

                • L Typerado

                  #9
                  Reply: How to create a file association

                  Try this:
                  Use the Form1.Load command to create a file type/association. This shows how to create a file type that looks like *.hello:

                  My.Computer.Reg istry.ClassesRo ot.CreateSubKey (".Hello").SetV alue("","Hello" ,Microsoft.Win3 2.RegistryValue Kind.String)
                  My.Computer.Reg istry.ClassesRo ot.CreateSubKey ("Hello\shell\o pen\command").S etValue("", Application.Exe cutablePath & " ""%l"" ", Microsoft.Win32 .RegistryValueK ind.String)

                  Now add the rich text box object to your form along with a Save file Dialog, and an Open File dialog. Change the filter on both dialogs to "Hello Files (*.hello)|*.hel lo". Now the user can open and save hello files, and your program will launch when that file type is clicked.
                  Good luck!
                  Hope this helped!

                  Comment

                  Working...