Link to home
Create AccountLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

vb6 - display first line from string

Hello there,
I have a string with data and I would like to have a button to display the first line of the string
for example.

string has this data

name1
name2
name3

so if i press the button I want it to display name1
ASKER CERTIFIED SOLUTION
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of karthika_cts
karthika_cts

save the data in a text file "a.txt" as
name1
name2
name3
let the text file be in your application path
then use either the following code...

Dim tmpLine as String
    Dim Name as String 'name selected in your program
    File = App.path & "\Text.txt"
    Open File for Input as #1
        Do Until EOF(1)
            Line Input #1, tmpLine
            if tmpLine = Name Then
                MsgBox "Name Exists in this txt file", vbOkOnly
                Exit Loop
            End if
        Loop
    Close #1


or

dim fs as new filesystemobject
dim fstxt as textstream
set fstxt=fs.opentextfile(App.path & "\a.txt")    ----check whether slash comes by checkign the App path
msgbox fstt.readline()
set fstxt=nothing
fs.close