This tutorial is meant to demonstrate one of many different ways that text within a form maybe saved into a text file in a drive. The form will have a button and the text will be directly entered on the form.
Firstly, you will need a Button called cmdSave and the caption Save. Then we basically start coding.
We first place in Option Explicit. This means it forces explicit declaration of all variables in a file.
Now everything revolves around the Save button. We first declare all the variables: list, datafile and item.
Private Sub cmdSave_Click() Dim list(5) As String * 10 Dim datafile As String Dim item As Integer
Continuing on, we then list the text that we want to list in the form. We use "Print" to place in text within the form.
Cls: Print Print "Text File Maker" 'the list of items list(1) = "A" list(2) = "B" list(3) = "C" list(4) = "D" list(5) = "E"
Still under the Save button, we now tell the program to list the items in order ie. 1 to 5
Print "List in alphabetical order" For item = 1 To 5 Print list(item) Next item
This now prints the text in the form into a Text file. You may change the drive name and the text file name. The second part prints the text in order in the file.
Print datafile = "D:\File.txt" 'open the file to receive data Open datafile For Output As 1 For item = 1 To 5 Print #1, list(item) Next item Close #1
So there we have it. A program which saves text on a form into a text file or similar.
This post has been edited by firebolt: 03 April 2009 - 10:25 PM