954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

read multi line txt.file and display in textbox

i would like to read some data and display it in textbox.

my example of data in my txt file are:
"moviename1", "movieshowtime1"
"moviename2", "movieshowtime2"

when i display it in text box, it shows exactly like above.
i want it to display without the quotes.
how i can achive tat?
moviename1, movieshowtime1
moviename2, movieshowtime2

this is my code

Private Sub Command1_Click()

Dim dText As String, dNextLine As String, lLineCount As Long
lLineCount = 1

        Open "C:\Users\Chern\CINEMA\reserve.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, dNextLine
            dText = dText & dNextLine & vbCrLf
        Loop
        Text1.Text = dText
        
End Sub
chern4ever
Light Poster
42 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

Hi,
Use the Replace function.
The syntax is

Replace(string, find, replace)

Doing it in your code:

Private Sub Command1_Click()

Dim dText As String, dNextLine As String, lLineCount As Long
lLineCount = 1

        Open "C:\Users\Chern\CINEMA\reserve.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, dNextLine
            dNextLine = Replace(dNextLine, Chr$(34), "")
            dText = dText & dNextLine & vbCrLf
        Loop
        Text1.Text = dText
        
End Sub

Chr$(34) is the " char.

Hope it helps.

dmf1978
Junior Poster in Training
51 posts since Aug 2006
Reputation Points: 18
Solved Threads: 7
 

Use Input statement instead of Line Input

Ex

Private Sub Command1_Click()
   Dim dText As String
   Dim sString1 As String, sString2 As String

   Open "C:\Users\Chern\CINEMA\reserve.txt" For Input As #1
   Do While Not EOF(1)
       Input #1, sString1, sString2
       dText = dText & sString1 & ", " & sString2 & vbCrLf
   Loop
   Text1.Text = dText
End Sub
selvaganapathy
Posting Pro
547 posts since Feb 2008
Reputation Points: 44
Solved Threads: 100
 

i have another problem, i wan it to appear like this
moviename1, movieshowtime1
moviename2, movieshowtime2

but it wont jump to second line, it stick together
moviename1,movieshowtime1moviename2,movieshowtime2

thanks for helping

chern4ever
Light Poster
42 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

thanks i solve my previous problem.
now another problem.
in my txt file :
moviename1, movieshowtime1
moviename2, movieshowtime2

i want to show only this in a text box. is that possible?
moviename1
moviename2

chern4ever
Light Poster
42 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

Hi, my above example will solve your problem. just modify the above example.

selvaganapathy
Posting Pro
547 posts since Feb 2008
Reputation Points: 44
Solved Threads: 100
 

thanks alot =)

chern4ever
Light Poster
42 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You