LB Booster
Programming >> Liberty BASIC language >> Store and une a filename in a variable
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1497765139

Store and une a filename in a variable
Post by flotulopex on Jun 18th, 2017, 05:52am

Hi,

I'm trying to improve a small program I just finished and one point would be to handle BMP files via a variable (ImageFile$) instead of having to name each file every time.

The purpose of the program is to display the actual kind of dance played and the user can select them by directly clicking on each image's list (easy to understand - I wish I could attach some images).

Code:
' Image Launcher short

NOMAINWIN

   WindowWidth = 1920
   WindowHeight = 1080

   LOADBMP "BackgroundImage",".\Aucune.bmp"

   GRAPHICBOX #MainWindow.GBx1,0,0,1920,1080
   STYLEBITS  #MainWindow.GBx1,0,_WS_BORDER,0,0

[MAIN]
   OPEN "Display BMP image" FOR window_popup AS #MainWindow
   #MainWindow "TRAPCLOSE [QUIT_MAIN_WINDOW]"
   #MainWindow.GBx1 "down"
   #MainWindow.GBx1 "drawbmp BackgroundImage 0 0"
   #MainWindow.GBx1 "when leftButtonDown [MouseLeftButton]"
   WAIT

[MAIN_REFRESH]
'***
LOADBMP "BackgroundImage",ImageFile$
'***
   #MainWindow.GBx1 "down"
   #MainWindow.GBx1 "drawbmp BackgroundImage 0 0"
   WAIT

[QUIT_MAIN_WINDOW]
   CLOSE #MainWindow
   END

[MouseLeftButton]
   IF (MouseX > 1685 AND MouseX < 1770) THEN    'Aucune
      IF (MouseY > 1055 AND MouseY < 1069) THEN
         UNLOADBMP "BackgroundImage"
'****
         'LOADBMP "BackgroundImage",".\Aucune.bmp"
ImageFile$ = ".\Aucune.bmp"
'****
         GOTO [MAIN_REFRESH]
      END IF
   END IF

   IF (MouseX > 603 AND MouseX < 671) THEN    'Bachata
      IF (MouseY > 962 AND MouseY < 979) THEN
         UNLOADBMP "BackgroundImage"
'****
         'LOADBMP "BackgroundImage",".\Bachata.bmp"
ImageFile$ = ".\Bachata.bmp"
'****
         GOTO [MAIN_REFRESH]
      END IF
   END IF

   IF (MouseX > 207 AND MouseX < 315) THEN    'Cha-Cha-Cha
      IF (MouseY > 919 AND MouseY < 935) THEN
         UNLOADBMP "BackgroundImage"
'****
         'LOADBMP "BackgroundImage",".\Cha-Cha-Cha.bmp"
ImageFile$ = ".\Cha-Cha-Cha.bmp"
'****
         GOTO [MAIN_REFRESH]
      END IF
   END IF

   IF (MouseX > 1820 AND MouseY > 1045) THEN GOTO [QUIT_MAIN_WINDOW] ' "Quitter"
   WAIT 

The changes are between '*** .

NB: how do I attach a file to the thread?

Re: Store and une a filename in a variable
Post by Richard Russell on Jun 18th, 2017, 4:04pm

on Jun 18th, 2017, 05:52am, flotulopex wrote:
one point would be to handle BMP files via a variable (ImageFile$) instead of having to name each file every time.

What's the problem? Are you saying that this line from your program isn't working:

Code:
LOADBMP "BackgroundImage",ImageFile$ 

Even the LBB docs show a variable being used for the filename, so it should certainly be OK.

Quote:
NB: how do I attach a file to the thread?

You can't, as far as I know.

Richard.

Re: Store and une a filename in a variable
Post by flotulopex on Jun 19th, 2017, 09:50am

I had to do it this way:

Code:
...
[MAIN_REFRESH]
   UNLOADBMP "BackgroundImage"
   LOADBMP ".\" + ImageFile$ + ".bmp"
   #MainWindow.GBx1 "down"
   #MainWindow.GBx1 "drawbmp BackgroundImage 0 0"
   WAIT

...
[MouseLeftButton]
   IF (MouseX > 1685 AND MouseX < 1770) THEN    'Aucune
      IF (MouseY > 1055 AND MouseY < 1069) THEN
         ImageFile$ = "Aucune"
         GOTO [MAIN_REFRESH]
      END IF
   END IF 

Re: Store and une a filename in a variable
Post by Richard Russell on Jun 19th, 2017, 1:35pm

on Jun 19th, 2017, 09:50am, flotulopex wrote:
I had to do it this way

I'm not too sure what point you are making. The leading ".\" to the file specification doesn't achieve anything ('dot' is the current directory anyway); you would probably be better to use DefaultDir$ like this:

Code:
LOADBMP "BackgroundImage", DefaultDir$ + "\" + ImageName$ + ".bmp" 

Richard.