Jump to content
Sign in to follow this  
AlmarM

Some small UDF's

Recommended Posts

AlmarM

Hiya,

I don't know if this will become handy for someone someday but...

I thought i'd share these old -and mayby useful- snippets I had made.

Don't mind the messiness please. :stupid:

  • _GetObjClasses - Debugs all current installed object classes
  • _GetNetworkCards - Gets all current installed network cards
  • _GetNetworkProfiles - Gets all network profiles
  • _ArrayAverage - Calculates the average of a 1D Array
  • _ArrayTotal - Calculates the total of a 1D Array

;; Array Example
#include <Array.au3>

Global $myArray[15]

For $i = 0 To 14
    $myArray[$i] = Random(1, 100)
Next

_ArrayDisplay($myArray)

$r = Random(1, 10, 1)
MsgBox(0, "", "Total R:     " & _ArrayTotal($myArray, 0, 1) & @CRLF & _
        "Total UR:      " & _ArrayTotal($myArray) & @CRLF & _
        "Average R: " & _ArrayAverage($myArray, 1) & @CRLF & _
        "Average UR:    " & _ArrayAverage($myArray))

; ============================================================

;; Other Examples
_GetObjClasses()
MsgBox(0, "", "Watch the SciTE console.")

$NetworkCards = _GetNetworkCards()
$NetworkProfiles = _GetNetworkProfiles()

_ArrayDisplay($NetworkCards, "Network Cards")
_ArrayDisplay($NetworkProfiles, "Network Profiles")

; #FUNCTION # =======================================================
; Name............; _GetObjClasses
; Description.....; Debugs all current installed Object classes
; Syntax..........; -
; Parameters......; -
; Return Values...; 1 | Succes
; Author..........; AlmarM (Almar Mulder)
; Modified........; -
; Remarks.........; -
; Related.........; -
; Link............; -
; Example.........; Yes
; ===================================================================
Func _GetObjClasses()
    Local $sReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes"

    For $i = 1 To 9999
        $sReadKey = RegEnumKey($sReg, $i)

        If @error = 0 Then
            If StringLeft($sReadKey, 1) <> "." And StringLeft($sReadKey, 1) <> "*" And StringInStr($sReadKey, ".") Then
                ConsoleWrite("[" & $i & "] " & $sReadKey & @CRLF)
            EndIf
        EndIf
    Next

    Return 1
EndFunc   ;==>_GetObjClasses

; #FUNCTION # =======================================================
; Name............; _GetNetworkCards
; Description.....; Get all current installed network cards
; Syntax..........; -
; Parameters......; -
; Return Values...; Returns a 2D array, first dimenstion is named to the key, second dimenstion is givin the networkcard name
; Author..........; AlmarM (Almar Mulder)
; Modified........; -
; Remarks.........; -
; Related.........; _GetNetworkProfiles
; Link............; -
; Example.........; Yes
; ===================================================================
Func _GetNetworkCards()
    Local $sReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards"
    Local $aReturn[99][99], $iNum = 0

    For $i = 1 To 99
        $sReadKey = RegEnumKey($sReg, $i)

        If @error = 0 Then
            $aReturn[$i - 1][0] = $sReadKey
            $aReturn[$i - 1][1] = RegRead($sReg & "\" & $sReadKey, "Description")

            $iNum += 1
        EndIf
    Next

    ReDim $aReturn[$iNum][2]

    Return $aReturn
EndFunc   ;==>_GetNetworkCards

; #FUNCTION # =======================================================
; Name............; _GetNetworkProfiles
; Description.....; Gets all network profiles
; Syntax..........; -
; Parameters......; -
; Return Values...; Returns a 2D array, first dimenstion is named to the key, second dimenstion is givin the networkprofile name
; Author..........; AlmarM (Almar Mulder)
; Modified........; -
; Remarks.........; -
; Related.........; _GetNetworkCards
; Link............; -
; Example.........; Yes
; ===================================================================
Func _GetNetworkProfiles()
    Local $sReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles"
    Local $aReturn[99][99], $iNum = 0

    For $i = 1 To 99
        $sReadKey = RegEnumKey($sReg, $i)

        If @error = 0 Then
            $aReturn[$i - 1][0] = $sReadKey
            $aReturn[$i - 1][1] = RegRead($sReg & "\" & $sReadKey, "ProfileName")

            $iNum += 1
        EndIf
    Next

    ReDim $aReturn[$iNum][2]

    Return $aReturn
EndFunc   ;==>_GetNetworkProfiles

; #FUNCTION # =======================================================
; Name............; _ArrayAverage
; Description.....; Calculates the average in a 1D array
; Syntax..........; _ArrayAverage(ByRef $Array, $iRound = 0)
; Parameters......;  | $Array - the array it should calculate the average of
;                       | $iRound - change this option to 1 if you want to round the calculated average
; Return Values...; Returns the calculated average, depending on its rounding option
; Author..........; AlmarM (Almar Mulder)
; Modified........; -
; Remarks.........; -
; Related.........; _ArrayTotal
; Link............; -
; Example.........; Yes
; ===================================================================
Func _ArrayAverage(ByRef $Array, $iRound = 0)
    If Not IsArray($Array) Then Return SetError(1, 0, 0)

    Local $aTotal = _ArrayTotal($Array, 1, 1)

    If ($iRound == 0) Then Return ($aTotal[1] / $aTotal[0])
    If ($iRound == 1) Then Return Round(($aTotal[1] / $aTotal[0]), 0)
EndFunc   ;==>_ArrayAverage

; #FUNCTION # =======================================================
; Name............; _ArrayTotal
; Description.....; Calculates the total of a 1D array
; Syntax..........; _ArrayTotal(ByRef $Array, $iOption = 0, $iRound = 0)
; Parameters......;  | $Array - the array it should calculate the average of
;                       | $iOption - change this to 1 if you wish to return the length of the array aswell
;                       | $iRound - change this option to 1 if you want to round the calculated total
; Return Values...; | Returns the calculated total depending on its rounding value
;                       | [0] - if the $iOption parameter has been set to 1, this will be the calculated total
;                       | [1] - same as above, this will be the array length
; Author..........; AlmarM (Almar Mulder)
; Modified........; -
; Remarks.........; -
; Related.........; _ArrayAverage
; Link............; -
; Example.........; Yes
; ===================================================================
Func _ArrayTotal(ByRef $Array, $iOption = 0, $iRound = 0)
    If Not IsArray($Array) Then Return SetError(1, 0, 0)

    Local $iTmp = 0

    For $i = 0 To UBound($Array) - 1
        $iTmp2 = $iTmp
        $iTmp = $Array[$i] + $iTmp2
    Next

    Switch ($iOption)
        Case 0
            If ($iRound == 0) Then Return $iTmp
            If ($iRound == 1) Then Return Round($iTmp, 0)

        Case 1
            Local $aReturn[2]
            $aReturn[0] = UBound($Array)
            If ($iRound == 0) Then $aReturn[1] = $iTmp
            If ($iRound == 1) Then $aReturn[1] = Round($iTmp, 0)

            Return $aReturn
    EndSwitch
EndFunc   ;==>_ArrayTotal
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×