Page 1 of 1

Saving Data into a Text file from a form Rate Topic: -----

#1 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Posted 03 April 2009 - 12:10 AM

Welcome to this Tutorial on saving data on a form into a text file.
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.
Option Explicit



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.

Thank you.

This post has been edited by firebolt: 03 April 2009 - 10:25 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Saving Data into a Text file

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Posted 06 April 2009 - 03:45 AM

Please correct me if anything in this code is wrong.
Thanks.

This post has been edited by firebolt: 06 April 2009 - 03:46 AM

Was This Post Helpful? 0
  • +
  • -

#3 Vortexfuel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-April 09

Posted 19 April 2009 - 09:09 PM

well done coding one thing missing "END SUB" it's good for beginner

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
End Sub
Was This Post Helpful? 0
  • +
  • -

#4 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Posted 19 April 2009 - 10:30 PM

Thanks for pointing that out! However, I dont have the rights to change it. Maybe you tell a mod or such to change it.

This post has been edited by firebolt: 19 April 2009 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1