Jump to content
Sign in to follow this  
au3scr

Need functions help (same problem but different func)

Recommended Posts

au3scr

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

Share this post


Link to post
Share on other sites
Pain

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

Share this post


Link to post
Share on other sites
au3scr

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

Share this post


Link to post
Share on other sites
Jos

You are sure that the registry entry exists?

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

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
au3scr

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
au3scr

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.