Page 1 of 2

Get build data

Posted: Tuesday 23rd February 2021 5:22pm
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.

Re: Get build data

Posted: Tuesday 23rd February 2021 5:37pm
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?

Re: Get build data

Posted: Tuesday 23rd February 2021 9:05pm
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 


Re: Get build data

Posted: Tuesday 23rd February 2021 9:51pm
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

Re: Get build data

Posted: Tuesday 23rd February 2021 11:27pm
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.

Re: Get build data

Posted: Wednesday 24th February 2021 11:05am
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.

Re: Get build data

Posted: Wednesday 24th February 2021 2:34pm
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

Re: Get build data

Posted: Wednesday 24th February 2021 2:41pm
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.

Re: Get build data

Posted: Wednesday 24th February 2021 2:53pm
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

Re: Get build data

Posted: Wednesday 24th February 2021 3:09pm
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.