Jump to content

Need functions help (same problem but different func)


au3scr
 Share

Recommended Posts

Hi , I am trying to make function that returns dir size 1-st msgbox (in func) shows right data,but second msgbox (in source it is beforefunc) shows me wrong info, it always shows 0 (zero) how I can make that secont msg box show right information?

$sourcedir = "C:\windows"
                $ProgramSize = 0
                _getsize($sourcedir,$ProgramSize)
                MsgBox(1,1,$ProgramSize)
                
Func _getsize ($sourcedir,$ProgramSize)
$ProgramSize = Round((DirGetSize($sourcedir) / 1024 )/1024,0)
                MsgBox(1,1,$ProgramSize)
                Return $ProgramSize
EndFunc

and How I could use it in If sentences later? i wanna do something like:

IF _getsize() < 30 then

_extraFunc

endif

I have never made any if sentences with funcs. Edited by au3scr
Link to comment
Share on other sites

Local $test

$sourcedir = "C:\"
_getsize($sourcedir, $test)

ConsoleWrite($test)


Func _getsize (ByRef $sourcedir, ByRef $ProgramSize)
    $ProgramSize = Round((DirGetSize($sourcedir) / 1024 )/1024,0)
;~  MsgBox(1,1,$ProgramSize)
;~  Return $ProgramSize
EndFunc

Link to comment
Share on other sites

But whats wrong here? I want that 2nd (in source it is on 1-st place) msgbox show size and location of Microsoft .NET Framework 2.0, but function dont edit variables as needed.

$ProgramSize = "N/A"
$Location = "N/A"
$SizeSourceRegSearch = "Microsoft .NET Framework 2.0"

_getsize($SizeSourceRegSearch,$ProgramSize,$Location)
MsgBox(1,1,$ProgramSize&"   "&$Location )

Func _getsize (ByRef $SizeSourceRegSearch,ByRef $ProgramSize,ByRef $Location)
    MsgBox(1,1,$SizeSourceRegSearch)
            $Keyun = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            $cun = 1
                Do
                    $cun+=1
                    RegEnumKey($Keyun,$cun)
                Until @error
                $answerun = ""
                For $i= 1 to $cun
                $varun = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
                    If @error <> 0 then ExitLoop
                    $var2un = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"DisplayName")
                    $var3un = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"UninstallString")
                    $var4un = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"QuietUninstallString")
                        If $var2un = $SizeSourceRegSearch Then
                        $Location = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"InstallLocation")
                        MsgBox(1,1,$Location)
                        $SizeFromReg = Round (RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"EstimatedSize") / 1024,2)
                        If Not $SizeFromReg = 0 Then
                        $ProgramSize = $SizeFromReg
                        EndIf
                    EndIf
                Next
;~              Return $Location
EndFunc
Link to comment
Share on other sites

  • Developers

You are sure that the registry entry exists?

Did you debug it by checking all returned values into $var2un?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What u mean?This function likely repeat itself until it finds matching "DisplayName" and then it reads "InstallLocation" .

MsgBox(1,1,$Location) on 25th line shows right info but msgbox on 6th line shows wrong info

edit: it shows msgbox on line 25 2 times 1-st time it contains right info, 2nd time dont contain any info

Edited by au3scr
Link to comment
Share on other sites

  • Developers

Ok then it does find it... well when its found you will need to stop the Func and return.

So add a return below the MSGBOX().

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I tried following modification but it dont stop func.but I see MsgBox(1,1,"2nd func"&$Location) 2 times for some reason, and that 2-nd time it goes bad.

If $var2un = $SizeSourceRegSearch Then
                        $Location = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"InstallLocation")
                        MsgBox(1,1,"2nd func"&$Location)
                        $SizeFromReg = Round (RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"&$varun,"EstimatedSize") / 1024,2)
                        If Not $SizeFromReg = 0 Then
                        $ProgramSize = $SizeFromReg
                        ExitLoop
Edited by au3scr
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...