Hey, I have a new tutorial to share to you guys, this tutorial is very exciting and good practice for newbies in programming.
Today we are going to work with files, different types of files, this tutorial is all about making file in visual basic 2008 and above versions. (I do not know if this codes will worked at vb6, well I guess it's worth a try)
Now, we all know that file is very important in digital world. OS and other programs are made out of file that contains a series of codes and instructions.
There are lots of common files that can be made in visual basic. I will give you some of the common files used nowadays.
Here are samples of common Text Files
and here are some of the common Data Files
In visual basic we can make a file that is listed above, we just need a simple code yet powerful to create files.
How to make a static file?
If you want to create a static file with fix file name and fix location where to save it you will need to write this code.
As you notice the file name and the location of the file to be created are programmatically fixed as "C:\MyFile.txt". This is the very basic code on how to create a static file.
How to make a Dynamic file?
If you are planning to create a file that you want to save it on a specific drives, put a specific file name and put a specific file extension you will need some additional controls on your project. Put this controls in your program.
1 ComboBox = List all the drives where to save the file
1 ComboBox = List all the specific file extensions
1 Textbox = Field to type a specific file name for new file to be created
1 Button = Set as Create File
How to edit items on combo box?
Once all the controls are set and ready for coding, select 1 combo box and you will notice that there is a small arrow on top of it. Click it and select 'Edit Items', Now each item must be separated by new line, after typing an item just press Enter to go to the next line.
now that all the controls are ready, you will need the following code to create or make a dynamic file types in visual basic.
Note that this code must be written into the button1_click event that serve as the 'Create File' button.
To check that the file has been created, browse on the drive where you set as the location of the file you created.
I have uploaded a video tutorial on how you can make a file with visual basic 2010 for beginners just to get you some example or what is this tutorial about.
Watch Video Tutorial
Today we are going to work with files, different types of files, this tutorial is all about making file in visual basic 2008 and above versions. (I do not know if this codes will worked at vb6, well I guess it's worth a try)
Now, we all know that file is very important in digital world. OS and other programs are made out of file that contains a series of codes and instructions.
There are lots of common files that can be made in visual basic. I will give you some of the common files used nowadays.
Here are samples of common Text Files
.doc | Microsoft Word Document |
.docx | Microsoft Word Open XML Document |
.log | Log File |
.msg | Outlook Mail Message |
.odt | OpenDocument Text Document |
.pages | Pages Document |
.rtf | Rich Text Format File |
.tex | LaTeX Source Document |
.txt | Plain Text File |
.wpd | WordPerfect Document |
.wps | Microsoft Works Word Processor Document |
and here are some of the common Data Files
.csv | Comma Separated Values File |
.dat | Data File |
.gbr | Gerber File |
.ged | GEDCOM Genealogy Data File |
.ibooks | Multi-Touch iBook |
.key | Keynote Presentation |
.keychain | Mac OS X Keychain File |
.pps | PowerPoint Slide Show |
.ppt | PowerPoint Presentation |
.pptx | PowerPoint Open XML Presentation |
.sdf | Standard Data File |
.tar | Consolidated Unix File Archive |
.tax2012 | TurboTax 2012 Tax Return |
.vcf | vCard File |
.xml | XML File |
In visual basic we can make a file that is listed above, we just need a simple code yet powerful to create files.
How to make a static file?
If you want to create a static file with fix file name and fix location where to save it you will need to write this code.
Dim path as String = "C:\MyFile.txt"Dim FS as FileStream = File.Create(path)Msgbox(path + " created")
As you notice the file name and the location of the file to be created are programmatically fixed as "C:\MyFile.txt". This is the very basic code on how to create a static file.
How to make a Dynamic file?
If you are planning to create a file that you want to save it on a specific drives, put a specific file name and put a specific file extension you will need some additional controls on your project. Put this controls in your program.
1 ComboBox = List all the drives where to save the file
1 ComboBox = List all the specific file extensions
1 Textbox = Field to type a specific file name for new file to be created
1 Button = Set as Create File
How to edit items on combo box?
Once all the controls are set and ready for coding, select 1 combo box and you will notice that there is a small arrow on top of it. Click it and select 'Edit Items', Now each item must be separated by new line, after typing an item just press Enter to go to the next line.
now that all the controls are ready, you will need the following code to create or make a dynamic file types in visual basic.
Dim path as string = Combobox1.text + Textbox1.text + Combobox2.textDim FS as FileStream = File.Create(path)Msgbox(path + " Has been created")
Your program must look like this |
Note that this code must be written into the button1_click event that serve as the 'Create File' button.
To check that the file has been created, browse on the drive where you set as the location of the file you created.
I have uploaded a video tutorial on how you can make a file with visual basic 2010 for beginners just to get you some example or what is this tutorial about.
Watch Video Tutorial
No comments:
Post a Comment