2015-01-15 2 views
-1

VB6에서 열린 txt 파일에서 특정 문자열을 선택하는 방법을 찾으려고합니다. 이미 파일을 열어서 변수에 할당했습니다 (제대로 작동하는지 확실하지 않음). 열린 txt 파일에는 관련성이없는 다른 정보도 포함되므로 관련 정보로 새 파일을 만들 필요가 있습니다. 내가 가지가 있지만 매우 좋지 않아, 알고리즘의 일종을 썼다 : Ptxt 파일에서 특정 문자열 선택 VB6

'READ Line 01 
'REPEAT 
    'IF line begins with "studentname=" then 
     'Copy to new textbox, in new textbox/variable create new line 
    'ELSE If line begins with "studentID=" 
     'Copy to new textbox, in new textbox/variable create 2 new lines 
    'ENDIF 
    'READ next line 
'UNTIL end of text is reached 

사람이 내가 이것을 달성 할 수있는 방법을 알고 있나요? 감사

+1

이 검토하시기 바랍니다 *주의 * : 각 부분이 무엇을하고 있는지 설명 할 수, 응답에 대한 – Plutonix

답변

3

이 귀하의 질문에 대한 예제 코드입니다 :

Filename$="myfilename.txt"  'This row assigns to variable Filename$ 
           'the name of your file, example: 
           '"myfilename.txt" 

Open Filename$ For Input As #1 'This row opens the file Filename$ 

    Do While Not EOF(1)   'This row inits the loop to read all 
           'lines in your file and loop ends when 
           'there is not others lines to read 

    Line Input #1, line$   'This row inserts on variable line$ a 
           'line of your file 

    If mid(line$,1,12)="studentname=" then 'In this row the command mid 
              ' extracts the first 12 chars 
              'of line and verify if is 
              'equal to "studentname=" 

    Text1.Text=mid(line$,13)  'Is equal? Then In this line mid 
           'extracts from 13° char 
           'to last char and set it on Text1 

    ElseIf mid(line$,1,10)="studentID=" then 'Is not equal to 
              ' "studentname="? Then 
              ' verify if the first 10 
              ' chars are equals to 
              ' "studentID=" 

    Text2.Text=mid(line$,11)  'Is equal? Then In this line mid 
           'extracts from 11° char 
           'to last char and set it on Text2 

    '... You can insert others ElseIf conditions 

    End If       

    Loop      'Loop 

Close #1      'This row closes file 
+0

감사합니다 [질문] 내 코드로 어떻게 활용할 수 있습니까? 다시 감사합니다 –

+0

나는 대답을 편집, 나는 도움이 essert 도움이됩니다. – Mailkov

+0

감사합니다. 정말 도움이되었습니다. –

관련 문제