[Gambas-user] Application.Version of another program

Martín Belmonte mbelmonte at belmotek.net
Thu Dec 9 22:25:43 CET 2021


El 9/12/21 a las 21:28, T Lee Davidson escribió:
> Consider submitting a feature request for that at the Gambas Bugtracker.
> 
> In the meantime, you could implement your own function as below:
> 
> Public Sub Main()
> 
>    Dim rMatch As RegExp
> 
>    rMatch = New RegExp(File.Load("a.gambas"), "Version=(.*)\n")
>    Print rMatch[1].Text
> 
> End

Good idea, it's interesting everything inside the .gambas file isn't it?
Your code led me to think that it can also be solved without loading the 
whole file in the memory (I think) in this way:

Static Public Function GetExecVersion(sExec As String) As String

   Dim sVersion As String
   Dim hFile As Stream
   Dim sLine As String

   If Exist(sExec) Then
     If Stat(sExec).Type = gb.File Then
       If File.Ext(sExec) = "gambas" Then
         hFile = Open sExec For Input
         While Not Eof(hFile)
           Line Input #hFile, sLine
           If InStr(sLine, "Version=") > 0 Then
             sVersion = Split(sLine, "=")[1]
             Break
           Endif
         Wend
         Close #hFile
       Endif
     Endif
   Endif

   Return sVersion

End

All the best
Martín


More information about the User mailing list