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

Gianluigi bagonergi at gmail.com
Wed Feb 5 16:07:47 CET 2020


Hi Peter,

I changed the code to CLong, you could have done it too. :-)

Regards
Gianluigi

Il giorno mer 5 feb 2020 alle ore 12:51 Peter Bauer <pebauer68 at gmail.com>
ha scritto:

> 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())
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200205/90ec473f/attachment.html>


More information about the User mailing list