Reading a text file and transfering data to a form

Cyber_Plague
Cyber_Plague used Ask the Experts™
on
Hi,

I have a problem here. I have a program which creates txt file and puts some data in it. The problem is - when i'm trying to read data from that file to the textbox in a form, it puts data in a quotation-marks: for example "John Brown" .
Does anybody know how to avaoid those quotation-marks? Meaning, I need that data to be written like this: John Brown, without quotation-marks.
I'll be glad to here every suggestion you have :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Te data was written to the File with WRITE instead of PRINT. WRITE encloses your text with ".  If you can change the program that generates the textfile to use PRINT then there wont be any ". otherwise you have to trim them away

txtLine = mid(txtLine,2,len(txtLine)-2)

Author

Commented:
Perfect solution! I'm a novice to VB, so this advice is very helpfull. I would like to make and amendemend to my question - how can i create an array from the data i'm writing to that file (for example : Name, Last name, Phone numb.)and organize search in that array?
I'll raise up points given to 100
use vb function "split", it acts on a text stream (read ur file in a single statement using "readall") and return an array of lines.

    Dim fso As New FileSystemObject
    Dim txtfile As File
    Dim ts As TextStream
    Dim ResultArray
    filename = App.Path & "\log.txt"
    Set txtfile = fso.GetFile(filename)
    Set ts = txtfile.OpenAsTextStream(ForReading)
    s = ts.ReadAll
    ResultArray = split(s)
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
OK. now i get the array. so need to organize sorting and search now. how can i do that?
Here is the code of my program, that creates txt file:
***************************
Private Sub Command1_Click()
Dim nFile As Integer
nFile = FreeFile
Open "C:\myfile.txt" For Append Shared As #nFile
Print #nFile, CStr(Text1.Text) + " " + CStr(Text2.Text)
Close #nFile
End Sub
(Actually it's your code KashifZia :) )
**************************
So now i need to create an array from those text1.text and text2.text and organize search. Meaning, if i have an array of statements, like this:
John Smith
Adam Brown
Mary Sue
I need to organize search by any part of those words and show the results in a different textbox.
For example: Search string is "Mary", and I must got the
"Mary Sue" on a new textbox.
Can u hekp me with that KashifZia?

yes
but plz tell me how did u make an array, from file? and u want to search in THAT ARRAY giving search string in text boxes and the display the result in another textbox?

Author

Commented:
OK. now i get the array. so need to organize sorting and search now. how can i do that?
Here is the code of my program, that creates txt file:
***************************
Private Sub Command1_Click()
Dim nFile As Integer
nFile = FreeFile
Open "C:\myfile.txt" For Append Shared As #nFile
Print #nFile, CStr(Text1.Text) + " " + CStr(Text2.Text)
Close #nFile
End Sub
(Actually it's your code KashifZia :) )
**************************
So now i need to create an array from those text1.text and text2.text and organize search. Meaning, if i have an array of statements, like this:
John Smith
Adam Brown
Mary Sue
I need to organize search by any part of those words and show the results in a different textbox.
For example: Search string is "Mary", and I must got the
"Mary Sue" on a new textbox.
Can u hekp me with that KashifZia?

Author

Commented:
Thanx. The one record consists of all info about the person: meaning name (text1.text) and last name(tetx2.text). I need to put this info to txt file, line by line. All records must be joined into array (still thinking how to do that :( )and afterwards i need to organize search: meaning, if i want to find a person by the name or last name, i simple put a word in a search text box (text3.text) and get the results in another text box (text4.text). So the task is:
1.Create txt file (it's done)
2.Write all names to it (done)
3. Declare that every one record is a part of array
4. Sort this array
5.Organize search (by any part of a word or number)
6.Display results in a big text box (text4.text)

Author

Commented:
Thanx. The one record consists of all info about the person: meaning name (text1.text) and last name(tetx2.text). I need to put this info to txt file, line by line. All records must be joined into array (still thinking how to do that :( )and afterwards i need to organize search: meaning, if i want to find a person by the name or last name, i simple put a word in a search text box (text3.text) and get the results in another text box (text4.text). So the task is:
1.Create txt file (it's done)
2.Write all names to it (done)
3. Declare that every one record is a part of array
4. Sort this array
5.Organize search (by any part of a word or number)
6.Display results in a big text box (text4.text)
ok
 for part 3->
Read the file as i told u.
now u have an array of all line of txt file.
 for part 4->
why do u want to sort this array. array sorting is itself a long process. u can search whatever u like in that array. if u want to sort it for display, just hoild this problem for the time being.
 for part 5->
now for search, u ahve to be column familiar too. in what column u want to search (first_name or age). now ur array contains the lines of text file (keep it in mind). okay lets make it simple too u want to search first name and want to display all data for that name.
for this just pass through this array and pick up the first find (for multilple finds u can think of appropriate stretegy). it would be something like this assuming ResultArray  is array of lines.

dim i as integer
for i = 0 to UBound(ResultArray)
    if ResultArray(i) = text3.text then
      text4.text = ResultArray(i)
      exit for  
    end if
next i
dim i as integer
for i = 0 to UBound(ResultArray)-1
   if ResultArray(i) = text3.text then
     text4.text = ResultArray(i)
     exit for  
   end if
next i
sorry i forgot one thing.
wait for 5 min
Private Sub Command1_Click()
Dim myarr(5) As String
myarr(0) = "hello this world"
myarr(1) = "hello1 this world"
myarr(2) = "hello2 this world"
myarr(3) = "hello3 this world"
myarr(4) = "hello4 this world"

For i = 0 To UBound(myarr)
    arr = Split(myarr(i), " ")
    For j = 0 To UBound(arr)
        MsgBox arr(j)
    Next
Next
End Sub

***********************
just ty above code for understanding
Dim myarr(5) As String
myarr(0) = "hello this world"
myarr(1) = "hello1 this world"
myarr(2) = "hello2 this world"
myarr(3) = "hello3 this world"
myarr(4) = "hello4 this world"

For i = 0 To UBound(myarr)
    arr = Split(myarr(i), " ")
    For j = 0 To UBound(arr)
        If Text1.Text = arr(j) Then
            Text2.Text = myarr(i)
        End If
    Next
Next
End Sub
 ******************
now try this
i hope it would be enough
cheers

Author

Commented:
Thanx. The one record consists of all info about the person: meaning name (text1.text) and last name(tetx2.text). I need to put this info to txt file, line by line. All records must be joined into array (still thinking how to do that :( )and afterwards i need to organize search: meaning, if i want to find a person by the name or last name, i simple put a word in a search text box (text3.text) and get the results in another text box (text4.text). So the task is:
1.Create txt file (it's done)
2.Write all names to it (done)
3. Declare that every one record is a part of array
4. Sort this array
5.Organize search (by any part of a word or number)
6.Display results in a big text box (text4.text)

Author

Commented:
Sorry:( Just returned - had my lunch brake :) OK, i'll try this code at home and let you know what happens, on monday.
I'm giving you the points, cause u r doing really great job here:)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial