none
How to add image in an if statement RRS feed

  • Question

  • Hi

    Thanks for all the amazing support I have had of this forum so far on ym moon phase calculator. I have finished the maths side of it, now I just need to add some images. The image will depend on what the variable is. I have wrote this code but when I run the program no image shows up:

    image1="C:\Users\Wetton Children\Pictures\moon phase images for small basic\black background.jpg"
     image2="C:\Users\Wetton Children\Pictures\moon phase images for small basic\moon phase 8.jpg"

    If phase="newmmon" Then
      GraphicsWindow.DrawImage(20,20,image1)
    EndIf
    If phase="waxing cresent" Then
      GraphicsWindow.DrawImage(20,20,image2)
    EndIf

    thanks in advance

    Thursday, May 24, 2012 4:19 PM

Answers

  • Oh sorry! Only now I've realized you had misplaced the argument order for GraphicsWindow.DrawImage()

    On the right side of Small Basic editor, when you highlight an SB instruction, you can see a help panel on how to use that.
    For your DrawImage case, you can see: GraphicsWindow.DrawImage(imageName, x, y). So, you have to place the imageName 1st, only then, its coordinates!

    GraphicsWindow.DrawImage(20,20,image1) is wrong, you have to replace it w/:
    GraphicsWindow.DrawImage(image1  20,20). Same thing for image2.  :-P

    Looking forward to see your lunar program working. Cya!

    Thursday, May 24, 2012 5:53 PM
    Answerer

All replies

  • Heyya Alex!

    For the variable phase to be = to "newmmon" or to "waxing cresent", there has to be some place else within your code where you can attribute those string values to phase!

    Another thing is, you have to pay attention for not mistyping those strings. For example:
    If, by chance, phase = "newmoon", but your If code line is testing for "newmmon", the condition won't match at all -> "newmmon" <> "newmoon".
    The same applies for -> "newmmon" <> "newmmon " <> " newmmon" <> "NewMoon" <> "newMoon" <> "New Moon", etc.

    Just for testing purposes, write phase = "newmmon" or phase = "waxing cresent" before the If code lines begin in your program, so you can check weather it's working or not!

    And also a cosmetic tip. Instead of typing the gigantic "C:\Users\Wetton Children\Pictures\moon phase images for small basic\xxxxx xxxxxxx.xxx" string all the time, you can rather make a variable for the part which always repeat.  Like this:

    path = "C:\Users\Wetton Children\Pictures\moon phase images for small basic\"
    
    image1 = path + "black background.jpg"
    image2 = path + "moon phase 8.jpg"

    Another option is placing all needed extra files inside the same folder where you save the program. This way you can attribute property Directory of object Program to variable path, like bellow:

    path = Program.Directory + "\"
    
    image1 = path + "black background.jpg"
    image2 = path + "moon phase 8.jpg"

    And there's always the option to put the extra files on a host Internet service, and make path = "http://URL of host/"

    Laterz!
    Thursday, May 24, 2012 5:32 PM
    Answerer
  • Oh sorry! Only now I've realized you had misplaced the argument order for GraphicsWindow.DrawImage()

    On the right side of Small Basic editor, when you highlight an SB instruction, you can see a help panel on how to use that.
    For your DrawImage case, you can see: GraphicsWindow.DrawImage(imageName, x, y). So, you have to place the imageName 1st, only then, its coordinates!

    GraphicsWindow.DrawImage(20,20,image1) is wrong, you have to replace it w/:
    GraphicsWindow.DrawImage(image1  20,20). Same thing for image2.  :-P

    Looking forward to see your lunar program working. Cya!

    Thursday, May 24, 2012 5:53 PM
    Answerer