[Gambas-user] Example script on Gambaswiki fails (GetUsedMemory) - needs Clong

Peter Bauer pebauer68 at gmail.com
Wed Feb 5 12:50:44 CET 2020


Hello,
http://gambaswiki.org/wiki/doc/whatisgambas?nh
http://gambaswiki.org/wiki/doc/whatisgambas?nh#t4
Gambas 3.14 output:
MMain.GetUsedMemory.14: #6: Type mismatch: wanted Integer, got String
instead MMain.GetUsedMemory.14 MMain.Main.23

While I do not fully understand the Type mismatch (got String !?, really ?).
-When I replace Cint(aRes[1]  with  CLong(aRes[1]) it works again.

Used memory: 265040 Kb /* Output checked on Gambas Playground for stable
and daily
Who could please update the script on Gambaswiki ?

Scripting with Gambas is nice and gets the job done with good performance.
Just wrote a  script for testing connectivity, hopefully its useful.
https://github.com/pebauer68/scripts/blob/master/networkcheck

Best Regards, Peter

Working Script:
Function GetUsedMemory() As Integer

  Dim sRes As String
  Dim aRes As String[]
  Dim cVal As New Collection
  Dim sVal As String

  Exec ["cat", "/proc/meminfo"] To sRes

  For Each sVal In Split(sRes, "\n", "", True)
    aRes = Split(sVal, " ", "", True)
    cVal[Left$(aRes[0], -1)] = *CLong(aRes[1])*
  Next

  Return cVal!MemTotal - cVal!MemFree - cVal!Buffers - cVal!Cached +
cVal!SwapTotal - cVal!SwapFree - cVal!SwapCached

End

Print Subst("Used memory: &1 Kb", GetUsedMemory())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200205/be86d72e/attachment.html>


More information about the User mailing list