(newbie VB 2005 EE ) composing string from variables

  • Thread starter Thread starter Opa Vito
  • Start date Start date
O

Opa Vito

Hello, I can't find out how to compose a string from a few variables
that can be used to define the location of a file.

For example:
PictureBox1.Image = System.Drawing.Image.FromFile("pictures\03.jpg")

I cannot find how to compose the string from the fact that the picture
is in folder "pictures" (all pictures will be in that folder) and that
the picture-file is a string-variable that can be randomly set by the user.

All help welcome
Thanks

Vito
 
Dim FileName as String
FileName = "03.jpg"
PictureBox1.Image = System.Drawing.Image.FromFile("pictures\" &
FileName)

also, dont forget to use File.Exists() first to make sure the file they
specify exists.

-keith
 
Do you mean you want to concatenate two strings? If so try this

Dim PictureFile as string
PictureFile = "03.jpg"

PictureBox1.Image = System.Drawing.Image.FromFile("pictures\" &
PictureFile)

That will open the same picture as your below code. If that's not what
you meant please repost and I'll try again :-)

Thanks,

Seth Rowe
 
Oops, I guess keith types faster than I do!

rowe_newsgroups said:
Do you mean you want to concatenate two strings? If so try this

Dim PictureFile as string
PictureFile = "03.jpg"

PictureBox1.Image = System.Drawing.Image.FromFile("pictures\" &
PictureFile)

That will open the same picture as your below code. If that's not what
you meant please repost and I'll try again :-)

Thanks,

Seth Rowe
 
rowe_newsgroups schreef:
Do you mean you want to concatenate two strings? If so try this

Dim PictureFile as string
PictureFile = "03.jpg"

PictureBox1.Image = System.Drawing.Image.FromFile("pictures\" &
PictureFile)

Hi, strange but I tried that too ... and it always failed. I tried it
again by splitting the filestring and checking if it exists:

Dim PictureFile as String
PictureFile="pictures\" & pic ' pic is the variable name
If File.Exists(PictureFile) Then
PictureBox1.Image = System.Drawing.Image.FromFile(PictureFile)
End If

And it works now :-)

Thanks for your cooperation

Vito
 
Opa said:
Hello, I can't find out how to compose a string from a few variables
that can be used to define the location of a file.

For example:
PictureBox1.Image = System.Drawing.Image.FromFile("pictures\03.jpg")

I cannot find how to compose the string from the fact that the picture
is in folder "pictures" (all pictures will be in that folder) and that
the picture-file is a string-variable that can be randomly set by the
user.

Do make sure that you give it the full path to the file.

Combining parts of a path is perhaps best done using System.IO.Path.Combine.

Andrew
 
Back
Top