Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. Names
  2.  
  3. HarryS1
  4. HarryS2
  5. HarryS3
  6.  
  7. Dim text As String = File.ReadAllText("names.txt")
  8. Dim index As Integer = text.IndexOf(HarryS)
  9.  
  10. If index >= 0 Then
  11. MessageBox.Show("Name Found")
  12.  
  13. Else
  14. MessageBox.Show("Name not found")
  15. End If
  16.  
  17. Try
  18. Dim text As String = vbCrLf & System.IO.File.ReadAllText("C:Tempnames.txt") & vbCrLf
  19. Dim index As Integer = text.IndexOf(vbCrLf & "HarryS2" & vbCrLf)
  20. If index >= 0 Then
  21. MessageBox.Show("Name Found")
  22. Else
  23. MessageBox.Show("Name not found")
  24. End If
  25. Catch ex As Exception
  26. MessageBox.Show("Exception found!" & vbCrLf & ex.ToString)
  27. End Try
  28.  
  29. Try
  30. FileOpen(1, "FilePath", OpenMode.Input, OpenAccess.Read, OpenShare.LockWrite)
  31. Dim found As Boolean = False
  32. While (EOF(1) = 0)
  33. Dim readData As String = LineInput(1)
  34. If readData = "HarryS" Then
  35. found = True
  36. Exit While
  37. End If
  38. End While
  39. If found = True Then
  40. MsgBox("Found")
  41. Else
  42. MsgBox("Not found")
  43. End If
  44. Catch ex As Exception
  45. MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
  46. Finally
  47. FileClose(1)
  48. End Try
  49.  
  50. Imports System
  51. Imports System.IO
  52. Imports System.Text
  53.  
  54. Public Class Test
  55.  
  56. Public Shared Sub Main()
  57. Dim path As String = "c:tempMyTest.txt"
  58.  
  59. Try
  60. If File.Exists(path) Then
  61. File.Delete(path)
  62. End If
  63.  
  64. Dim sw As StreamWriter = New StreamWriter(path)
  65. sw.WriteLine("This")
  66. sw.WriteLine("is some text")
  67. sw.WriteLine("to test")
  68. sw.WriteLine("Reading")
  69. sw.Close()
  70.  
  71. Dim sr As StreamReader = New StreamReader(path)
  72.  
  73. Do While sr.Peek() >= 0
  74. Console.WriteLine(sr.ReadLine())
  75. Loop
  76. sr.Close()
  77. Catch e As Exception
  78. Console.WriteLine("The process failed: {0}", e.ToString())
  79. End Try
  80. End Sub
  81. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement