Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to save the chosen file location to a .txt file and have it display in the textbox when the program loads again. It reads correctly from the file on loadup, but it won't save it to the file. There are no errors, just not working...Any help is greatly appreciated.

 

Dim ofDialog As New OpenFileDialog

       With ofDialog
           .InitialDirectory = "C:\Program Files\Programming\list.txt"
           .Filter = "textfiles|*.txt"

           If .ShowDialog = DialogResult.OK Then
           End If

       End With
       TextBox2.Text = ofDialog.FileName

       Dim SW As New IO.StreamWriter("location.txt")
       SW.Write(ofDialog.FileName)
       SW.Close()
[/Code]

 
 
In form1_load
 
[Code]
Dim str As String
       Dim sr As System.IO.StreamReader
       Dim prog As System.IO.File
       sr = prog.OpenText("location.txt")
       str = sr.ReadLine
       TextBox2.Text = str

It's not impossible, it's Inevitable.
Posted
In your form_load try adding a sr.close() at the end.

 

I added that, but it read fine from the file on form1_load anyway...It's not writing the chosen location from the browse button to the text file. I need it to overwrite what's already on the text file. I need to fix this coding:

 

Dim ofDialog As New OpenFileDialog

       With ofDialog
           .InitialDirectory = "C:\Program Files\Programming\list.txt"
           .Filter = "textfiles|*.txt"

           If .ShowDialog = DialogResult.OK Then
           End If

       End With
       TextBox2.Text = ofDialog.FileName

       Dim SW As New IO.StreamWriter("location.txt")
       SW.Write(ofDialog.FileName)
       SW.Close()

It's not impossible, it's Inevitable.
  • Administrators
Posted

try changing the saving code to

Dim ofDialog As New OpenFileDialog

       With ofDialog
           .InitialDirectory = "C:\Program Files\Programming\list.txt"
           .Filter = "textfiles|*.txt"

           If .ShowDialog = DialogResult.OK Then
           End If

       End With
       TextBox2.Text = ofDialog.FileName

       Dim SW As New IO.StreamWriter(Application.StartupPath & "\location.txt")
       SW.WriteLine(ofDialog.FileName)
       SW.Close()

and the load code to

Dim str As String
       Dim sr As System.IO.StreamReader
       Dim prog As System.IO.File
       sr = prog.OpenText(Application.StartupPath & "\location.txt")
       str = sr.ReadLine
       TextBox2.Text = str
       sr.Close

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

Since we're back onto this saving to file topic, I never did get that other one to work... Here's my situation:

 

I have a dropdown combobox that displays 6 server names. Then I have 3 textbox's. one for nickname, loginname, and password. Then I have a checkbox that if checked, it will save the nickname, loginname and password for each chosen server from the combobox to a .ini file. The login and everything works, but it's not saving the nickname, loginname, and password to the text file. There are no errors, it just won't save the info.

 

Here is all the coding...

 

Dim ini As New Org.Mentalis.Files.IniReader("settings.ini") -- in public class

IniReader.vb -- .ini reader file

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPath As String

       Dim Non00bs, DangerousGaming, Renstation, WiloServ, n00bstories, BCServ As String

       If TextBox1.Text = "" Then
           MessageBox.Show("You must enter a Nickname to connect to TeamSpeak.", "PureSc0pe's TeamSpeak Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           Exit Sub
       End If

       If TextBox2.Text = "" Then
           MessageBox.Show("You must enter a Login Name to connect to TeamSpeak.", "PureSc0pe's TeamSpeak Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           Exit Sub
       End If

       If TextBox3.Text = "" Then
           MessageBox.Show("You must enter a Password to connect to TeamSpeak.", "PureSc0pe's TeamSpeak Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           Exit Sub
       End If

       If ComboBox1.Text = "" Then
           MessageBox.Show("You must select a TeamSpeak Server.", "PureSc0pe's TeamSpeak Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           Exit Sub
       End If

       If ComboBox1.Text = "Non00bs" Then
           strPath = "teamspeak://209.120.238.21:8767?nickname=" & TextBox1.Text & "?loginname=" & TextBox2.Text & "?password=" & TextBox3.Text & "?channel=?channelpassword=?"
           System.Diagnostics.Process.Start("iexplore", strPath)
       End If

       If ComboBox1.Text = "DangerousGaming" Then
           strPath = "teamspeak://69.57.146.51:8772?nickname=" & TextBox1.Text & "?loginname=" & TextBox2.Text & "?password=" & TextBox3.Text & "?channel=?channelpassword=?"
           System.Diagnostics.Process.Start("iexplore", strPath)
       End If

       If ComboBox1.Text = "Renstation" Then
           strPath = "teamspeak://ts.renstation.net?nickname=" & TextBox1.Text & "?loginname=" & TextBox2.Text & "?password=" & TextBox3.Text & "?channel=?channelpassword=?"
           System.Diagnostics.Process.Start("iexplore", strPath)
       End If

       If ComboBox1.Text = "StormHosting" Then
           strPath = "teamspeak://69.93.71.130:8767?nickname=" & TextBox1.Text & "?loginname=" & TextBox2.Text & "?password=" & TextBox3.Text & "?channel=?channelpassword=?"
           System.Diagnostics.Process.Start("iexplore", strPath)
       End If

       If ComboBox1.Text = "n00bstories" Then
           strPath = "teamspeak://teamspeak.n00bstories.com?nickname=" & TextBox1.Text & "?loginname=" & TextBox2.Text & "?password=" & TextBox3.Text & "?channel=?channelpassword=?"
           System.Diagnostics.Process.Start("iexplore", strPath)
       End If

       If CheckBox1.Checked = True Then
           ini.Write(ComboBox1.SelectedItem.ToString, "NickName", TextBox1.Text)
           ini.Write(ComboBox1.SelectedItem.ToString, "LoginName", TextBox2.Text)
           ini.Write(ComboBox1.SelectedItem.ToString, "Password", TextBox3.Text)
       End If
End Sub

 

The file I need it to save to is "settings.ini" -- settings.ini is assembled like this:

 

[Non00bs]

NickName=

LoginName=

Password=

 

[DangerousGaming]

NickName=

LoginName=

Password=

 

[Renstation]

NickName=

LoginName=

Password=

 

[stormHosting]

NickName=

LoginName=

Password=

 

[n00bstories]

NickName=

LoginName=

Password=

 

[bCServ]

NickName=

LoginName=

Password=

Edited by PureSc0pe
It's not impossible, it's Inevitable.
  • Administrators
Posted

When you say it doesn't work what actually happens (or doesn't happen as the case may be). Does the file not get written out correctly?

If you step through the code in the debugger does it execute the 3 ini.Write statements?

Again you may be better off replacing the string "settings.txt" with Application.StartupPath & "\settings.txt" just to make sure it is always looking in the same place for the file.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

ok, changing that made it save it to the file, thanks. Now, I need to have something in form1_load to read. This had no errors, but it showed bugs when loading the program.

 

TextBox1.Text = ini.ReadString(ComboBox1.SelectedItem.ToString, "NickName")
       TextBox2.Text = ini.ReadString(ComboBox1.SelectedItem.ToString, "LoginName")
       TextBox3.Text = ini.ReadString(ComboBox1.SelectedItem.ToString, "Password")

It's not impossible, it's Inevitable.
Posted

Wait, I've figured it out! I moved what I just posted to the ComboBox and added this to the form1_load and it works great!

 

ComboBox1.DataSource = ini.GetSectionNames()

 

 

Thanks for all your help :D

It's not impossible, it's Inevitable.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...