none
Photo-viewer - programming techniques RRS feed

  • General discussion

  • Hello, the topic is not to rewrite a new photoviewer but i got some questions on program.delay not working as expected, activate a button, get information from the grapics window, create a countdown, get an image, creating an array with the files from a directory, etc. So I was putting all this stuff together, just to show some possibilities. OK I wasn't optimizing this program at all and passed variables from one subroutine to another changing their names, but the topic is just showing some features. I am not interested in a photo-viewer ... Perhaps it would be a better idea to publish each module seperately ? My concern is that it is difficult to find small examples. I found some from Ed, litdev, Jan, Nonki ... but also a lot of extreme complex games where the programming syntax techniques are very difficult to analyse, creating a lack of motivation. There are more than thousand program languages perhaps more than spoken languages so it is important to find small programs to help students studying mathematics  (The only standardized language ?) "Small" basic is really fun, an introduction but a lot more than turttlebasic. It helps to understand the techniques behind mathematical theory to get practical results.     

    The program is published as TRZ088

    And NO IDEA why the imported program is not working (I tried it 3 times - WPG334, TRZ088 and JGB070

    Copy/Paste of the program below is working)

    'Arrow-button 
    w = 250
    h = 500
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Width = w
    GraphicsWindow.Height = h
    GraphicsWindow.Top = 50   
    GraphicsWindow.Left = 50  
    GraphicsWindow.FontSize = 15
    TextWindow.left=550
    TextWindow.top =50
    textwindow.writeline("w= "+w+" h= "+h+" top= "+GraphicsWindow.Top+" left= "+GraphicsWindow.Left)

    GraphicsWindow.PenWidth = 5
    GraphicsWindow.PenColor = "Black"

    GraphicsWindow.DrawRectangle(25,10,200,325)

    GraphicsWindow.Backgroundcolor="DimGray"

    'GraphicsWindow.fontbold
    GraphicsWindow.fontsize=12
    'xxxxxxxxxxxxxx  MAIN PROGRAM xxxxxxxxxxxxxxx
    CreateGUI()
    Controls.ButtonClicked = ButtonDown 
    'waiting for input and will execute each time the ButtonDown subroutine
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Sub CreateGUI   
      Start = Controls.AddButton("START", 15,345) 'put in place the button
      Controls.SetSize(START, 65, 30)
      Stop = Controls.AddButton("STOP", 90,345) 'put in place the button
      Controls.SetSize(Stop, 65, 30)
      Resume = Controls.AddButton("RESUME", 165,345) 'put in place the button
      Controls.SetSize(Resume, 65, 30)

      GraphicsWindow.BrushColor = "White"
      GraphicsWindow.FontSize = 14
      GraphicsWindow.DrawText(15,376,"             Photodirectory")
      GraphicsWindow.DrawText(15,425,"Interval in seconds")
      GraphicsWindow.BrushColor = "Black"
      GraphicsWindow.FontSize = 12
      ImgDir = Controls.AddTextBox(15,395)
      Controls.SetSize(ImgDir,220,22)
      Interval= Controls.AddTextBox(160,425)
      Controls.SetSize(Interval,35,22)
      
    EndSub  
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Sub ButtonDown
      operator = Controls.GetButtonCaption(Controls.LastClickedButton)  
      TextWindow.WriteLine("operator : "+operator) 
      Mydir=controls.gettextboxtext(Imgdir)
      TextWindow.WriteLine("Image directory : "+Mydir) 
      
      MyInterval=controls.gettextboxtext(Interval)
      If myinterval<1 then
        MyInTerVal= 3
        endif
      TextWindow.WriteLine("Interval : "+MyInterval)
       
      If operator="START" Then
        start=1
        begin=1
        TextWindow.WriteLine("operator Hit  : "+operator) 
        startimages()
        Elseif operator="STOP" Then
        start=0
        x=100000 'to stop the delay counter
        TextWindow.WriteLine("operator Hit  : "+operator)
        Elseif operator="RESUME" Then
        start=1  
        begin=counter+1 'or begin=counter
        ReadImages()
        TextWindow.WriteLine("operator Hit  : "+operator)
            
      endif
    EndSub
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
    Sub startimages
       
        'Mydir="D:\SB\Photos" 'Mydir="D:\SB\Photos"
        path=Mydir
        TextWindow.WriteLine("showfiles : "+File.getfiles (Mydir))
      TextWindow.WriteLine("[" + path + "]")
      Images="" 'to empty the array
      Images = File.GetFiles(path)              ' get directories
      n = Array.GetItemCount(Images)
      ReadImages()
        
      EndSub

    Sub ReadImages
      
      For i = begin To n
        if start=1 then
          counter=i
          x=0
          
        TextWindow.WriteLine("Counter = "+i+" Image = "+ Images[i])
          GraphicsWindow.DrawResizedImage(Images[i], 25, 10, 200, 325) 
          '   xxxxxxxxxxxxx   
        
        GraphicsWindow.BrushColor = "White"
        GraphicsWindow.PenWidth = 1
        GraphicsWindow.fillRectangle(15,465,220,25) 
        GraphicsWindow.FontSize = 14
        GraphicsWindow.BrushColor = "Black"
        GraphicsWindow.DrawText(15,467,Images[i]  )
     '    xxxxxxxxxxxxxx   
        Delay()
        
        endif       
      EndFor
      'TextWindow.WriteLine("intervalseconds : "+sec)
            TextWindow.WriteLine("End Of Show")
      
    endsub

    Sub DelayOrig
      Max=10000
     x=0                                     ''EA
             While x < Max                           ''EA
               GraphicsWindow.DrawText(1,1," ")      ''EA
               x=x+1                                 ''EA
             Endwhile 
    EndSub
       
    Sub Delay
      
    imgItv=myinterval
    while imgItv > 0 
    BeginImgItv=Clock.Second
    timerloop()
      EndImgItv=Clock.Second
      
      if EndImgItv < BeginImgItv then
        TextWindow.WriteLine(EndImgItv+"   "+ BeginImgItv)
      EndImgItv= EndImgItv+60
      EndIf
      imgItv=imgItv+BeginImgItv-EndImgItv
        TextWindow.WriteLine("Interval counter : "+imgItv)
     '   xxxxxxxxxxxxx   
        GraphicsWindow.BrushColor = "White"
        GraphicsWindow.PenWidth = 1
        GraphicsWindow.fillRectangle(210,427,30,20) 
        GraphicsWindow.FontSize = 14
        GraphicsWindow.BrushColor = "Black"
        GraphicsWindow.DrawText(220,428,imgItv)
     '    xxxxxxxxxxxxxx   
    endwhile
      TextWindow.WriteLine("End Interval : "+imgItv)
      Endsub


    sub timerloop
    x=0
    while x<1000
        GraphicsWindow.DrawText(1,1," ")
        x=x+1
      EndWhile
    endsub

     



    • Edited by Eddy Abts Wednesday, May 8, 2019 8:48 AM
    Wednesday, May 8, 2019 8:17 AM

All replies

  • Dod you notice in your uploaded programs the following type of lines?

    ' The following line could be harmful and has been automatically commented.
    '   Images = File.GetFiles(path)              ' get directories
     To make the program working you hasve to uncommnet the GetFiles lines!


    Jan [ WhTurner ] The Netherlands

    Wednesday, May 8, 2019 9:40 AM
    Answerer
  • Hi Eddy, did you check following article?  It introduces short samples.

    Small Basic: Sample Code (TechNet Wiki) 


    Nonki Takahashi

    Wednesday, May 22, 2019 3:33 AM
    Moderator