Get Last Tag

Post Reply
cage
Posts: 55
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Get Last Tag

Post by cage » Wednesday 18th March 2020 3:41am

I have been working on a array of picture boxes which are in a scrollview. I can load the icons into a picture box with no problem. However I can't find a way to find a way to determine which picture box was clicked on. I have used last.tag but it only seems to work on the array if it's outside the scrollview. Does anyone know how to determine which picture box was clicked in the scrowview? Any help will be greatly appreciated.

cage
Posts: 55
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Get Last Tag

Post by cage » Wednesday 18th March 2020 7:40am

Here us the code, it's a bit rough around the edges yet.
' Gambas class file

Public BoxName As New String[43]
Public BoxCmd As New String[43] 
Public TotalRec As Integer

Public Sub Form_Open()

Dim hFile As File
Dim ProgName As String
Dim Lcon As String
Dim Comd As String
Dim LineSpace As String
Dim txtLabel As New String[43]
Dim picBox As New String[43]
Dim button As New String[43]
Dim oo As Object
Dim I As Integer

'Assign names to buttons into an array
'See if there is any data in the index file

 hFile = Open Application.Path &/ "Index.dat" For Input
   If Eof(hFile) = True Then
      Return
   Else
      I = 0 'Set i to 1
      While Not Eof(hFile)

         Line Input #hFile, ProgName
         Line Input #hFile, Lcon
         Line Input #hFile, Comd
         Line Input #hFile, LineSpace
         txtLabel = ProgName
         BoxCmd = Comd
         picBox = Lcon
         Inc I  'Index by one
      Wend
      Close #hFile
      TotalRec = I - 1
      If TotalRec >= 42 Then
         Message(Str(TotalRec))
      Endif
   Endif 

 I = 0  
  For Each oo In ScrollView1.Children 
     'See if the next control is a Picturbox if so load image
     If oo Is PictureBox Then
       If picBox = "" Then Exit
         oo.Picture = Picture.Load(picBox)
       Inc I
    Endif
   Next 
  I = 0 
For Each oo In ScrollView1.Children    
    If oo Is TextLabel Then
     oo.text = txtLabel
      Inc I
    Endif
Next     
  
End


Public Sub Picture_MouseDown()
  
  Dim X As Integer
  Dim Picturbox As Object
  
    X = Last.Tag

   Shell BoxCmd[X] 

End


User avatar
Quincunxian
Posts: 71
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Get Last Tag

Post by Quincunxian » Wednesday 18th March 2020 9:40am

Hi cage,
Add each of the Pictures to a Group
(give all the picture blocks the same group name... 'Blah')

Then add the following code:
Public Sub Blah_MouseDown()
   Message (Last.Name)
End
I got a quick test program to work doing this.
Cheers - Quin.
I code therefore I am

User avatar
cogier
Site Admin
Posts: 428
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get Last Tag

Post by cogier » Wednesday 18th March 2020 4:14pm

Hi cage, I am with Quincunxian on this. By using the Group feature it works fine. I have attached a small program that should help.
test.tar.gz
(34.81 KiB) Downloaded 29 times

cage
Posts: 55
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Get Last Tag

Post by cage » Thursday 19th March 2020 7:09pm

Thanks guys. Quincunxian I knew about the name tag however I was looking for the tag number. Charlies example reminded me that I forgot to assign a tag number to the picture boxes. I am loading the images from a index file which now does what I wanted. I still have some work to do since loading the images does not work 100% correctly. I think I know the reason why and am going to go at this in a different way.

Post Reply