TextBox

In VB4 I have a form, a FileListBox (which includes some jpg pictures), an Image and a TextBox.
With a click in the name of any picture in the FileListBox, the picture appears in the Image.
(I use the command:
f$ = File1.Path + "\" + File1.filename
image1.Picture = LoadPicture(f$)
How could I, for any picture I load, a certain text to be displayed in the TextBox? (Which will describe the picture).  
I would not like to use the «ListIndex», because the order and the number of the pictures will be change from time to time.  
What I want is when the picture (city.jpg for example), is loaded, a certain text for this picture to be displayed.
oteAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VbmasterConnect With a Mentor Commented:
Humm.. you have the filename in File1.filename don't you? Code like this should do it

Select Case Ucase$(File1.filename)
Case "CITY.JPG"
  Text1.Text = "A city.. or something"
..
<add more case statements here>
..
End Select
0
 
mcriderCommented:
If you want to be able to change your text without recompiling your program, you can put your text in an ASCII file or a database.  Key the file with the name of the JPG file...

Then all you have to do is read the file or database...

For example, in a file, you could have the following lines:

   CITY.JPG:A city.. or something
   STATE.JPG:A state.. or something

Then you could read the file and split the record read into fields and test the fields, like in this function:

function GetText(Filename as string) as string
dim fnum as long
dim buf as string
dim ival as integer
dim arg1 as string
dim arg2 as string
fnum=freefile
open "myfile" for input access read as #fnum
do while not eof(fnum)
   line input #fnum, buf
   ival=instr(1,buf,":")
   arg1=left$(buf,ival-1)
   arg2=mid$(buf,ival+1)
   if Filename=arg1 then
      GetText=arg2
      exit do
   end if
loop
close fnum
end function


Cheers!
0
 
mark2150Commented:
Got a sample project on my web page that pulls up images and text from an Access database. Visit www.cyberchute.com/rvbus/madmark

M
0
 
oteAuthor Commented:
I accept the simple answer of VBmaster.
That was what I needed!
I'll keep the valuable answer of mcrider for some next effort of mine.
Thanks!
0
 
mcriderCommented:
Glad I could help...


Cheers!
0
All Courses

From novice to tech pro — start learning today.