Jump to content

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


kor
 Share

Recommended Posts

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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...