none
Help with Debugging aids (3.6) Show what you know RRS feed

  • Question

  • Hello!

    I have been (for an hour now) trying to get this code to work. I couldn't get the sample code to work well, so i wrote my own, studying the sample. but, i have run into a problem... I can't get the images to appear! there are images in the folder, and when i use textwindow.writeline(File.GetFiles(path)), it does print it on the textwindow. how can i get it to print the images on the graphics window? any help is greatly appreciated.

    Code:

    GUI()
    
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
    EndSub
    path1 = "C:\Users\Public\Pictures\Sample Pictures\"
    path = File.GetFiles(path1)
    
    
    
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
      GraphicsWindow.DrawImage(path,1,1)
      
      EndIf
      EndIf
    EndSub


    I am a 12 year old learning how to code using small basic.


    • Edited by 8Bit Pony Saturday, June 15, 2013 3:51 AM
    Saturday, June 15, 2013 3:50 AM

Answers

  • You have some mistakes in your code.

    First you have 1 if but 2 endif's. You need to delete one.

    Than you need to tell the program which picture it has to use.

    This code works well for me:

    GUI()
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
    EndSub
    path1 = "C:\Users\Public\Pictures\"
    path = File.GetFiles(path1)
    
    
    
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
      GraphicsWindow.DrawImage(path[2],1,1) 'the [2] tells the program that it has to use the second file in the directory.
      
      EndIf
    EndSub

    But note, if there are other files in the directory which are not images, can new problems appear. You need to filter the files if you want to be sure.

    If you want to use a random file, use this code:

    GUI()
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
    EndSub
    path1 = "C:\Users\Public\Pictures\"
    path = File.GetFiles(path1)
    
    
    
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
      GraphicsWindow.DrawImage(path[Math.GetRandomNumber(Array.GetItemCount(path))],1,1)
      
      EndIf
    EndSub


    Mit freundlichen Grüßen Timo Greetings Timo




    • Edited by Timo Sö Saturday, June 15, 2013 8:46 AM
    • Marked as answer by 8Bit Pony Saturday, June 15, 2013 5:35 PM
    Saturday, June 15, 2013 8:42 AM
  • Good program, a couple of points:

    1] You have an extra EndIf in there, use the right click-> Format program to check this - if it is right all the indentations should look right

    2] The variable path is an array of files so you need to have an index to this array that updates for each picture.

    3] Some files in this folder may not be images and will not show (in my folder anyway)

    Here it is modified a bit

    GUI()
    
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
      path1 = "C:\Users\Public\Pictures\Sample Pictures\"
      path = File.GetFiles(path1)
      iCount = 0
    EndSub
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
        iCount = iCount+1
        TextWindow.WriteLine(path[iCount])
        GraphicsWindow.DrawImage(path[iCount],1,1)
      EndIf
    EndSub
    
    
    Note that when all the pictures are shown, iCount will just keep increasing and show nothing.  I kept in the TextWindow.WriteLine to show what is happening.

    • Marked as answer by 8Bit Pony Saturday, June 15, 2013 5:35 PM
    Saturday, June 15, 2013 8:45 AM
    Moderator

All replies

  • You have some mistakes in your code.

    First you have 1 if but 2 endif's. You need to delete one.

    Than you need to tell the program which picture it has to use.

    This code works well for me:

    GUI()
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
    EndSub
    path1 = "C:\Users\Public\Pictures\"
    path = File.GetFiles(path1)
    
    
    
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
      GraphicsWindow.DrawImage(path[2],1,1) 'the [2] tells the program that it has to use the second file in the directory.
      
      EndIf
    EndSub

    But note, if there are other files in the directory which are not images, can new problems appear. You need to filter the files if you want to be sure.

    If you want to use a random file, use this code:

    GUI()
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
    EndSub
    path1 = "C:\Users\Public\Pictures\"
    path = File.GetFiles(path1)
    
    
    
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
      GraphicsWindow.DrawImage(path[Math.GetRandomNumber(Array.GetItemCount(path))],1,1)
      
      EndIf
    EndSub


    Mit freundlichen Grüßen Timo Greetings Timo




    • Edited by Timo Sö Saturday, June 15, 2013 8:46 AM
    • Marked as answer by 8Bit Pony Saturday, June 15, 2013 5:35 PM
    Saturday, June 15, 2013 8:42 AM
  • Good program, a couple of points:

    1] You have an extra EndIf in there, use the right click-> Format program to check this - if it is right all the indentations should look right

    2] The variable path is an array of files so you need to have an index to this array that updates for each picture.

    3] Some files in this folder may not be images and will not show (in my folder anyway)

    Here it is modified a bit

    GUI()
    
    Sub GUI
      GraphicsWindow.Width = 700
      GraphicsWindow.Height = 500
      next = Controls.AddButton("Next",10,10)
      Controls.ButtonClicked = SlideShow
      path1 = "C:\Users\Public\Pictures\Sample Pictures\"
      path = File.GetFiles(path1)
      iCount = 0
    EndSub
    
    Sub SlideShow
      If (Controls.LastClickedButton = next) Then 
        iCount = iCount+1
        TextWindow.WriteLine(path[iCount])
        GraphicsWindow.DrawImage(path[iCount],1,1)
      EndIf
    EndSub
    
    
    Note that when all the pictures are shown, iCount will just keep increasing and show nothing.  I kept in the TextWindow.WriteLine to show what is happening.

    • Marked as answer by 8Bit Pony Saturday, June 15, 2013 5:35 PM
    Saturday, June 15, 2013 8:45 AM
    Moderator
  • Thank you everyone! i ment to erase that extra endif, sorry.

    I am a 12 year old learning how to code using small basic.

    Saturday, June 15, 2013 5:36 PM