+ Reply to Thread
Results 1 to 9 of 9

Thread: Tutorial - Picture Box with extra features!

  1. #1
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17

    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:

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

    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:

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

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

    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!


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

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

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

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

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

    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 Attached Files
    Last edited by Jordan; 09-13-2007 at 06:15 AM.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    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.

  4. #3
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17
    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...!
    Last edited by travy92; 09-13-2007 at 03:46 AM.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  5. #4
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0
    nice post... keep it up..

  6. #5
    freshfish is offline Newbie
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0
    How can i save those things as exe ?

  7. #6
    Showwb is offline Newbie
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Re: Tutorial - Picture Box with extra features!

    The explanation has reallly helped, the input box is really useful for me in my program

  8. #7
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    Re: Tutorial - Picture Box with extra features!

    @Travy: Maybe you have a trial version or something?

  9. #8
    Satanix is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Re: Tutorial - Picture Box with extra features!

    thanks a lot

  10. #9
    megha_7407 is offline Newbie
    Join Date
    May 2009
    Posts
    1
    Rep Power
    0

    Re: Tutorial - Picture Box with extra features!

    very helpful post!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extra information on links.
    By k4m1k4z1 in forum JavaScript and CSS
    Replies: 1
    Last Post: 07-28-2010, 08:56 PM
  2. [Help Needed] CSS - Extra pixels below footer need removing
    By Paxjah in forum JavaScript and CSS
    Replies: 10
    Last Post: 10-20-2009, 08:58 AM
  3. Error: Extra Tokens at end of #ifndef Directive
    By fantanoice in forum C and C++
    Replies: 18
    Last Post: 10-02-2009, 10:08 PM
  4. array_slice vs. extra query
    By BASHERS33 in forum PHP Development
    Replies: 10
    Last Post: 04-22-2009, 05:25 PM
  5. Some Extra Money
    By NeedHelp in forum Marketing
    Replies: 5
    Last Post: 08-23-2008, 07:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts