Get build data

Post your Gambas programming questions here.
AndyGable
Posts: 52
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Get build data

Post by AndyGable » Tuesday 23rd February 2021 5:22pm

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: 648
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get build data

Post by cogier » 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?

User avatar
BruceSteers
Posts: 401
Joined: Thursday 23rd July 2020 5:20pm

Re: Get build data

Post by BruceSteers » Tuesday 23rd February 2021 9:05pm

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 

Wishing well
Bruce

If at first you don't succeed , try it differently.

AndyGable
Posts: 52
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: Get build data

Post by AndyGable » Tuesday 23rd February 2021 9:51pm

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: 401
Joined: Thursday 23rd July 2020 5:20pm

Re: Get build data

Post by BruceSteers » 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.
Wishing well
Bruce

If at first you don't succeed , try it differently.

AndyGable
Posts: 52
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: Get build data

Post by AndyGable » 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.

User avatar
BruceSteers
Posts: 401
Joined: Thursday 23rd July 2020 5:20pm

Re: Get build data

Post by BruceSteers » Wednesday 24th February 2021 2:34pm

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
Wishing well
Bruce

If at first you don't succeed , try it differently.

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

Re: Get build data

Post by cogier » 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
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: 52
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: Get build data

Post by AndyGable » Wednesday 24th February 2021 2:53pm

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: 648
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get build data

Post by cogier » Wednesday 24th February 2021 3:09pm

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