Cyber_Plague
asked on
Reading a text file and transfering data to a form
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 :)
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 :)
ASKER
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
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(F orReading)
s = ts.ReadAll
ResultArray = split(s)
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(F
s = ts.ReadAll
ResultArray = split(s)
ASKER
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?
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?
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?
ASKER
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?
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?
ASKER
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)
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)
ASKER
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)
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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)
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
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
ASKER
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)
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)
ASKER
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:)
I'm giving you the points, cause u r doing really great job here:)
txtLine = mid(txtLine,2,len(txtLine)