Visual Basic, loading a image.

Displaying a image from the web in a picture box - help!

Page 1 of 1

7 Replies - 8498 Views - Last Post: 16 September 2008 - 09:50 AM Rate Topic: -----

#1 flash_20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-September 08

Visual Basic, loading a image.

Posted 16 September 2008 - 08:40 AM

Hi, I am creating a from where the user builds a form that includes images from there website.

I am stuck on the following.

I have a input box where the user enters the URL of the thumbnail image they require, eg. http://www.yahoo.co.uk/image.jpeg (just made that one up). Once that input has lost focus I want the image to be displayed in the picture box.

The way I though would work keeps throwing an error, can anyone help? Thanks in advance,

Flash.

Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic, loading a image.

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 08:43 AM

1) Are you using VB6 or a different version?
2) Show us the code you're using and we will try our best to help you debug it.
3) When posting your code please use code tags, like so => :code:
Was This Post Helpful? 0
  • +
  • -

#3 flash_20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-September 08

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:14 AM

View PostPsychoCoder, on 16 Sep, 2008 - 08:43 AM, said:

1) Are you using VB6 or a different version?
2) Show us the code you're using and we will try our best to help you debug it.
3) When posting your code please use code tags, like so => :code:



This is the code I have:

Private Sub btnThumb_Click()
imgThumb.Image = "http://http.cdnlayer.com/dreamincode/home/images/logo.gif"
imgThumb.Refresh
End Sub

Have also tried imgThumb.Picture but have the same problem.

Many thanks.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:16 AM

Ok, what error are you receiving?
Was This Post Helpful? 0
  • +
  • -

#5 flash_20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-September 08

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:20 AM

View PostPsychoCoder, on 16 Sep, 2008 - 09:16 AM, said:

Ok, what error are you receiving?


Hi again, the error is a follows:

Compile Error, invalid use of property.

Cheers again.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:28 AM

That's because you cant add a picture to a PictureBox like that. The Picture Property is expecting an actual image, not the name of an image. You can try using the LoadPicture Function, like so


Private Sub btnThumb_Click()
     Set imgThumb.Picture= LoadPicture("http://http.cdnlayer.com/dreamincode/home/images/logo.gif")
End Sub



This may or may not work (I haven't tested it yet since I'm working), but t should at least lead you down the right path :)
Was This Post Helpful? 0
  • +
  • -

#7 flash_20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-September 08

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:35 AM

View PostPsychoCoder, on 16 Sep, 2008 - 09:28 AM, said:

That's because you cant add a picture to a PictureBox like that. The Picture Property is expecting an actual image, not the name of an image. You can try using the LoadPicture Function, like so


Private Sub btnThumb_Click()
     Set imgThumb.Picture= LoadPicture("http://http.cdnlayer.com/dreamincode/home/images/logo.gif")
End Sub



This may or may not work (I haven't tested it yet since I'm working), but t should at least lead you down the right path :)


Thanks for the reply but I still get an error.

This time it I get a run-time error 75, path/file access error.

Cheers.
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic, loading a image.

Posted 16 September 2008 - 09:50 AM

Thats why I warned that it may not work since the image is coming from a URL not a local file. The easiest way to accomplish this is to Open Visl Basic and select Active-X Control as a project type. Add a PictureBox control to the new user control project you created. Then add this code to the new user control project you just created

Option Explicit
      Const vbAsyncTypePicture = 0

      Private Sub UserControl_AsyncReadComplete(AsyncProp As
      AsyncProperty)
        On Error Resume Next
        Set Picture1.Picture = AsyncProp.Value
      End Sub

      Private Sub UserControl_Initialize()
       UserControl.AsyncRead   "http://http.cdnlayer.com/dreamincode/home/images/logo.gif",  vbAsyncTypePicture
      End Sub




Rename the project to something more meaningful than Project1, compile the project and you now have a user control that is a picturebox to load an image from a URL.

Create a new project (An application this time) and add your new control to the form and it will load your image from the URL :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1