Get build data

Post

Posted
Rating:
#1 (In Topic #593)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
The version number is easy: -

Code (gambas)

  1.   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?
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
you could Stat() the application exe to get modified date…

Code (gambas)

  1.  
  2. 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
  3.  
  4. Label1.Text = Application.Name & " V" & Application.Version & " , date: " & Stat(s).LastModified
  5.  
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

cogier said

The version number is easy: -

Code (gambas)

  1.   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
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

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.
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

BruceSteers said

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 :)

Code (gambas)

  1.  
  2. '
  3. Label1.Text = Application.Name & " V" & Application.Version & " , date: " & Stat(Application.Path &/ ".gambas/FMAIN").LastModified
  4. '
  5.  
  6.  

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
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Guru
cogier is in the usergroup ‘Guru’
Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.

No need. Try this code: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Print GetProgDetails()
  4.  
  5.  
  6. Public Sub GetProgDetails() As String
  7.  
  8.   Dim sText As String = "No executable file found"
  9.   Dim sPath As String = Application.Path &/ Application.Name & ".gambas"
  10.  
  11.   If Exist(sPath) Then sText = Format(Stat(sPath).LastModified, "dd/mm/yyyy hh:nn")
  12.   Return Application.Name & " V" & Application.Version & " Created: - " & sText
  13.  
  14.  

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.
Online now: No Back to the top

Post

Posted
Rating:
#9
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

cogier said

Thanks Bruce I shall try that. Worse case is I just have to changed the date manually.

No need. Try this code: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Print GetProgDetails()
  4.  
  5.  
  6. Public Sub GetProgDetails() As String
  7.  
  8.   Dim sText As String = "No executable file found"
  9.   Dim sPath As String = Application.Path &/ Application.Name & ".gambas"
  10.  
  11.   If Exist(sPath) Then sText = Format(Stat(sPath).LastModified, "dd/mm/yyyy hh:nn")
  12.   Return Application.Name & " V" & Application.Version & " Created: - " & sText
  13.  
  14.  


I have just tried this and I get a error "Unexpected 'Application' in frmSplash.Class:15 any idea what this means
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

Code

' Gambas class file
Public Sub Form_Open()
   Me.labApplicationVersion.Text = "Application Version : " & Application.Version
   getBuildDate
End

Private Sub getBuildDate()
   Dim sText As String = "no "
   Dim spath As String = Application.Path & "/" Application.Name & ".Gambas"  
   If Exist(sPath) Then sPath = Format(Stat(sPath).LastModified, DD dd mmm yyyy)
   Me.labBuildDate.Text = Build Date: " & " sText
End

That is my code from the application
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Guru
cogier is in the usergroup ‘Guru’
OK there is a few things here.

1/. When posting code use the 'gb' button, it's much nicer :D
2/. &/ is a powerful command that sorts out if you need, or don't need, a slash in the path. The following will work sPath = "/usr/" &/ "/bin/" &/ "/amidi"
3/. Dim spath As String = Application.Path & "/" Application.Name & ".Gambas", You changed "gambas" to "Gambas". The file ending is ".gambas"
4/. Me.labApplicationVersion.Text, just labApplicationVersion.Text will do.
5/. If Exist(sPath) Then sPath = Format(Stat(sPath).LastModified, DD dd mmm yyyy). The DD dd mmm yyyy needs to be in inverted commas "DD dd mmm yyyy" and sPath needs to be sText
6/. Me.labBuildDate.Text = Build Date: " & " sText. Again "Me." is not required, and you have got your inverted commas muddled.

Try this: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   labApplicationVersion.Text = "Application Version : " & Application.Version
  4.   getBuildDate
  5.  
  6.  
  7. Private Sub getBuildDate()
  8.  
  9.   Dim sText As String = "no "
  10.   Dim sPath As String = Application.Path &/ Application.Name & ".gambas"
  11.  
  12.   If Exist(sPath) Then sText = Format(Stat(sPath).LastModified, "DD dd mmm yyyy")
  13.   labBuildDate.Text = "Build Date: " & sText
  14.  
Online now: No Back to the top

Post

Posted
Rating:
#13
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Hi Cogier,

Thanks so much for sorting my code I am still finding myself working in VB.net (as I am porting my application across from that to Gambas)

I use to work in VB6 for a long time and then moved to vb.net I should have moved to Gambas then but for some reason I moved to .NET (big mistake) now I am getting my head around Gambas I really like it

on the date side is it possible to have it show like

Monday 1st February 2021 and not Monday 1 February 20201?
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Guru
cogier is in the usergroup ‘Guru’

AndyGable said

…on the date side is it possible to have it show like

Monday 1st February 2021 and not Monday 1 February 20201?

The quick answer is yes, but you need to create the code to do it. Try this: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   labApplicationVersion.Text = "Application Version : " & Application.Version
  4.   getBuildDate
  5.  
  6.  
  7. Private Sub getBuildDate()
  8.  
  9.   Dim sText As String = "no "
  10.   Dim sPath As String = Application.Path &/ Application.Name & ".gambas"
  11.   Dim sOrdinal As String
  12.  
  13.   If Exist(sPath) Then
  14.     sOrdinal = GetOrdinal(Format(Stat(sPath).LastModified, "d"))
  15.     sText = Format(Stat(sPath).LastModified, "dddd d") & sOrdinal & Format(Stat(sPath).LastModified, " mmm yyyy")
  16.   End If
  17.  
  18.   labBuildDate.Text = "Build Date: " & sText
  19.  
  20.  
  21. Public Sub GetOrdinal(sDay As String) As String
  22.  
  23.    Select Case sDay
  24.     Case "1", "21", "31"
  25.       Return "st"
  26.     Case "2", "22"
  27.       Return "nd"
  28.     Case "3", "23"
  29.       Return "rd"
  30.  
  31.   Return "th"
  32.  
  33.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.