Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Read/Write in the text file

  Asked By: Anpu    Date: Mar 18    Category: MS Office    Views: 989
  

Code: Write the txtFirstName.text to text file (a.txt) and read from
the text file and show on the txtMsg.text
-------------------------------------------------------------------
Option Explicit

Private Sub btnRead_Click()


Dim sFile As String
Dim sText As String
Dim iFileNum As Integer


sFile = "C:\Documents and Settings\user\Desktop\Testing\a.txt"

iFileNum = FreeFile
Open sFile For Input As iFileNum
Input #iFileNum, sText
Close #iFileNum

//* Read from the text file and show the content into the text
box*//
txtMsg.Text = sText

End Sub

Private Sub btnWrite_Click()

Dim sFile As String
Dim sText As String
Dim iFileNum As Integer

sFile = "C:\Documents and Settings\user\Desktop\Testing\a.txt"

//* Write to the text file *//
sText = txtMsg.Text
iFileNum = FreeFile
Open sFile For Output As iFileNum
Write #iFileNum, sText
Close #iFileNum

End Sub
-------------------------------------------------------------------
Problem:
(1:) Type txtFirstName.Text = Peter, text file show: "Peter"
Read from text file and show : txtMsg.Text = Peter
..It is OK no problem.
(2:) When type: Peter into text file and read from the text file,
-------
the txtMsg.Text = Peter ....this is also normal....

BUT when I type: Peter love IP "10.11.12.13" Or Peter Love IP,
10.12.13.14 on text file, read from text file , the txtMsg.text ONLY
show: Peter love IP (the text behind the " and ,is not able to show
on the text box).

Question: Can I read the word or letter after the " and , from the
text box and show onto the text box without using the open and close
parentesis ???

@@@@@@@
(3) Dim strIP as String
strIP = "10.12.13.14"
txtMsg.Text = "I Love You""" & strIP &"""very much."
The file shown: "I Love You""10.12.13.14""very much."
Q: Can I write ONLY: I Love You"10.12.13.14"very much.(without "
and ") to the text file??
@@@@@@@

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Frank Butler     Answered On: Mar 18

I created a userform with a textbox called txtMsg and a Read button
and copied your code  into the click event for the button.
I then created the a.txt file  and tested your code
and it worked fine!!! Peter loves IP "10.11.12.13"
showed in the text  box.

Try entering a longer string like: Peter loves all IP regardless of
location
and try it.
Does it truncate?
Maybe the problem  is with the definition of the textbox on the userform.
Is there a MaxLength value set?

 
Didn't find what you were looking for? Find more on Read/Write in the text file Or get search suggestion and latest updates.




Tagged: