VB6 Small Backup Program

Discussion in 'Visual Basic [VB]' started by Darkness1337, May 28, 2008.

  1. Darkness1337

    Darkness1337 New Member

    Joined:
    Mar 15, 2007
    Messages:
    130
    Likes Received:
    1
    Trophy Points:
    0
    Been away for long time so just decided to make a little tutorial about file handling, I'll make it a clear as possible however if it's not clear then just pm me :)

    Background



    Little tutorial about file handling :) this is something that i did for my course work...

    In this tutorial i will tell u how to make a small back up program to back up a text document some of you may already know this but hope this will help someone*

    lets go step by step!

    get ready :

    1. open VB
    2. New project [don't do anything, yet]
    3. Save the project in a folder [make a folder on your desktop name it "backup_program"and save it there for easy access]
    4. make a folder there [name it "original"]
    5. make another folder [name it "backup]

    [​IMG]

    Screenshot above shows what it should look lyk after you create them folders...

    6. rite, now you need a text file in this example i am using "example.txt", thats the file we going to back up]

    7. open notepad and type in some random stuff and then save it in the "original" folder.

    [​IMG]

    8. open the VB project you just saved lets get down to making our superb interface!

    [​IMG]

    thats what it should look like!

    two command buttons

    1
    name : cmdCheck
    caption : CheckForTheFile
    2
    name : cmdBackUp
    caption : BackupFile

    9. now double click on the CheckForFile command button to start coding there are many ways to check if the files there... i am going to use DIR$

    so,

    first declare a variable
    Dim FileCheck as string

    and then you can use that variable to check the file availability

    basically you telling the program to look in "original" directory for the file called "example.txt"

    FileCheck = Dir$("original/example.txt")

    and then if the file is not there, FileCheck value will be blank! if it is there then the FileCheck value will be equal to file name... therefore if the file is there the value of FileCheck will be equal to "example.txt" :)

    we could could use that to check if the files present!

    to do that we could make a IF statement

    Code:
    if FileCheck = "example.txt" then 
    	msgbox "File Found"
    else
    	msgbox "File Not Found"
    end if
    
    or we could say:

    Code:
    if FileCheck <> "" then
    	msgbox "File Found"
    else
    	msgbox "File Not Found"
    end if
    
    either of them will work,,...

    now check if it works...

    if you get the message box saying "File Found" then your good to go...

    ...............

    now we could get down to coding our second button :BackUpFile: get to the code window

    now we know the file is there so we could make the backup now.. here we are using FileCopy method to copy the file to the "backup" directory

    simple:

    when you type in FileCopy VB will tell you what you have to type in there!

    FileCopy "original/example.txt", "backup/exampleBackUp.txt"

    right on here we could add date so we know what date that files been backed up all you have to do is put Date$ in middle

    FileCopy "original/example.txt", "backup/exampleBackUp" Date$ ".txt"

    The code



    A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.

    Blocks of code should be set as style "Formatted" like this.
    Code:
    Private Sub cmdBackUp_Click()
    	FileCopy "original/example.txt", "backup/example" & Date$ & ".txt"
    	MsgBox "Backup Complete!!"
    End Sub
    
    Private Sub cmdCheck_Click()
    	Dim FileCheck As String
    	FileCheck = Dir$("original/example.txt")
    	If FileCheck <> "" Then
    		MsgBox "File Found"
    	Else
    		MsgBox "File Not Found"
    	End If
    End Sub
    
    thats what the code look like :D

    [​IMG]

    there is our backed up file :D

    hope that helped!!!

    References



    http://www.vbexplorer.com/VBExplorer/vb_feature/may2000/may2000.asp
     
    Last edited by a moderator: Jan 21, 2017
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  3. Dak914

    Dak914 Member

    Joined:
    May 3, 2008
    Messages:
    48
    Likes Received:
    5
    Trophy Points:
    8
    Two things:
    1) Yeah, So much for the whole "I dont care about article of the month"! :)
    2) Why would you bash me when you have a whole lot more you could be doing. Obviously, you know what you are talking about with VB programs. It isnt all that hard to see.
    3) (extra message) I see that the whole slang language is just a one-time-lazy type thing. :crazy:
    I hate being bashed, and, since we both know what we are talking about, why not be fair to each other. :undecided
    Well that is all I have to say.
    ~3xistanc3
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Can you quote the reference of your post
     
  5. Darkness1337

    Darkness1337 New Member

    Joined:
    Mar 15, 2007
    Messages:
    130
    Likes Received:
    1
    Trophy Points:
    0
    Last edited: Jun 13, 2008
  6. Dak914

    Dak914 Member

    Joined:
    May 3, 2008
    Messages:
    48
    Likes Received:
    5
    Trophy Points:
    8
    The referrence is "Change the admin password the easy way..." I posted a while back.
     
  7. MartinJose

    MartinJose New Member

    Joined:
    Aug 17, 2010
    Messages:
    55
    Likes Received:
    1
    Trophy Points:
    0
    Home Page:
    http://www.comm100.com/emailmarketingnewsletter/
    It's a easy and useful tool. I wiill go and make one.
     
  8. Full Zip Hoody

    Full Zip Hoody New Member

    Joined:
    Sep 29, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programer
    Location:
    US of A
    i just managed to do a small back up program which can back up a text document using your method above, thanks for the tut darkness
     
  9. mukeshsoftona

    mukeshsoftona Banned

    Joined:
    Oct 28, 2011
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    Hi dear.

    i never heard about it. This is very informative post.
     
    Last edited: Nov 11, 2011
  10. edwardallene

    edwardallene New Member

    Joined:
    Apr 16, 2012
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Home Page:
    http://shop.pchappy.com.au/
    I have a short course of VB in our school and learning this program makes me more knowledgeable somehow because when I have my interface and then one thing that I should do is to run the program. I haven't tried to back up my file using VB, your post is very informative and it is very useful. I would love to try this and save my file to this software. Hope you will post again about what you have learn in VB.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice