how to read the value from a text file?
-
I m new to VB 6 programming and i have encountered some problems. I have to load a text file into the program and search through the file to find a keyword 'entities'. When the program reaches the keyword, it has load some values at different lines of this text file into the program array. This is one of the possible algorithm i have thought of: 1.Select the file 2.Search through the file for keyword 'Entities' 3.Load the values into the array. However, i am stuck in step 2. Could anyone of you please give me some suggestions on how to complete step 2 and step 3?? Thankyou so much. Esther
-
I m new to VB 6 programming and i have encountered some problems. I have to load a text file into the program and search through the file to find a keyword 'entities'. When the program reaches the keyword, it has load some values at different lines of this text file into the program array. This is one of the possible algorithm i have thought of: 1.Select the file 2.Search through the file for keyword 'Entities' 3.Load the values into the array. However, i am stuck in step 2. Could anyone of you please give me some suggestions on how to complete step 2 and step 3?? Thankyou so much. Esther
ESJY, b sure include a button (Command1) on your form. not sure wat step 3 is about.. Option Explicit Option Base 1 '//start array at index 1 Option Compare Text Private vArray() As Variant '//array of variants - can b specified Private Sub Command1_Click() Dim vVariable1 As Variant 'Dim iFile As Integer Dim i As Integer Open "c:\sample.txt" For Input As #1 'iFile While Not EOF(1) Input #1, vVariable1 If (vVariable1 Like "*Entities*") Then i = i + 1 ReDim Preserve vArray(i) As Variant vArray(i) = vVariable1 MsgBox vArray(i) End If Wend Close #1 'iFile End Sub :rose::rose:
-
ESJY, b sure include a button (Command1) on your form. not sure wat step 3 is about.. Option Explicit Option Base 1 '//start array at index 1 Option Compare Text Private vArray() As Variant '//array of variants - can b specified Private Sub Command1_Click() Dim vVariable1 As Variant 'Dim iFile As Integer Dim i As Integer Open "c:\sample.txt" For Input As #1 'iFile While Not EOF(1) Input #1, vVariable1 If (vVariable1 Like "*Entities*") Then i = i + 1 ReDim Preserve vArray(i) As Variant vArray(i) = vVariable1 MsgBox vArray(i) End If Wend Close #1 'iFile End Sub :rose::rose:
-
thanks kamush, that really helps... how many variable can be stored in the array?? because the file to be loaded is a very large file and therefore there is quite a number of variables to be read into the array.
Hi ESJY, an array is jus memory space, so it can take quite alot but slows down your app, right? wat do u want the array for? u could read 5 lines after the keyword n display it (or whatever u wanna do). jus depends on wat u want Esther.. While Not EOF(1) Line Input #1, vVariable1 '//reads whole line If (vVariable1 Like "*Entities*") Then i = i + 1 if (i=5) then i=1 ReDim vArray(i) As Variant '//reset array wit 1 item.. else ReDim Preserve vArray(i) As Variant end if vArray(i) = vVariable1 ListBox1.AddItem vArray(i) End If Wend :rose::rose:
-
Hi ESJY, an array is jus memory space, so it can take quite alot but slows down your app, right? wat do u want the array for? u could read 5 lines after the keyword n display it (or whatever u wanna do). jus depends on wat u want Esther.. While Not EOF(1) Line Input #1, vVariable1 '//reads whole line If (vVariable1 Like "*Entities*") Then i = i + 1 if (i=5) then i=1 ReDim vArray(i) As Variant '//reset array wit 1 item.. else ReDim Preserve vArray(i) As Variant end if vArray(i) = vVariable1 ListBox1.AddItem vArray(i) End If Wend :rose::rose: