Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help with StreamReader

Help with StreamReader

Scheduled Pinned Locked Moved Visual Basic
help
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad
    wrote on last edited by
    #1

    Been coding for about 3 months now and am currently making a "login" client for myself. I hve created a streamreader and have linked it to a .txt file which is located on my hardrive and i am struggling to get it to read of multiple lines so i can have more than one user. This is the code i have at the moment Public Class Form1 Dim webe As New ProcessStartInfo() Dim username1 As New IO.StreamReader("C:\Textfile.txt") Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click If Username.Text & Password.Text = username1.ReadToEnd & "lol" Or Username.Text & Password.Text = "Admin" & "admin" Then StatusStrip.Text = "Welcome " & Username.Text Thanks In Advance

    J 1 Reply Last reply
    0
    • B Brad

      Been coding for about 3 months now and am currently making a "login" client for myself. I hve created a streamreader and have linked it to a .txt file which is located on my hardrive and i am struggling to get it to read of multiple lines so i can have more than one user. This is the code i have at the moment Public Class Form1 Dim webe As New ProcessStartInfo() Dim username1 As New IO.StreamReader("C:\Textfile.txt") Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click If Username.Text & Password.Text = username1.ReadToEnd & "lol" Or Username.Text & Password.Text = "Admin" & "admin" Then StatusStrip.Text = "Welcome " & Username.Text Thanks In Advance

      J Offline
      J Offline
      JUNEYT
      wrote on last edited by
      #2

      Text file suppose to have more than one record there fore you should read the values inside a loop. Please see example below. The shown code sample below suppse to be inside Login_Click procedure :wtf:

      Dim webe As New ProcessStartInfo()
      Dim username1 As New IO.StreamReader("C:\Textfile.txt")
      
      Do While NOT UserName.EndOfStream
         If UserName1.ReadLine() = UserName.Text.toString & PassWord.Text.ToString Then
            'login information exist perform some type of actions
            exit do
         ElseIf UserName.Text & PassWord.Text = "Admin" & "admin" Then
            StatusStrip.text = "WelCome" & userName.Text
         End IF
      Loop
      UserName1.Close()
      

      -- modified at 12:28 Monday 19th March, 2007

      What a curious mind needs to discover knowledge is noting else than a pin-hole.

      B 2 Replies Last reply
      0
      • J JUNEYT

        Text file suppose to have more than one record there fore you should read the values inside a loop. Please see example below. The shown code sample below suppse to be inside Login_Click procedure :wtf:

        Dim webe As New ProcessStartInfo()
        Dim username1 As New IO.StreamReader("C:\Textfile.txt")
        
        Do While NOT UserName.EndOfStream
           If UserName1.ReadLine() = UserName.Text.toString & PassWord.Text.ToString Then
              'login information exist perform some type of actions
              exit do
           ElseIf UserName.Text & PassWord.Text = "Admin" & "admin" Then
              StatusStrip.text = "WelCome" & userName.Text
           End IF
        Loop
        UserName1.Close()
        

        -- modified at 12:28 Monday 19th March, 2007

        What a curious mind needs to discover knowledge is noting else than a pin-hole.

        B Offline
        B Offline
        Brad
        wrote on last edited by
        #3

        I added in your code and i seen to be getting this error under the "Username.EndOfReader" 'EndofReader is not a members of the windows.form.textbox' Another expection i am getting is the "exit loop" is thrwoing an exception, 'exit must be followed by sub, function, property etc etc etc' I have tried to play about with it but still struggling with working it out.

        J 1 Reply Last reply
        0
        • B Brad

          I added in your code and i seen to be getting this error under the "Username.EndOfReader" 'EndofReader is not a members of the windows.form.textbox' Another expection i am getting is the "exit loop" is thrwoing an exception, 'exit must be followed by sub, function, property etc etc etc' I have tried to play about with it but still struggling with working it out.

          J Offline
          J Offline
          JUNEYT
          wrote on last edited by
          #4

          Sorry my mistake... Convert .text.toString and then use exit do also Replace EndOfReader with EndOfStream... I apologize... :doh:

          What a curious mind needs to discover knowledge is noting else than a pin-hole.

          B 1 Reply Last reply
          0
          • J JUNEYT

            Sorry my mistake... Convert .text.toString and then use exit do also Replace EndOfReader with EndOfStream... I apologize... :doh:

            What a curious mind needs to discover knowledge is noting else than a pin-hole.

            B Offline
            B Offline
            Brad
            wrote on last edited by
            #5

            Perfect....Cheers

            1 Reply Last reply
            0
            • J JUNEYT

              Text file suppose to have more than one record there fore you should read the values inside a loop. Please see example below. The shown code sample below suppse to be inside Login_Click procedure :wtf:

              Dim webe As New ProcessStartInfo()
              Dim username1 As New IO.StreamReader("C:\Textfile.txt")
              
              Do While NOT UserName.EndOfStream
                 If UserName1.ReadLine() = UserName.Text.toString & PassWord.Text.ToString Then
                    'login information exist perform some type of actions
                    exit do
                 ElseIf UserName.Text & PassWord.Text = "Admin" & "admin" Then
                    StatusStrip.text = "WelCome" & userName.Text
                 End IF
              Loop
              UserName1.Close()
              

              -- modified at 12:28 Monday 19th March, 2007

              What a curious mind needs to discover knowledge is noting else than a pin-hole.

              B Offline
              B Offline
              Brad
              wrote on last edited by
              #6

              JUNETY or anyone else, i have just had to format my pc and when i load up VS05 and my code i keep getting this error when debuging it, i have looked everywhere but it is really baffling me! any help will be appreciated! Dim username1 As New IO.StreamReader("C:\username.txt") Dim password1 As New IO.StreamReader("C:\password.txt") Dim adminun As New IO.StreamReader("C:\adminun.txt") Dim adminpw As New IO.StreamReader("C:\adminpw.txt") Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click Do While username1.EndOfStream If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then Exit Do End If Loop username1.Close() Do While password1.EndOfStream If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then Exit Do End If Loop password1.Close() End Sub ERROR: System.ObjectDisposedException was unhandled Message="Cannot read from a closed TextReader." ObjectName="" Source="mscorlib" StackTrace: at System.IO.__Error.ReaderClosed() at System.IO.StreamReader.get_EndOfStream() at WindowsApplication1.Form1.Login_Click(Object sender, EventArgs e) in C:\Users\Brad\Documents\Visual Studio 2005\Projects\SC Login\SC Login\Form1.vb:line 9 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(I

              J 1 Reply Last reply
              0
              • B Brad

                JUNETY or anyone else, i have just had to format my pc and when i load up VS05 and my code i keep getting this error when debuging it, i have looked everywhere but it is really baffling me! any help will be appreciated! Dim username1 As New IO.StreamReader("C:\username.txt") Dim password1 As New IO.StreamReader("C:\password.txt") Dim adminun As New IO.StreamReader("C:\adminun.txt") Dim adminpw As New IO.StreamReader("C:\adminpw.txt") Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click Do While username1.EndOfStream If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then Exit Do End If Loop username1.Close() Do While password1.EndOfStream If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then Exit Do End If Loop password1.Close() End Sub ERROR: System.ObjectDisposedException was unhandled Message="Cannot read from a closed TextReader." ObjectName="" Source="mscorlib" StackTrace: at System.IO.__Error.ReaderClosed() at System.IO.StreamReader.get_EndOfStream() at WindowsApplication1.Form1.Login_Click(Object sender, EventArgs e) in C:\Users\Brad\Documents\Visual Studio 2005\Projects\SC Login\SC Login\Form1.vb:line 9 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(I

                J Offline
                J Offline
                JUNEYT
                wrote on last edited by
                #7

                Because you are making a mistake as follows: When you close the first stream therefore without reopening it you can't define UserName1 inside the second stream because its closed. Your approach to check username, password, etc. seems not appripriate. I suggest you to reorganize your code. :wtf:

                What a curious mind needs to discover knowledge is noting else than a pin-hole.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups