locked
I need some help with a project... RRS feed

  • Question

  • Im doing a project and I got asked a question that Im stumped on. Can anyone help me. The question is:

    write a script that creates a file the script should

    a) Ask for a folder name

    b) Ask for filename

    c)if the folder already exsists delete it

    d) ask for text from the keyboard to write the file

    e)write the text to file

    f) save and close the file

     

    if you know the code i need can you please help. cheers.

    Thursday, April 29, 2010 11:53 AM

Answers

  • Is this for a class?  Have you tried searching this forum for the answers to your 6 questions?

    Hint to get you started:  SaveFileDialog

    :)


    Doug

    SEARCH ... then ask
    • Proposed as answer by Cor Ligthert Thursday, April 29, 2010 3:21 PM
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Thursday, April 29, 2010 12:14 PM
  • rory,

    this will help also

    a) Ask for a folder name

        folderbrowserdialog (save file dialog may have a new folder option as well)

    b) Ask for filename

        input box, form with textbox and labels, or savefiledialog

    c)if the folder already exsists delete it

        io.directory.exists and io.directory.delete

    d) ask for text from the keyboard to write the file

        again, some kind of entry (input box, form with text entry control, etc...)

    e)write the text to file

        io.streamwriter

    f) save and close the file

       io.streamwriter  and close whatever you have used to allow the user to enter the text with


    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    • Proposed as answer by Cor Ligthert Thursday, April 29, 2010 3:21 PM
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Thursday, April 29, 2010 2:24 PM
  • Hello rorygb,
    Thanks for your post.
    The following is the relative code for implement according to my understanding which could be as a suppliment to the above replies. I hope it helpful.
    a)Ask for a folder name
    c)if the folder already exsists delete it
    First, input the fold you want to open into TextBox1. Then click Button1. If the folder already exsists, delete it. Else open the fold.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
           
            If System.IO.Directory.Exists(TextBox1.Text) = False Then
                System.IO.Directory.CreateDirectory(TextBox1.Text)
                MessageBox.Show("create a new folder")
            Else
                System.IO.Directory.Delete(TextBox1.Text)
                MessageBox.Show("delete an exist folder")
            End If

    End Sub

    b)Ask for a filename
    d)ask for text from the keyboard to write the file
    e)write the text to file
    f) save and close the file
    First, input the filename into TextBox2. Then click Button2 open this file(if the file exists). Click Button3 write the text to the file. At last save and close the file.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim Str As String
            Str = TextBox2.Text
            If File.Exists(Str) Then
                System.Diagnostics.Process.Start(Str)
            Else
                MsgBox("sorry ,the file is  not exists!")
            End If
          
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim sw As StreamWriter = New StreamWriter(TextBox2.Text)
            '   Add   some   text   to   the   file.  
            sw.Write("This   is   the   ")
            sw.WriteLine("header   for   the   file.")       
            sw.Close()     

    End Sub

    If you have any problems, please feel free to contact me.
    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Tuesday, May 4, 2010 5:22 AM

All replies

  • Is this for a class?  Have you tried searching this forum for the answers to your 6 questions?

    Hint to get you started:  SaveFileDialog

    :)


    Doug

    SEARCH ... then ask
    • Proposed as answer by Cor Ligthert Thursday, April 29, 2010 3:21 PM
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Thursday, April 29, 2010 12:14 PM
  • rory,

    this will help also

    a) Ask for a folder name

        folderbrowserdialog (save file dialog may have a new folder option as well)

    b) Ask for filename

        input box, form with textbox and labels, or savefiledialog

    c)if the folder already exsists delete it

        io.directory.exists and io.directory.delete

    d) ask for text from the keyboard to write the file

        again, some kind of entry (input box, form with text entry control, etc...)

    e)write the text to file

        io.streamwriter

    f) save and close the file

       io.streamwriter  and close whatever you have used to allow the user to enter the text with


    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    • Proposed as answer by Cor Ligthert Thursday, April 29, 2010 3:21 PM
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Thursday, April 29, 2010 2:24 PM
  • Hello rorygb,
    Thanks for your post.
    The following is the relative code for implement according to my understanding which could be as a suppliment to the above replies. I hope it helpful.
    a)Ask for a folder name
    c)if the folder already exsists delete it
    First, input the fold you want to open into TextBox1. Then click Button1. If the folder already exsists, delete it. Else open the fold.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
           
            If System.IO.Directory.Exists(TextBox1.Text) = False Then
                System.IO.Directory.CreateDirectory(TextBox1.Text)
                MessageBox.Show("create a new folder")
            Else
                System.IO.Directory.Delete(TextBox1.Text)
                MessageBox.Show("delete an exist folder")
            End If

    End Sub

    b)Ask for a filename
    d)ask for text from the keyboard to write the file
    e)write the text to file
    f) save and close the file
    First, input the filename into TextBox2. Then click Button2 open this file(if the file exists). Click Button3 write the text to the file. At last save and close the file.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim Str As String
            Str = TextBox2.Text
            If File.Exists(Str) Then
                System.Diagnostics.Process.Start(Str)
            Else
                MsgBox("sorry ,the file is  not exists!")
            End If
          
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim sw As StreamWriter = New StreamWriter(TextBox2.Text)
            '   Add   some   text   to   the   file.  
            sw.Write("This   is   the   ")
            sw.WriteLine("header   for   the   file.")       
            sw.Close()     

    End Sub

    If you have any problems, please feel free to contact me.
    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Wednesday, May 5, 2010 8:56 AM
    Tuesday, May 4, 2010 5:22 AM