5 Replies - 764 Views - Last Post: 04 May 2009 - 09:44 AM Rate Topic: -----

#1 darrkwolfy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 27-March 09

how do i read from txt document

Posted 20 April 2009 - 10:49 AM

i found a tutorial on this site for writing the contents of a text box to a text document but it does not tell you how to load it i tried messing around with the print code but it just does nothing can anyone tell me what I'm doing wrong.

Option Explicit

Private Sub CMD1_Click()
On Error GoTo errorhandler

Dim abc As Control

For Each abc In BPv2.Controls
	If TypeOf abc Is TextBox Then

		If abc.Text = "" Then
		abc.Text = "0"
		End If

	End If
Next abc

Dim Sum1 As Integer
Dim Sum2 As Integer
Dim Sum3 As Integer
Dim Sum4 As Integer
Dim Sum5 As Integer

Sum1 = Val(TXT1a.Text * txt1d.Text) + (TXT2a.Text * txt2d.Text) + (TXT3a.Text * txt3d.Text) + (TXT4a.Text * txt4d.Text) + (TXT5a.Text * txt5d.Text) + (TXT6a.Text * txt6d.Text) + (TXT7a.Text * txt7d.Text) + (TXT8a.Text * txt8d.Text) + (TXT9a.Text * txt9d.Text) + (TXT10a.Text * txt10d.Text)
	 Label1.Caption = Sum1
	 
Sum2 = Val(TXT1b.Text * txt1d.Text) + (TXT2b.Text * txt2d.Text) + (TXT3b.Text * txt3d.Text) + (TXT4b.Text * txt4d.Text) + (TXT5b.Text * txt5d.Text) + (TXT6b.Text * txt6d.Text) + (TXT7b.Text * txt7d.Text) + (TXT8b.Text * txt8d.Text) + (TXT9b.Text * txt9d.Text) + (TXT10b.Text * txt10d.Text)
	 Label2.Caption = Sum2

Sum3 = Val(TXT1c.Text * txt1d.Text) + (TXT2c.Text * txt2d.Text) + (TXT3c.Text * txt3d.Text) + (TXT4c.Text * txt4d.Text) + (TXT5c.Text * txt5d.Text) + (TXT6c.Text * txt6d.Text) + (TXT7c.Text * txt7d.Text) + (TXT8c.Text * txt8d.Text) + (TXT9c.Text * txt9d.Text) + (TXT10c.Text * txt10d.Text)
	 Label3.Caption = Sum3
	 
Sum4 = Val(txt1d.Text) + (txt2d.Text) + (txt3d.Text) + (txt4d.Text) + (txt5d.Text) + (txt6d.Text) + (txt7d.Text) + (txt8d.Text) + (txt9d.Text) + (txt10d.Text)
	 Label4.Caption = Sum4
	 
Sum5 = Val(TXTcoins.Text) * (Sum4)
	 Label5.Caption = Sum5
Exit Sub
errorhandler:
MsgBox "Please enter a valid number", vbCritical
End Sub

Private Sub cmd2_Click()

Dim abc As Control

For Each abc In BPv2.Controls
	If TypeOf abc Is TextBox Then

		If abc.Text <> "" Then
		abc.Text = ""
		End If
End If
Next abc


If Label1.Caption <> "" Then
 Label1.Caption = ""
End If
If Label2.Caption <> "" Then
 Label2.Caption = ""
End If
If Label3.Caption <> "" Then
 Label3.Caption = ""
End If
If Label4.Caption <> "" Then
 Label4.Caption = ""
End If
If Label5.Caption <> "" Then
 Label5.Caption = ""
End If

	
End Sub



Private Sub load_Click()

Dim list(5) As String * 10
Dim datafile As String
Dim item As Integer

Label1.Caption = list(1)
Label2.Caption = list(2)
Label3.Caption = list(3)
Label4.Caption = list(4)
Label5.Caption = list(5)


datafile = "C:\File.txt"


Open datafile For Input As 1


For item = 1 To 5
Input #1, list(item)
Next item
Close #1



End Sub


Private Sub save_Click()
Dim list(5) As String * 10
Dim datafile As String
Dim item As Integer


Cls: Print
Print "Text File Maker"

'the list of items
list(1) = Label1.Caption
list(2) = Label2.Caption
list(3) = Label3.Caption
list(4) = Label4.Caption
list(5) = Label5.Caption



Print
datafile = "C:\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


This post has been edited by darrkwolfy: 20 April 2009 - 10:51 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how do i read from txt document

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

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

Re: how do i read from txt document

Posted 20 April 2009 - 04:45 PM

My tutorial was not of that purpose. It was for writing the contents of a form (such as a string) into a text file. However you can configure that to make it a textbox. Like so: (Please look at the documentation within the code)
Dim list(2) As String * 10 '<<<List(2) refers to how many fields
Dim datafile As String
Dim item As Integer

'the list of items
list(1) = Text1.Text '<<<Optional textboxes
list(2) = Text2.Text

Print
datafile = "C:\File.txt" '<<<Create this file

'open the file to receive data
Open datafile For Output As 1

For item = 1 To 2 '<<<Shows how many fields
Print #1, list(item)
Next item
Close #1


This post has been edited by firebolt: 20 April 2009 - 04:46 PM

Was This Post Helpful? 0
  • +
  • -

#3 SoloFrog  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 25
  • Joined: 20-April 09

Re: how do i read from txt document

Posted 20 April 2009 - 08:21 PM

Im not sure if this will help.
But do you mean to read from a text file and then have the text able to print to a text box?
here is some code from one of my programs.

Dim fileText As String = My.Computer.FileSystem.ReadAllText("c:\" & selectedHero & ".rtf")



This gives the variable fileText the data of the text file
and...
infoDisplay.AppendText(fileText)


Would print out the files contents to a Rich Text box named infoDisplay. But you could use any type of text box.

Sorry if this wasnt what you are looking for. Just new to the site, thought i would try and help :(
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

Re: how do i read from txt document

Posted 20 April 2009 - 08:42 PM

Also, my method is just one of many different methods that serve the same purpose. Please read my tutorial more carefully to understand its purpose.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: how do i read from txt document

Posted 20 April 2009 - 08:45 PM

@SoloFron: Your code is VB.NET code and the OP is asking for help with VB6 :)
Was This Post Helpful? 0
  • +
  • -

#6 darrkwolfy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 27-March 09

Re: how do i read from txt document

Posted 04 May 2009 - 09:44 AM

i thought i had already posted back here but i guess not ive been really busy lately with school thx for trying to help but i found a way to make it work so that it will read back the strings it writes to file into the correct place.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1