3 Replies - 647 Views - Last Post: 29 January 2013 - 02:41 PM Rate Topic: -----

#1 kcorj2244  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-January 13

Need Help Deleting A File, and Something Else

Posted 29 January 2013 - 02:03 PM

Ok, I'm currently in programming 1 in high school so don't make fun of my knowledge of vb.net. Ok, so first of all, this isn't for an assignment or anything like that.

I need help deleting a file when I click a button. Currently I am having all the things I type in an input box, saved to a text file. (I also need help with the code to create the text file, currently it just looks for the file and appends it each time). So basically, I want to be able to click a button and have the saved file delete itself. Is this possible?

The other thing I need help with is enabling a part of my code, by using a seperate form. Right now, in my code for the MainForm, I have it so when I click the button it opens a input box and everything I type is saved. Is there a way I can on a seperate form enable whether or not I want saving enabled? I'm writing to the file using steamwriter atm.


Thanks :P

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help Deleting A File, and Something Else

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8940
  • View blog
  • Posts: 33,531
  • Joined: 12-June 08

Re: Need Help Deleting A File, and Something Else

Posted 29 January 2013 - 02:13 PM

Quote

I need help deleting a file when I click a button.
...
So basically, I want to be able to click a button and have the saved file delete itself. Is this possible?


Yes this is possible.

system.io.file.delete seems to work pretty well.
http://msdn.microsof...em.io.file.aspx


Quote

I also need help with the code to create the text file, currently it just looks for the file and appends it each time

Streamwriter works pretty well for that.

http://msdn.microsof...reamwriter.aspx


Quote

The other thing I need help with is enabling a part of my code, by using a seperate form. Right now, in my code for the MainForm, I have it so when I click the button it opens a input box and everything I type is saved. Is there a way I can on a seperate form enable whether or not I want saving enabled?

Like a properties form? Yes... Forms are objects and you can pull values from forms through a property or a return method of a function. You then can save that value in a text file, or in the My.Settings, or even a database - to be retrieved later.
Was This Post Helpful? 0
  • +
  • -

#3 kcorj2244  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-January 13

Re: Need Help Deleting A File, and Something Else

Posted 29 January 2013 - 02:34 PM

View Postmodi123_1, on 29 January 2013 - 02:13 PM, said:

Quote

I need help deleting a file when I click a button.
...
So basically, I want to be able to click a button and have the saved file delete itself. Is this possible?


Yes this is possible.

system.io.file.delete seems to work pretty well.
http://msdn.microsof...em.io.file.aspx


Quote

I also need help with the code to create the text file, currently it just looks for the file and appends it each time

Streamwriter works pretty well for that.

http://msdn.microsof...reamwriter.aspx


Quote

The other thing I need help with is enabling a part of my code, by using a seperate form. Right now, in my code for the MainForm, I have it so when I click the button it opens a input box and everything I type is saved. Is there a way I can on a seperate form enable whether or not I want saving enabled?

Like a properties form? Yes... Forms are objects and you can pull values from forms through a property or a return method of a function. You then can save that value in a text file, or in the My.Settings, or even a database - to be retrieved later.


Alright. I don't really know too much about function
s in vb.net. Could you show me an example of using a button click on another form to enable a function/disable a function?

That would be awesome :D
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8940
  • View blog
  • Posts: 33,531
  • Joined: 12-June 08

Re: Need Help Deleting A File, and Something Else

Posted 29 January 2013 - 02:41 PM

Perhaps we should just start with what is a function and what is a subroutine..

    Public Sub main()
        '-- the function Foo returns a value.. which 'debug.writeline' catches and prints out.
        Debug.WriteLine(Foo)
        '-- bar is a subroutine.. it doesn't return a value so the writing has to be done inside the method.
        Bar()
    End Sub

    Public Function Foo() As String
        Return "abc"
    End Function
    Public Sub Bar()
        Debug.WriteLine("abc")
    End Sub



Here's an example.. we have two classes.. a dog class and a flea class. The dog class creates, and instantiates, the flea class. It then pulls data from that completely different object with a property and even a function.

Having two windows forms is no different. Your first form is an object as is your second.. The first needs to instantiate the second... and the first can pull values from the second with functions or properties. (well.. and events as well but I think that is going to be way over your head.)

Sub Main()
Dim oo As New Dog_Form
end sub


Public Class Dog_Form
    '-- variables
    Private _oFlea As Flea_Form '-- declare object of type 'flea' that is inside 'dog'.
    Public Sub New()
        _oFlea = New Flea_Form '-- instantiate the object

        Console.WriteLine(_oFlea.GetBabies)
        Console.WriteLine(_oFlea.MakeMoreBabies)
    End Sub
End Class

Public Class Flea_Form
    Private _lBabies As Int32 = 0 '-- how many babies the flea has

    '-- a property to get how many babies there are currently
    Public ReadOnly Property GetBabies As Int32
        Get
            Return _lBabies
        End Get
    End Property

    '-- constructor
    Public Sub New()
        _lBabies = 1 '-- set default number of babies
    End Sub

    '-- function that multiples the current number of babies, retains it, and returns how many babies there are now
    Public Function MakeMoreBabies() As Int32
        _lBabies *= 3
        Return _lBabies
    End Function
End Class


This post has been edited by modi123_1: 29 January 2013 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1