Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper Coding?

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
THere's soemthing I just don't understand about programming (and this may sound stupid)... I can do the if's and else if's etc etc but I'm not sure how to write a series of commands to make something happen. Below, is code which deletes two files and then copies two files in their place. Can you just type it as I have done line after line or is there something i have to do? All of the books i ever read seem to show you the bits I already know ;o(


Private Sub cmdImageRemove_Click()
On Error GoTo Image_Error

Dim n, o, p, msg, btn As String
Dim IDPath, ThumbImage, ThumbLocation, ThumbImagePath As String
Dim Image, Location, ImagePath As String

Set f = CreateObject("Scripting.FileSystemObject")

'the id to use as the file name...
IDPath = txtImgID.Text

'locations/destinations for the thumbnail...
ThumbImage = "U:\VB Movie Image DB\jpg\thmb_0000.jpg"
ThumbLocation = "U:\VB Movie Image DB\jpg\netvisual\thumbnail\"
ThumbImagePath = ThumbLocation & "thmb_" & IDPath & ".jpg"

'locations for the standard images...
Image = "U:\VB Movie Image DB\jpg\0000.jpg"
Location = "U:\VB Movie Image DB\jpg\netvisual\"
ImagePath = Location & IDPath & ".jpg"
'for the message box to check whether to delete image or not...
msg = "Are you sure that you want to remove this image?" & Chr(13) & Chr(13) & "The image will be deleted and the record in the database will be updated."
btn = vbOKCancel + vbDefaultButton1 + vbQuestion

'starts the process to delete the images...
n = MsgBox(msg, btn, "Remove the Image?")
If n = vbOK Then
'********THIS IS WHAT I'M UNSURE ABOUT********
Kill (ThumbImagePath)
Kill (ImagePath)
f.CopyFile ThumbImage, ThumbImagePath
f.CopyFile Image, ImagePath
o = MsgBox("The image has now been deleted...",
vbInformation, "Confirmation")
End If
Exit Sub

...sorry for sounding so thick but you'll never know if you never ask ;o)

Thanks All....
 
Looks ok apart from you don't need the brackets after kill and also you didn't need to make a reference to the scripting library. The vbrun library already has filecopy included. You could rewrite it to say:
Kill ThumbImagePath
Kill ImagePath
FileCopy ThumbImage, ThumbImagePath
FileCopy Image, ImagePath

And no you don't need to do anything else apart from click start for VB to start running your code.
 

There's a quote from Alice In Wonderland that I like to use to ilustrate sequential code. Alice is being tried at the Court of Cards, and a rabbit guard is about to read the charges against her:

"Where do I begin, please Your Majesty?"
"Begin at the beginning, and go on to the end. Then stop."


So, in your case, the code gets executed one line at a time, in sequential order. If you want to change the order, re-arrange the lines of code so that everything happens as you want it to.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top