Lost Password?


  #1 (permalink)  
Old 09-12-2007, 05:51 AM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 72
Credits: 14
Rep Power: 5
travy92 is on a distinguished road
Send a message via MSN to travy92
Post Tutorial - Picture Box with extra features!

INTRO!

Hello everyone! Today we'll be making a program that loads a picture (pretty simple huh?) BUT it will have extended features! (Error handling AND InputBox)

----------------------------------------------------------------

GUI (LAYOUT):

Here is my GUI:



----------------------------------------------------------------

WHAT YOU NEED:

1 Command Button with:
Name: cmdLoad
Caption: Load

1 Picture Box:
Name: Picture1
Caption: (None)

----------------------------------------------------------------

CODE:

Add this code in General Declarations before you add the other code:

Quote:
Dim Error1 As Integer
Dim Pic As String
Now you can add this code:

Quote:
Private Sub cmdLoad_Click()
Pic = InputBox("What would you like to load?", "Yes?")

On Error GoTo Error

Picture1.Picture = LoadPicture(Pic)


Error:
Select Case Err.Number
Case 53
Error1 = MsgBox("Sorry, File not found! Please try again!", _
vbCritical + vbOKOnly, _
"File not found!")
Case Else
MsgBox (Err.Number & ", " & Err.Description)
End Select

End Sub
This is the full code, the explanation follows.

----------------------------------------------------------------

CODE EXPLANATION:

Quote:
Private Sub cmdLoad_Click()
Basically means whatever code is under this line gets executed.

----------------------------------------------------------------

Quote:
Pic = InputBox("What would you like to load?", "Yes?")
Makes an InputBox appear.

Remember: Type the picture location in the space given in the InputBox!


----------------------------------------------------------------

Quote:
On Error GoTo Error
This code tells VB to go to "Error" (Which is the title of the Error Handler section).

----------------------------------------------------------------

Quote:
Picture1.Picture = LoadPicture(Pic)
Simply means load the file that's location was specified by the user in InputBox.

----------------------------------------------------------------

Quote:
Error:
Select Case Err.Number
Case 53
Error1 = MsgBox("Sorry, File not found! Please try again!", _
vbCritical + vbOKOnly, _
"File not found!")
Case Else
MsgBox (Err.Number & ", " & Err.Description)
End Select

End Sub
This code is titled by "Error" which is the part where VB is supposed to go to if an error occured with the file location. Basically waht it does it when VB encounters an error, this part swings into action and gives you a message saying the file wasn't found OR another one with a different message (Case Else). This advantages of this is the fact that it wont close the program if it encounters an error! Disadvantages are that it requires extra coding LOL!

----------------------------------------------------------------

This is goodbye for now!

Thanks to TheComputerMaster and Tcm9669 for the ScreenShot program.

Special thanks to you for reading this tutorial.

Made by me, Travy92!

P.S - If you need help with any of the tutorials i've posted then feel free to PM me or post in the threads related to it!

SAMPLES LOL!:
Attached Files To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.
__________________
C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

Last edited by Jordan; 09-13-2007 at 09:15 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-12-2007, 05:58 PM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Credits: 0
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Well instead of the Inputbox, I would have used the component called 'Microsoft Common Dialog Control' as it makes it simpler to browse for the picture. But this shows the basic concept so it is good! And it seems like you have got the 'Case' concept! That is very, very good.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-12-2007, 08:51 PM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 72
Credits: 14
Rep Power: 5
travy92 is on a distinguished road
Send a message via MSN to travy92
Default

Yeah, the case concept is very simple now thanks to you !

EDIT - I can't use "Microsoft Common Dialog Controls" because when i try to add the item from the toolbox (After ticking "Microsoft Common Dialog Controls") i get an error saying i don't have the license to do it...!
__________________
C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

Last edited by travy92; 09-13-2007 at 06:46 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-12-2008, 05:47 AM
Abhimanyugupta2@gmail.com Abhimanyugupta2@gmail.com is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Credits: 0
Rep Power: 0
Abhimanyugupta2@gmail.com is on a distinguished road
Default

nice post... keep it up..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 04:16 PM
freshfish freshfish is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Credits: 0
Rep Power: 0
freshfish is on a distinguished road
Default

How can i save those things as exe ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-18-2008, 10:28 AM
Showwb Showwb is offline
Newbie
 
Join Date: Mar 2008
Posts: 1
Credits: 0
Rep Power: 0
Showwb is on a distinguished road
Default Re: Tutorial - Picture Box with extra features!

The explanation has reallly helped, the input box is really useful for me in my program
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-22-2008, 11:35 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Credits: 0
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default Re: Tutorial - Picture Box with extra features!

@Travy: Maybe you have a trial version or something?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: C# Hello World Jordan CSharp Tutorials 15 10-16-2008 11:44 PM
VB 6.0: Tutorial, How to make a GIF in your application TcM VB Tutorials 17 07-01-2008 04:26 PM
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 04:05 PM
General: Tutorial, Keep your PC secure for Free! TcM Tutorials 2 09-21-2006 01:51 PM


All times are GMT -5. The time now is 03:34 AM.

Contest Stats

WingedPanther ........ 2630.54
Xav ........ 2576.41
Brandon W ........ 1697.27
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 959.05
dcs ........ 646.09
Steve.L ........ 475.59
orjan ........ 407.96
chili5 ........ 378.6

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads