More Code Snippets
I was wondering if it was possible to have more code snippets;
like;
- Open a file and place text in that file in a text box.
- Save text in a text box into a file.
- Save text in multiple text boxes into a file.
- Open a file and place the image in that file in a picture box.
- Save image in a picture box into a file.
[350 byte] By [
JasonD] at [2008-2-20]
Using Tools | Code Snippets Manager you can create your own.
Look in the directory: C:\Program Files\Microsoft Visual Studio 8\VB\Snippets\1033 for snippets you can copy & alter
Have fun!
Marinus
Hi Jason,
Thanks for your suggestions. We probably won't be able to ship additional IntelliSense code snippets with this release of Visual Studio, but we definitely appreciate your suggestions and we'll take them into consideration for our next version. If you have more suggestions please let us know.
We're also encouraging users to write and share their own code snippets, and, to expand on Marinus suggestion, a good way to start is to download the VB Snippet Editor: http://msdn.microsoft.com/vbasic/downloads/2005/tools/snippeteditor/
It's a free tool that will make editing and writing your own code snippets easier.
Lorenzo Minore
VB .Net Development
Hi Jason,
I think you can do the first three tasks using snippets in the product. The last two I'll give you the code for. then you can use the code snippet editor tool that Lorenzo mentions to create the actual .snippet file. You could be a hero by posting them back - but i'll leave that to you ;)
- Open a file and place text in that file in a text box.
[py] use the built in snippet:
Snippets > File System ... > Read text from an existing file
Then set the replacement value to your file. the code will look something like this:
| |
Dim filePath As String Dim allText As String Try filePath = System.IO.Path.Combine( _ My.Computer.FileSystem.SpecialDirectories.MyDocuments, "SampleTextFile.txt") allText = My.Computer.FileSystem.ReadAllText(filePath) Catch fileException As Exception Throw fileException End Try
|
- Save text in a text box into a file.
[py] use the built in snippet:
Snippets > File System ... > Write text to files
Then set the replacement value to your file. the code will look something like this:
| |
Dim filePath As String Try My.Computer.FileSystem.WriteAllText("SampleTextFile.txt", Me.TextBox1.Text & vbCrLf, True) Catch fileException As Exception Throw fileException End Try |
- Save text in multiple text boxes into a file.
[py] this is almost identical -- use the built in snippet:
Snippets > File System ... > Write text to files
Then set the replacement value to your file. the code will look something like this:
| |
Dim filePath As String Try My.Computer.FileSystem.WriteAllText("SampleTextFile.txt", Me.TextBox1.Text & vbCrLf, True) My.Computer.FileSystem.WriteAllText("SampleTextFile.txt", Me.TextBox2.Text & vbCrLf, True) Catch fileException As Exception Throw fileException End Try
|
- Open a file and place the image in that file in a picture box.
[py] here is new snippet code
| |
Dim imagePath As String Try imagePath = System.IO.Path.Combine( _ My.Computer.FileSystem.SpecialDirectories.MyPictures, "sunset.jpg") Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage Me.PictureBox1.Load(imagePath) Catch fileException As Exception Throw fileException End Try
|
- Save image in a picture box into a file.
[py] here is new snippet code
| |
Dim imageSavePath As String Try imageSavePath = System.IO.Path.Combine( _ My.Computer.FileSystem.SpecialDirectories.MyPictures, "SavedImage.jpg") Me.PictureBox1.Image.Save(imageSavePath) Catch fileException As Exception Throw fileException End Try
|
This should do the trick :)
Best,
Paul Yuknewicz
Visual Basic Team