Hack Forums
[.NET] Saving to .txt giving me issues?? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Saving to .txt giving me issues?? (/showthread.php?tid=5557430)



Saving to .txt giving me issues?? - Gørilla - Feb 21, 2017

I keep getting this error whenever I am saving my listbox info to a .txt file for some reason..
Could anyone help me out? I've been screwin with it for a couple hours now.

https://gyazo.com/df41710a0ab0d21a08d06cf3dbcfbe84

Code for the saving button:

Code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Using ofd As New SaveFileDialog() With {.Filter = "Text Files|*.txt"}

            If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim sb As New StringBuilder()

                For Each item In ListBox1.Items
                    sb.AppendLine(item.ToString())
                Next

                IO.File.WriteAllText(ofd.FileName, sb.ToString())

                MessageBox.Show("Working proxies have been exported")
            End If
        End Using
    End Sub

Am I missing something here..? It's never given me this problem in any other programs I've used it in.


* - +Haze - Feb 21, 2017

ListBox1 is probably null, that's the issue


* - Gørilla - Feb 21, 2017

(Feb 21, 2017 05:50 PM)+Haze Wrote:  ListBox1 is probably null, that's the issue

How could it be null?

The saving option works fine when there's nothing in the tlist box. But once I have stuff in the list box it will not save.. It saves like 50% of it then gives an error, which I cannot find what that error is.)


* - Darrell - Feb 21, 2017

Will take a look at this soon for you.


* - Gørilla - Feb 21, 2017

(Feb 21, 2017 05:56 PM)apt-get Wrote:  Will take a look at this soon for you.

Sounds good. I'm not trying to be spoon fed, but I've been messing with it for about 4 hours now and no matter how I put it, I get the same error.

I'm assuming I'm getting something in my list box that is not being able to be saved.
Would anyone know how to only allow certain things in a list box?


* - redmoon90211 - Feb 21, 2017

you have a null string or object in the listbox


* - Gørilla - Feb 21, 2017

(Feb 21, 2017 05:59 PM)redmoon90211 Wrote:  you have a null string or object in the listbox

I am now trying to figure out how to remove only things that are not numbers or the ":" sign.


* - Gt403cyl - Feb 21, 2017

I'm not sure how to do it in .vb

But a try/catch in the save button with
Code
try
{
     if (!textbox1.text == null)
     {
         dostuff();
     }
     Else
     {

     }
}

catch (exception error)
{
     Messagebox.show("oops", error.ToString());
}



This can be simplified without the try/catch but meh you get the idea.

Just it's in c# so convert it as needed.


* - redmoon90211 - Feb 21, 2017

(Feb 21, 2017 06:00 PM)Gørilla Wrote:  I am now trying to figure out how to remove only things that are not numbers or the ":" sign.

Code
For Each item In ListBox1.Items
    If item IsNot Nothing Then
        sb.AppendLine(item.ToString())
    End If
Next



* - Gørilla - Feb 21, 2017

(Feb 21, 2017 06:08 PM)redmoon90211 Wrote:  
Code
For Each item In ListBox1.Items
    If item IsNot Nothing Then
        sb.AppendLine(item.ToString())
    End If
Next
Seem to get an error when I try to use this. It's because of the if statement.

(Feb 21, 2017 06:08 PM)Gt403cyl Wrote:  I'm not sure how to do it in .vb

But a try/catch in the save button with
Code
try
{
     if (!textbox1.text == null)
     {
         dostuff();
     }
     Else
     {

     }
}

catch (exception error)
{
     Messagebox.show("oops", error.ToString());
}



This can be simplified without the try/catch but meh you get the idea.

Just it's in c# so convert it as needed.

I'll see if I can convert this:)


* - Gt403cyl - Feb 21, 2017

There maybe errors (disclaimer lol on phone) but the you get the idea..

I didn't see you were using a listbox but should still work just replace as needed.


* - Gørilla - Feb 21, 2017

(Feb 21, 2017 06:18 PM)Gt403cyl Wrote:  There maybe errors (disclaimer lol on phone) but the you get the idea..

I didn't see you were using a listbox but should still work just replace as needed.

I'm trying to convert it but I want to keep numbers 0-9 in, periods, and semi colens and everything else is to be deleted.

Currently trying to use this on my start thread button:
Code
Dim i As Integer = 0
        Do While (ListBox1.Items.Count) - 1 >= i
            If String.IsNullOrEmpty(ListBox1.Items(i)) Then
                ListBox1.Items.Remove(ListBox1.Items(i))
                i -= 1
            End If
            i += 1
        Loop

Turns out I had my regex off a tad, and for some reason when using both threads at the same time it returns as null value, assuming it's conjoining some information some how. But spaced them out with a timer and fixed the problem.. It only took me 6 hours but damn it was worth the learning curve. Thanks for all the help guys.