Get build data

Post your Gambas programming questions here.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Get build data

Post by AndyGable »

Hi everyone,

Is it possible in Gambas to get the build date and version number and show it on a label?

I can do this in vb.net I just wondered if it something you can do in Gambas.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get build data

Post by cogier »

The version number is easy: -
  Label1.Text = "MySuperProgram V" & Application.Version
You can change the version number from the menu Projects > Properties... It is also updated when you make a executable.

I'm not sure what you mean by 'Build Date'. Is it the last time it was run in the IDE or when it was last made an executable?
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Get build data

Post by BruceSteers »

you could Stat() the application exe to get modified date...

Dim s As String = Application.Path &/ Application.Name
If File.Ext(s) <> "gambas" Then s &= ".gambas"  ' gat app path this way for it to work if run from shell or if run from IDE

Label1.Text = Application.Name & " V" & Application.Version & " , date: " & Stat(s).LastModified 

If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Get build data

Post by AndyGable »

cogier wrote: Tuesday 23rd February 2021 5:37pm The version number is easy: -
  Label1.Text = "MySuperProgram V" & Application.Version
You can change the version number from the menu Projects > Properties... It is also updated when you make a executable.

I'm not sure what you mean by 'Build Date'. Is it the last time it was run in the IDE or when it was last made an executable?
Sorry I should have said the build date was when it was last made into a executable
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Get build data

Post by BruceSteers »

It might be an even better idea to use Stat() on one of the exes internal files rather than the actual exe , I'm not sure If modified date if exe can change but the file ./.gambas/FMAIN For example will be present and its date should stay the same even if the exe changes.
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Get build data

Post by AndyGable »

BruceSteers wrote: Tuesday 23rd February 2021 11:27pm It might be an even better idea to use Stat() on one of the exes internal files rather than the actual exe , I'm not sure If modified date if exe can change but the file ./.gambas/FMAIN For example will be present and its date should stay the same even if the exe changes.
Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Get build data

Post by BruceSteers »

AndyGable wrote: Wednesday 24th February 2021 11:05am
BruceSteers wrote: Tuesday 23rd February 2021 11:27pm It might be an even better idea to use Stat() on one of the exes internal files rather than the actual exe , I'm not sure If modified date if exe can change but the file ./.gambas/FMAIN For example will be present and its date should stay the same even if the exe changes.
Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.

you're welcome

I tried it , it works a treat :)
Got it down to a one liner :)

'
Label1.Text = Application.Name & " V" & Application.Version & " , date: " & Stat(Application.Path &/ ".gambas/FMAIN").LastModified 
'

when you make the executable the .gambas/FMAIN file is renewed and it's modified date changes

the file is stored inside the executable and accessible with the above code.

then if the executable files modified date gets changed by an archiver or something then the FMAIN file inside the .gambas dir inside the executable will not change.

Bruce
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get build data

Post by cogier »

Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.
No need. Try this code: -
Public Sub Form_Open()

  Print GetProgDetails()

End

Public Sub GetProgDetails() As String

  Dim sText As String = "No executable file found"
  Dim sPath As String = Application.Path &/ Application.Name & ".gambas"

  If Exist(sPath) Then sText = Format(Stat(sPath).LastModified, "dd/mm/yyyy hh:nn")
  Return Application.Name & " V" & Application.Version & " Created: - " & sText

End
My text program printed TestNew V0.0.6 Created: - 24/02/2021 14:38

EDIT
I see Bruce pipped me to the post, but my version does look for the actual executable and puts the date in world format.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Get build data

Post by AndyGable »

cogier wrote: Wednesday 24th February 2021 2:41pm
Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.
No need. Try this code: -
Public Sub Form_Open()

  Print GetProgDetails()

End

Public Sub GetProgDetails() As String

  Dim sText As String = "No executable file found"
  Dim sPath As String = Application.Path &/ Application.Name & ".gambas"

  If Exist(sPath) Then sText = Format(Stat(sPath).LastModified, "dd/mm/yyyy hh:nn")
  Return Application.Name & " V" & Application.Version & " Created: - " & sText

End
I have just tried this and I get a error "Unexpected 'Application' in frmSplash.Class:15 any idea what this means
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get build data

Post by cogier »

I have just tried this and I get a error "Unexpected 'Application' in frmSplash.Class:15 any idea what this means
Please post your program, so we can see what happens.
Post Reply