Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic [VB] (http://www.go4expert.com/articles/visual-basic-tutorials/)
-   -   VB6 Small Backup Program (http://www.go4expert.com/articles/vb6-small-backup-program-t10875/)

Darkness1337 28May2008 20:01

VB6 Small Backup Program
 
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]

http://www.go4expert.com/images/arti...creenshot1.jpg

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.

http://www.go4expert.com/images/arti...p/example2.jpg

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

http://www.go4expert.com/images/arti...backup/ex3.jpg

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: VB

if FileCheck = "example.txt" then
    msgbox "File Found"
else
    msgbox "File Not Found"
end if

or we could say:

Code: VB

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: VB

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

http://www.go4expert.com/images/arti...backup/ex4.jpg

there is our backed up file :D

hope that helped!!!

References



http://www.vbexplorer.com/VBExplorer...00/may2000.asp

shabbir 2Jun2008 16:28

Re: VB6 Small Backup Program
 
Nomination for article of the month of May

Dak914 12Jun2008 20:03

Re: VB6 Small Backup Program
 
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

shabbir 12Jun2008 22:38

Re: VB6 Small Backup Program
 
Quote:

Originally Posted by Dak914
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

Can you quote the reference of your post

Darkness1337 13Jun2008 07:36

Re: VB6 Small Backup Program
 
waeva u say!

go bak to watching diehard4.0...
lolz

http://www.go4expert.com/showthread....7&page=2&pp=10

Dak914 13Jun2008 17:43

Re: VB6 Small Backup Program
 
The referrence is "Change the admin password the easy way..." I posted a while back.

MartinJose 31Aug2010 12:35

Re: VB6 Small Backup Program
 
It's a easy and useful tool. I wiill go and make one.

Full Zip Hoody 30Sep2010 08:58

Re: VB6 Small Backup Program
 
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

mukeshsoftona 11Nov2011 17:28

Re: VB6 Small Backup Program
 
Hi dear.

i never heard about it. This is very informative post.

edwardallene 17Apr2012 05:46

Re: VB6 Small Backup Program
 
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.


All times are GMT +5.5. The time now is 22:45.