Automatically Creating a text file, and Refreshing a form

I have a program that uses a text file to write data to. I want to know if I can make my program automatically create a folder with a text file in it.

psuedocode

Open Webpages.txt
If webpages.txt is not found
Create folder C:Webpage ManagerWebpages.txt
Restart Program

Which brings up another point. How do I make my program restart so that all new data added to this text file in run time is added to the combo box.

psuedocode
Ask for webpage input
add file to webpages.txt
refresh/restart program

Comments

  • alright...ill try to answer this one... try this code:

    [code]
    On Local Error Goto NoExist
    Open "[red]Drive:Folder[/red]webpages.txt" For Input as #1
    Close

    Exit Sub
    MakeFile:
    On Local Error Resume Next
    MkDir "[red]Drive:Folder[/red]" [green]'Create the folder[/green]
    Open "[red]Drive:Folder[/red]webpages.txt" For Output as #2 [green]'Create the file[/green]
    [green]'Add anything you want webpages.txt to start with here...if anything[/green]
    Close

    Exit Sub
    NoExist:
    Resume MakeFile
    [/code]

    This will check for the file and if it doesnt exist create the folder and the file. Of course you need to put in your own path in place of "[red]Drive:Folder[/red]. Good luck

    As for 'Refreshing' the form...im not sure what you need to accomplish by this, but it should be easy to do..just null all variables etc...

    [hr]

    : I have a program that uses a text file to write data to. I want to know if I can make my program automatically create a folder with a text file in it.
    :
    : psuedocode
    :
    : Open Webpages.txt
    : If webpages.txt is not found
    : Create folder C:Webpage ManagerWebpages.txt
    : Restart Program
    :
    : Which brings up another point. How do I make my program restart so that all new data added to this text file in run time is added to the combo box.
    :
    : psuedocode
    : Ask for webpage input
    : add file to webpages.txt
    : refresh/restart program
    :
    :


  • [HR]
    [green]Thank you thank you thank you!!!!![/green] It worked like a charm. But I dunno what ya mean by nulling the variables. Can anyone tell me how to do this or how to restart/reload/refresh the program so that the new data comes up in the combo box!!!
    [HR]
  • [b][red]This message was edited by VB5begginner at 2002-8-2 12:13:36[/red][/b][hr]

    alright...to refresh a form there are a lot of options that you have...depending on what you need to do and how you have your program set up...one of the easiest ways is using the Dim statement to make a new form of the current form...for example...if your form's name is Form1 then you can use the code:
    [code]Dim RefreshForm As New Form1[/code]
    and then simply:
    [code]RefreshForm.Show
    Unload Form1[/code]
    To Show the "refreshed" form and unload the old one

    but to do this you will have to make sure that all of the information in the form uses [b]Me[/b] instead of [b]Form1[/b] to refer to itself...(I would think, though I'm not [italic]sure[/italic])...you would also not be able to refer to the form from other forms without further programming...you could try a [b]ReDim[/b] statement to try to ReDim RefreshForm as Form1...though I have no clue whether a statement like that would work or not...

    probably the [b]safest[/b] way to do it would be to make another form JUST for the process of unloading/reloading the form you need to...for example...make a new form and call it ReloadForm1...then put a timer in it and set the timer to oh say 2000 milliseconds to be safe...then in the Timer1_Timer sub add the following code:
    [code]On Local Error Goto FormNotUnloaded
    Form1.Show
    Unload Me
    FormNotUnloaded:[/code]
    and make sure the Timer [b]IS[/b] enabled...then whenever you want to refresh [italic]Form1[/italic] just add this code in Form1:
    [code]ReloadForm1.show
    Unload Me[/code]
    that should work...

    PS: The reason for putting the ReloadForm1 code in a Timer rather than in the Form_Load sub is that the form may not have a chance to completely unload before it loads, and this could cause an Error...putting it in a timer just gives it time to unload..

    hope that helps!

    :
    : [HR]
    : [green]Thank you thank you thank you!!!!![/green] It worked like a charm. But I dunno what ya mean by nulling the variables. Can anyone tell me how to do this or how to restart/reload/refresh the program so that the new data comes up in the combo box!!!
    : [HR]
    :







Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories