By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,757 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,757 IT Pros & Developers. It's quick & easy.

Create a File Extension

P: 44
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
May 2 '07 #1
Share this Question
Share on Google+
8 Replies


100+
P: 149
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
May 2 '07 #2

P: 20
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
May 2 '07 #3

Expert 5K+
P: 8,434
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.
May 2 '07 #4

P: 44
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?
May 2 '07 #5

P: 44
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?
May 2 '07 #6

Expert 5K+
P: 8,434
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.
May 3 '07 #7

Dököll
Expert 100+
P: 2,364
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub STORE_ME_Click()
  3.  
  4. Open App.Path + "\SaveThisFile.txt" For Append As #1
  5.  
  6.                 Write #1, , Text1.Text
  7.  
  8.                 Close #1
  9.  
  10. Text1.Text = ""
  11.  
  12. End Sub
  13.  
  14.  
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub RETURN_ME_Click()
  3.  
  4. Dim FileLine As String
  5.  
  6. Open App.Path + "\SaveThisFile.txt" For Input As #1
  7.  
  8.                     Do While Not EOF(1)                                                         
  9.                             Input #1, FileLine
  10.                             If FileLine$ <> "" Then
  11.                             Text1.Text = FileLine
  12.                             End If
  13.                     Loop
  14.                     Close #1
  15.  
  16.  
  17. End Sub
  18.  
  19.  
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.txt = SaveThisFile.bttf, therefore to load the file

Hence:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Open App.Path + "\SaveThisFile.bttf" For Append As #1
  3.  
  4.  

Form_Load (Step 2)


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub RETURN_ME_Click()
  3.  
  4. Dim FileLine As String
  5.  
  6. Open App.Path + "\SaveThisFile.bttf" For Input As #1
  7.  
  8. SaveThisFile.bttf = SaveThisFile.txt
  9.  
  10.                     Do While Not EOF(1)                                                         
  11.                             Input #1, FileLine
  12.                             If FileLine$ <> "" Then
  13.                             Text1.Text = FileLine
  14.                             End If
  15.                     Loop
  16.                     Close #1
  17.  
  18.  
  19. End Sub
  20.  
  21.  
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
May 6 '07 #8

P: n/a
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.Registry.ClassesRoot.CreateSubKey(".He llo").SetValue("","Hello",Microsoft.Win32.Registry ValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("Hel lo\shell\open\command").SetValue("", Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.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)|*.hello". 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!
Oct 16 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.