ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

Visual Basic Help please!



  BMW X5
Hi all,

I am using Visual Studio to create a form that will allow a user to enter a product code into a field, click enter and the form will display an image that refers to the product.

The product image is always in the same location, "C:\pics\" and is always named after the product code, but with the suffix ".jpg".

I am really struggling to ge this to work as Im not a programmer and don't know where to start, and have searched the net...

Code I have at the mo is;

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If Dir("C:\pics\" & TextBox1 & ".jpg") <> "" Then

PictureBox1.Image = ("C:\pics\" & TextBox1 & ".jpg")
Else
PictureBox1.Image = ("C:\pics\nopic.jpg")
End If

End Sub

But its not working at all... can anyone help!! Please!!
Thanks,

David
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim filename as string

filename = "C:\pics\" & textbox1.text & ".jpg"

If Dir(filename) <> "" Then


PictureBox1.Image = (filename)
Else
PictureBox1.Image = ("C:\pics\nopic.jpg")
End If

End Sub

Try that mate
 
  BMW X5
Hi... got it working perfectly with this;

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If Dir("C:\pics\" & TextBox1.Text & ".jpg") <> "" Then

PictureBox1.Image = Image.FromFile("C:\pics\" & TextBox1.Text & ".jpg")
TextBox1.Text = ""
TextBox1.Focus()

Else
PictureBox1.Image = Image.FromFile("C:\pics\nopic.jpg")
TextBox1.Text = ""
TextBox1.Focus()

End If

End Sub

But how do i link textbox1 to button1_click when enter (return) is pressed on keyboard?

Thanks!!
 
Haven't a clue i'm afraid mate. Been trying to do this myself for a number of project iv written in VB
 


Top