simple help i think..

Discussion in 'Programming General' started by trumiz, Jan 10, 2008.

simple help i think..
  1. Unread #1 - Jan 10, 2008 at 7:33 AM
  2. trumiz
    Joined:
    Mar 20, 2007
    Posts:
    243
    Referrals:
    0
    Sythe Gold:
    0

    trumiz Active Member

    simple help i think..

    well i'm in the process of creating a simple guess the number game but the problem i'm having is writing to a file i don't know the code :$

    i'v got 2 cases where i need to use this, for a log in where the user can create there own username and password and for the highscores so the user can enter there name and score.

    if anyone can help that will be great and if you want me to post the code i currently have for both those i can do

    thanks :)

    ow iv got it so the information can be retrieved from the file so that it is displayed and i can log in but not that i can created my own password and username without actually going the the file and adding the information in there, if that helps anymore :$
     
  3. Unread #2 - Jan 24, 2008 at 2:34 AM
  4. hmm
    Joined:
    Jan 21, 2007
    Posts:
    181
    Referrals:
    2
    Sythe Gold:
    5

    hmm Active Member

    simple help i think..

    youre wanting to read and write a textfile?

    open a file
    Code:
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim sr As IO.StreamReader = New IO.StreamReader(OpenFileDialog1.FileName)
                While sr.Peek >= 0 ' or sr.endofstream=false
                   ListView1.Items.Add(sr.ReadLine) 'will add the txt to a listview. 
    'textbox1.text = split(split(sr.readline, "[User:")(1), "]") ' assuming you have "[User:BOB]" in a txt, it will load it..
    'note the split can be used in listview if needed 'ListView1.Items.Add(split(split(sr.readline, "[User:")(1), "]") ) 
                End While
      sr.Close()
            End If      
    
    save
    Code:
    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim sw As IO.StreamWriter = New IO.StreamWriter(SaveFileDialog1.FileName)
                For i As Integer = 0 To ListView1.Items.Count - 1
                    If i = ListView1.Items.Count - 1 Then
                        sw.Write(ListView1.Items(i).Text)
    'could add it to save username, etc ' sw.Write("[User:" & ListView1.Items(i).Text & "]")
                    Else
                        sw.WriteLine(ListView1.Items(i).Text)
    'here too..' sw.WriteLine("[User:" & ListView1.Items(i).Text & "]")
                    End If
                Next
                sw.Close()
            End If
    
    or save from textbox..
    Code:
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim sw As IO.StreamWriter = New IO.StreamWriter(SaveFileDialog1.FileName)
                For i As Integer = 0 To ListView1.Items.Count - 1
                    If i = ListView1.Items.Count - 1 Then
                        sw.Write(textbox1.Text)
                        'could add it to save username, etc ' sw.Write("[User:" & textbox1.Text  & "]")
                    Else
                        sw.WriteLine(textbox1.Text)
                        'here too..' sw.WriteLine("[User:" & textbox1.Text & "]")
                    End If
                Next
                sw.Close()
            End If
        End Sub
    
    i think that covers the examples i was trying to give..and obviously if your not using openfiledialog or savefiledialog, just remove the following:
    Code:
     If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    end if
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    end if
    
     
< Help me please | Help me please >

Users viewing this thread
1 guest


 
 
Adblock breaks this site