Jump to content
Sign in to follow this  
kor

[SOLVED] Why doesn't a function ignore an optional parameter if it isn't there?

Recommended Posts

kor

My example is _GuiCtrlCreateProgress

Func _Message($sMessage, $bError = 0, $iBarCount = "")
    _GUICtrlListBox_InsertString($hProgress, $sMessage, -1)
    Local $iCount = _SendMessage($hProgress, 0x18B, 0, 0) ; get count
    _SendMessage($hProgress, 0x197, $iCount - 1, 0) ; scroll to correct line
    If $bError = False Then
        $iBarCount += 5 ; step the precentage
        GUICtrlSetData($hBar, $iBarCount) ; set the progress bar percentage
        Sleep(200) ; sleep to allow time to see progress step and read messages
    EndIf
EndFunc   ;==>_Message

This function (among other things) steps the progress bar percentage by 5 every time it is called. However there are certain times when calling this function that I'd like to set the progress bar percentage to an exact value.

When calling this function with the current parameters I get this

_Message("step 1", False, 25)
                _Message("step 2", False, 55)
                _Message("testing")

When step 1 and step 2 run they correctly set the progress percentage to the value in the function (25 and 55 respectivly) however when testing runs it resets the progress bar back to 0. Any idea why?

The behavior I am looking for is that if I specify the percentage when calling the function I want to specifically set the progress bar to that value, otherwise I want the progress bar to add 5 to whatever the last value was.

IE, the progress percentage should be at 60 when "testing" runs, yet it is actually at 5.

Edited by kor

Share this post


Link to post
Share on other sites
jchd

Default = 0 but you test for False. They are not the same, see help Language Reference > Datatypes


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
MilesAhead

Not quite sure what you're doing but $iBarCount is set to "" if not specified. Later in the function you += 5 to it. Seems like you are incrementing "" by 5. Also it's not a ByRef param so it's not holding value between calls. It may just be simpler to use a global to hold the percentage and increment that outside the function. Just send in the percentage you want instead of incrementing. It should work either way as long as you keep track of the value somewhere.

Share this post


Link to post
Share on other sites
kor

Func _Message($sMessage, $bError = False, $iBar = 0)
    _GUICtrlListBox_InsertString($hProgress, $sMessage, -1)
    Local $iCount = _SendMessage($hProgress, 0x18B, 0, 0) ; get count
    _SendMessage($hProgress, 0x197, $iCount - 1, 0) ; scroll to correct line
    If $bError = False Then
        If $iBar <> 0 Then
            $iBarCount = $iBar
        Else
            $iBarCount += 10 ; step the precentage
        EndIf
        GUICtrlSetData($hBar, $iBarCount) ; set the progress bar percentage
        Sleep(2000) ; sleep to allow time to see progress step and read messages
    EndIf
EndFunc   ;==>_Message

My fixed code. I realized I just needed to make 2 different variables to allow me check for the 2 different scenarios I wanted. Thanks.

Share this post


Link to post
Share on other sites
Blue_Drache

It may just be simpler to use a global

No ... bad coder ... no doughnut. That's bad form. Do not use a global. Pass ByRef.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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  

×