|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
(newbie VB 2005 EE ) composing string from variablesHello, 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 Opa Vito wrote: Show quoteHide quote > 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 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 Opa Vito wrote: Show quoteHide quote > 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 Oops, I guess keith types faster than I do!
rowe_newsgroups wrote: Show quoteHide quote > 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 > > Opa Vito wrote: > > 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 rowe_newsgroups schreef:
> Do you mean you want to concatenate two strings? If so try this Hi, strange but I tried that too ... and it always failed. I tried it > > Dim PictureFile as string > PictureFile = "03.jpg" > > PictureBox1.Image = System.Drawing.Image.FromFile("pictures\" & > PictureFile) 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 Vito wrote:
> Hello, I can't find out how to compose a string from a few variables Do make sure that you give it the full path to the file.> 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. Combining parts of a path is perhaps best done using System.IO.Path.Combine. Andrew
how to rollback a procedure (sqlserver) from VB2005?
EXE and Dev environment. Epson TM-T88 Drawer Kick string or StringBuilder return ? how to make base and derived class use the same member variable? Can we Read the text contents from PDF using .net Reflection, creating object with inherited cunstructor, how? Subtract Days from a Date How to licensce a .NET desktop application TreeView node remove: what event? |
|||||||||||||||||||||||