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

Dani AI

Generated

Two quick gotchas explain why your output was stuck on one line and still had quotes. First, make sure the destination control is multiline. In VB6 a TextBox will ignore vbCrLf unless Text1.MultiLine = True. That is the reason your lines were concatenating in post #4, . Second, instead of showing the whole line, split it and display just the column(s) you want.

Here is a simple, safe pattern that reads each line, splits on the comma, strips wrapping quotes, and appends only the movie title. It also uses FreeFile and App.Path so you do not hardcode file handles or absolute paths:

Option Explicit

Private Function Unquote$(ByVal s As String)
    s = Trim$(s)
    If Len(s) >= 2 And Left$(s, 1) = """" And Right$(s, 1) = """" Then
        Unquote = Mid$(s, 2, Len(s) - 2)
    Else
        Unquote = s
    End If
End Function

Private Sub Command1_Click()
    Dim f As Integer, line As String, parts() As String, out As String
    f = FreeFile
    Open App.Path & "\CINEMA\reserve.txt" For Input As #f
    Do While Not EOF(f)
        Line Input #f, line
        parts = Split(line, ",")
        If UBound(parts) >= 0 Then out = out & Unquote(parts(0)) & vbCrLf
    Loop
    Close #f
    Text1.MultiLine = True
    Text1.Text = out
End Sub

Notes:

  • If a title itself contains a comma (e.g. "Batman, The"), a naive Split will over-split. In that case, the CSV-aware approach suggested (reading into two String variables) is safer because VB6 understands quoted fields.
  • For : your ping idea is different enough that it deserves its own thread (as said). Read each IP into a list, iterate, and shell out to ping or use the Win32 ICMP API.

Recommended Answers

All 9 Replies

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.

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

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

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

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

thanks alot =)

i want to read a list of ip adresses from a text file but line by line inorder to ping them and put each adress in a textbox

thnx for ur responses

: make your own thread dude..don't raise dead thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.