Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50085

How To return five different arguments through one function

$
0
0
Hi everyone,

I have found on the web the following VBA Code to return all System Memory Information:

Code:

Type MEMORYSTATUS
  dwLength As Long
  dwMemoryLoad As Long
  dwTotalPhys As Long
  dwAvailPhys As Long
  dwTotalPageFile As Long
  dwAvailPageFile As Long
  dwTotalVirtual As Long
  dwAvailVirtual As Long
End Type

Type SYSTEM_INFO
  dwOemID As Long
  dwPageSize As Long
  lpMinimumApplicationAddress As Long
  lpMaximumApplicationAddress As Long
  dwActiveProcessorMask As Long
  dwNumberOrfProcessors As Long
  dwProcessorType As Long
  dwAllocationGranularity As Long
  dwReserved As Long
End Type
Declare Sub abGlobalMemoryStatus Lib "kernel32" Alias "GlobalMemoryStatus" (lpBuffer As MEMORYSTATUS)

Sub GetSysInfo()
    Dim intMousePresent As Integer
    Dim strBuffer As String
    Dim intLen As Integer
    Dim MS As MEMORYSTATUS
    Dim SI As SYSTEM_INFO


    'Set the length member before you call GlobalMemoryStatus
    MS.dwLength = Len(MS)
    abGlobalMemoryStatus MS
    MsgBox "MemoryLoad" & MS.dwMemoryLoad & "%"
    MsgBox "TotalPhysical" & Format(Fix(MS.dwTotalPhys / 1024), "###,###") & "K"
    MsgBox "AvailablePhysical" & Format(Fix(MS.dwAvailPhys / 1024), "###,###") & "K"
    MsgBox "TotalVirtual" & Format(Fix(MS.dwTotalVirtual / 1024), "###,###") & "K"
    MsgBox "AvailableVirtual" & Format(Fix(MS.dwAvailVirtual / 1024), "###,###") & "K"

End Sub

It works just fine, however I need to develop it to return the results through one function with multiple arguments instead of message boxes as well as Environ Function, for that purpose I tried the following code, but it didn't work at all:

Code:

Function MemoInfo()
    Dim intMousePresent As Integer
    Dim strBuffer As String
    Dim intLen As Integer
    Dim MS As MEMORYSTATUS
    Dim SI As SYSTEM_INFO

    'Set the length member before you call GlobalMemoryStatus
    MS.dwLength = Len(MS)
    abGlobalMemoryStatus MS
   
    MemoInfo(MemoryLoad) = MS.dwMemoryLoad & " %"
    MemoInfo(TotalPhys) = Format(Fix(MS.dwTotalPhys / 1024), "###,###") & " K"
    MemoInfo(AvailPhys) = Format(Fix(MS.dwAvailPhys / 1024), "###,###") & " K"
    MemoInfo(TotalVirtual) = Format(Fix(MS.dwTotalVirtual / 1024), "###,###") & " K"
    MemoInfo(AvailVirtual) = Format(Fix(MS.dwAvailVirtual / 1024), "###,###") & " K"

End Function

I hope that you can help me in this case,

Best Regards,

Viewing all articles
Browse latest Browse all 50085

Trending Articles