27-12-17, 10:37 PM
ده كود لقرائة سطر في ملف تكست
الملف اسمه Boo.txt السطر مكتوب فيه open my file
انا مش عايز اقول له لو لقيت هذا السطر في السطر الاول او الثاني افعل كذا
انا عايز اقول له لو لقيت هذا السطر في اي مكان من ملف التكست افعل كذا
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objStreamReader As StreamReader
Dim strLine As String
'Pass the file path and the file name to the StreamReader constructor.
objStreamReader = New StreamReader("C:\Boo.txt")
'Read the first line of text.
strLine = objStreamReader.ReadLine
If strLine = "open my file" Then
MsgBox(strLine)
End If
'Continue to read until you reach the end of the file.
Do While Not strLine Is Nothing
'Write the line to the Console window.
Console.WriteLine(strLine)
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
'Close the file.
objStreamReader.Close()
Console.ReadLine()
End Sub
End Class
الملف اسمه Boo.txt السطر مكتوب فيه open my file
انا مش عايز اقول له لو لقيت هذا السطر في السطر الاول او الثاني افعل كذا
انا عايز اقول له لو لقيت هذا السطر في اي مكان من ملف التكست افعل كذا
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objStreamReader As StreamReader
Dim strLine As String
'Pass the file path and the file name to the StreamReader constructor.
objStreamReader = New StreamReader("C:\Boo.txt")
'Read the first line of text.
strLine = objStreamReader.ReadLine
If strLine = "open my file" Then
MsgBox(strLine)
End If
'Continue to read until you reach the end of the file.
Do While Not strLine Is Nothing
'Write the line to the Console window.
Console.WriteLine(strLine)
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
'Close the file.
objStreamReader.Close()
Console.ReadLine()
End Sub
End Class