Jump to content

Select Item in Listview


 Share

Recommended Posts

My attached script is simply adds items to a listview.  There are two combo boxes (both populated) and an input box.

The concept is to be able to use the combo boxes with either key strokes or mouse.

With keystrokes you just start typing and the combo will bring a variable to the top line, you hit the enter key and the cursor advances to the input box and then to the second combo box where upon hitting the enter key the item is added to the listview.  It works.

Second is to use the mouse , drop down the combo, click  and then advance to input box (use enter key for input) then the second combobox and again drop down, select and at that point the item is added to the listview. It works too.

Here is what I have discovered:

Add several items to listview using the keystroke process. Next click on any item in the listview. It gets selected and is in blue. That is the desired outcome as well.

Start program over again and this time add several item using the mouse/click process.  Next click on any item in the listview and nothing is selected or highlighted in blue.

Why?  Why would it work via one process and not the other.  I would like for the select/hightlight to be the same in either case.

 

Thanks in advance for any help or direction. And all the #includes are for everything I will be using but just not now. Still new at this scripting, so it may not be stream lined as the very advanced people, but its what I have at this point.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=f:\Dash Board.exe
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Icon_Add=F:\Dash Board.ico

;<<<<<<<<<<<<<<<<<<<<<<<<
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
;<<<<<<<<<<<<

$MyScript = "Budget Dash Board"; name of the script
If WinExists($MyScript) Then
    MsgBox(16, "Notice", "Only One Instance Allowed ")
    Exit; It's already running
    AutoItWinSetTitle($MyScript)
EndIf


$main = GUICreate("Budget Dash Board", 680, 515, 150, 100)

$combo_b = GUICtrlCreateCombo("", 10, 26, 75, 25)
GUICtrlSetData(-1, "PICK |SHOVEL |ROPE |BOX|TAPE|LUGS")
GUICtrlSetState($combo_b, $GUI_show)

$AEamounts = GUICtrlCreateInput("$$$", 96, 26, 70, 21);
GUICtrlSetState($AEamounts, $GUI_show)

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE))
GUICtrlSetData(-1, "TIM|MIKE|SAM|JOE|BILL")
GUICtrlSetState($hcombo, $GUI_show)

$List1 = GUICtrlCreateListView("", 172, 72, 500, 260, $LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT) ;Spending Log
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($List1, "Vendor ", 230)
_GUICtrlListView_AddColumn($List1, "Category", 90)
_GUICtrlListView_AddColumn($List1, "Amount", 70)
_GUICtrlListView_AddColumn($List1, "Card", 115)
GUICtrlSetFont(-1, 8.5, 700, 0, "Verdana")
GUICtrlSetState($List1, $GUI_enABLE)
GUICtrlSetState($List1, $GUI_show)


$cEnterPressed = GUICtrlCreateDummy();x

Global $listswitch = 1
Global $MMM
Global $NNN
Global $AEmoney
Global $ListDel = String($List1)
Global $fComboSelected = False
Global $tInfo, $fComboActive = False
Global $fComboActive2 = False
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Global $msg
Global $SourceCard
Global $SourceCard2


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")


Global $tInfo, $fComboActive = False
Global $tInfo2, $fComboActive2 = False

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)
$hEdit = DllStructGetData($tInfo, "hEdit")

_GUICtrlComboBox_GetComboBoxInfo($combo_b, $tInfo2)
$hEdit2 = DllStructGetData($tInfo2, "hEdit")

GUISetState()

While 1

    $iMsg = GUIGetMsg()

    Switch $iMsg

        Case $GUI_EVENT_CLOSE

            Exit

        Case $GUI_EVENT_PRIMARYUP

            If $fComboActive2 Then
                GUICtrlSetState($AEamounts, $GUI_FOCUS)
            EndIf

            If $fComboActive Then
                If ($AEmoney / $AEmoney) = 1 And GUICtrlRead($combo_b) <> "" And GUICtrlRead($hcombo) <> "" Then
                    GUICtrlCreateListViewItem(GUICtrlRead($hcombo) & "|" & $NNN & "|" & $AEmoney, $List1)

                Else
                    _catcher()
                    _aeReset()
                EndIf
                _GUICtrlComboBox_SetCurSel($hcombo, -1)
                _GUICtrlComboBox_SetCurSel($combo_b, -1)
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($hcombo, False)

                _aeReset()


            EndIf

        Case $cEnterPressed

            Switch $listswitch

                Case 1 ;<<<<THREE COLUMN LIST>>>>>>>>

                    $filemode = 1
                    $countit = _GUICtrlListView_GetItemCount($List1) ;used in _aeReset for blanks
                    $aPayeecheck = _GUICtrlComboBox_GetListArray($hcombo)


                    If _WinAPI_GetFocus() = $hEdit2 And GUICtrlRead($combo_b) <> "" Then
                        GUICtrlRead($combo_b)
                        GUICtrlSetData($combo_b, GUICtrlRead($combo_b))
                        GUICtrlSetState($AEamounts, $GUI_FOCUS)

                    EndIf

                    If _WinAPI_GetFocus() = $hEdit And GUICtrlRead($hcombo) Then

                        If ($AEmoney / $AEmoney) = 1 And GUICtrlRead($combo_b) <> "" And GUICtrlRead($hcombo) <> "" Then
                            $value = GUICtrlRead($hcombo)
                            GUICtrlCreateListViewItem(GUICtrlRead($hcombo) & "|" & GUICtrlRead($combo_b) & "|" & GUICtrlRead($AEamounts) & "|" & $SourceCard, $List1)

                        EndIf


                    EndIf

                    _GUICtrlComboBox_ShowDropDown($hcombo, False)
                    If _GUICtrlListView_GetItemCount($List1) > $countit And $hcombo <> "" Then
                        _aeReset() ; for resetting all fields First Listview to blank in anticipation of the next entry

                    EndIf



            EndSwitch
        Case $AEamounts ;Enter Dollar Amounts For Record

            $AEmoney = GUICtrlRead($AEamounts)

            Switch $listswitch


                Case 1

                    $AEmoney = GUICtrlRead($AEamounts)

                    If ($AEmoney / $AEmoney) = 1 And _IsPressed("0D") Then ; checking for number entry
                        GUICtrlSetState($hcombo, $GUI_FOCUS)
                    EndIf

                    If ($AEmoney / $AEmoney) <> 1 Then
                        MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                        _aeReset() ; for resetting all fields First Listview to blank in anticipation of the next entry
                    Else

                        GUICtrlSetState($hcombo, $GUI_FOCUS)

                    EndIf
            EndSwitch



    EndSwitch
    If _GUICtrlComboBox_GetDroppedState($hcombo) = True Then
        $fComboActive = True
    EndIf

    If _GUICtrlComboBox_GetDroppedState($combo_b) = True Then

        $fComboActive2 = True
    EndIf

WEnd

Func _Edit_Changed($hcombo)
    _GUICtrlComboBox_AutoComplete($hcombo)
    _GUICtrlComboBox_AutoComplete($combo_b)
EndFunc   ;==>_Edit_Changed


Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo)
                Case $combo_b
                    _Edit_Changed($combo_b)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Blanker()

    $blankcount = _GUICtrlListView_GetItemCount($List1)
    For $i = (($blankcount) - 1) To 0 Step -1
        If (_GUICtrlListView_GetItemText($List1, $i)) = "" Then
            _GUICtrlListView_DeleteItem($List1, $i)
        EndIf
    Next
    Sleep(50)
EndFunc   ;==>_Blanker

Func _catcher()

    If GUICtrlRead($hcombo) = "" Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Vendor.   ")
    ElseIf GUICtrlRead($combo_b) = "" Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Category.   ")
    ElseIf $AEmoney = "" Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Amount.   ")
    ElseIf $AEmoney = 0 Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Amount.   ")
    EndIf

EndFunc   ;==>_catcher

Func DoubleClickFunc() ;Deletes Record From Listview

    $DoubleClicked = False
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Local $msgText = _GUICtrlListView_GetItemTextString($ListDel, -1)
    $msgText = StringReplace($msgText, "|", "  ")
    GUICtrlSetState($combo_b, $GUI_FOCUS)
    $statementfile = "" ;commented  out for test
EndFunc   ;==>DoubleClickFunc


Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $List1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _aeReset()
    If _GUICtrlListView_GetItemCount($List1) >= $countit And $hcombo <> "" Then
        $NNN = ""
        GUICtrlSetData($AEamounts, "$$$")
        $AEmoney = 0.0
        GUICtrlSetState($combo_b, $GUI_FOCUS)
        _GUICtrlComboBox_SetCurSel($hcombo, -1)
        _GUICtrlComboBox_SetCurSel($combo_b, -1)
    EndIf
EndFunc   ;==>_aeReset

Hobbyist

 

 

Link to comment
Share on other sites

Thanks but I don't think that is the issue.

First your 

_GUICtrlListView_SetItemFocused

Is not used in my script anywhere and yet when using keystrokes I am able to SELECT(highlight) any item but when using mouse control I am not able.

I have also read some example (in help file) of populating listviews at run time and still have the ability to select/highlight any item and your suggestion is NOT present in the script.

Given the above I am more apt to think it is something I have done within the script.

I like to know the reasons why something is or is not working in order to learn it and use it right.

In the meantime I have noticed under the mouse process, items in the listview can be selected IF I use the secondary mouse(right) button.  So now it is even more confusing to me.

Link to comment
Share on other sites

  • Moderators

Hobbyist,

The ListView does not show the selected item because you have not used the $LVS_SHOWSELALWAYS style. When you use the mouse to select items, the script appears to default to the "$$$" input as focus , thus the ListView will not show the selected item. if you add the style, the selected item remains highlighted (highlit?), albeit in white and not blue.

I will take a deeper look at the code to see if I can solve the focus problem, while retaining the current keyboard/mouse functionality.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hobbyist,

This seems to work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GuiListView.au3>
#include <GUIComboBox.au3>
#include <ColorConstants.au3>

Global $tInfo
Global $listswitch = 1
Global $SourceCard = "SourceCard"
Global $fComboActive_1 = False
Global $fComboActive_2 = False
Global $sComboData_1 = "|PICK|SHOVEL|ROPE|BOX|TAPE|LUGS" ; Note leading |
Global $sComboData_2 = "|TIM|MIKE|SAM|JOE|BILL"
Global $fDoubleClicked = False

$hMain = GUICreate("Budget Dash Board", 680, 515, 150, 100)

$cCombo_1 = GUICtrlCreateCombo("", 10, 26, 75, 25)
GUICtrlSetData($cCombo_1, $sComboData_1)

$cAmounts = GUICtrlCreateInput("$$$", 96, 26, 70, 21) ;

$cCombo_2 = GUICtrlCreateCombo("", 274, 26, 300, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE))
GUICtrlSetData($cCombo_2, $sComboData_2)

$cListView = GUICtrlCreateListView("", 172, 72, 500, 260, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
_GUICtrlListView_SetExtendedListViewStyle($cListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor($cListView, $COLOR_aqua)
_GUICtrlListView_AddColumn($cListView, "Vendor ", 230)
_GUICtrlListView_AddColumn($cListView, "Category", 90)
_GUICtrlListView_AddColumn($cListView, "Amount", 70)
_GUICtrlListView_AddColumn($cListView, "Card", 115)
GUICtrlSetFont(-1, 8.5, 700, 0, "Verdana")

$cEnterPressed = GUICtrlCreateDummy() ;x

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_GUICtrlComboBox_GetComboBoxInfo($cCombo_1, $tInfo)
$hEdit_1 = DllStructGetData($tInfo, "hEdit")
_GUICtrlComboBox_GetComboBoxInfo($cCombo_2, $tInfo)
$hEdit_2 = DllStructGetData($tInfo, "hEdit")

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cEnterPressed
            Switch $listswitch
                Case 1 ;<<<<THREE COLUMN LIST>>>>>>>>
                    Switch _WinAPI_GetFocus()
                        Case $hEdit_1
                            If GUICtrlRead($cCombo_1) <> "" Then
                                GUICtrlSetState($cAmounts, $GUI_FOCUS)
                            EndIf
                        Case $cAmounts
                            If GUICtrlRead($cAmounts) <> "" Then
                                GUICtrlSetState($cCombo_2, $GUI_FOCUS)
                            EndIf
                        Case $hEdit_2
                            If GUICtrlRead($cCombo_2) And _catcher() Then
                                GUICtrlCreateListViewItem(GUICtrlRead($cCombo_2) & "|" & GUICtrlRead($cCombo_1) & "|" & GUICtrlRead($cAmounts) & "|" & $SourceCard, $cListView)
                                _aeReset()
                            EndIf
                    EndSwitch
            EndSwitch

        Case $cAmounts ;Enter Dollar Amounts For Record
            Switch $listswitch
                Case 1
                    If Number(GUICtrlRead($cAmounts)) = 0 Then
                        MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                        _aeReset()
                    Else
                        GUICtrlSetState($cCombo_2, $GUI_FOCUS)
                    EndIf
            EndSwitch
    EndSwitch

    $fComboDrop = _GUICtrlComboBox_GetDroppedState($cCombo_1)
    If $fComboActive_1 = True And $fComboDrop = False Then
        ; Combo closed again
        If GUICtrlRead($cCombo_1) Then
            GUICtrlSetState($cAmounts, $GUI_FOCUS)
        EndIf
        $fComboActive_1 = False
    ElseIf $fComboActive_1 = False And $fComboDrop = True Then
        ; Combo opened
        $fComboActive_1 = True
    EndIf

    $fComboDrop = _GUICtrlComboBox_GetDroppedState($cCombo_2)
    If $fComboActive_2 = True And $fComboDrop = False Then
        ; Combo closed again
        If GUICtrlRead($cCombo_2) And _catcher() Then
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo_2) & "|" & GUICtrlRead($cCombo_1) & "|" & GUICtrlRead($cAmounts) & "|" & $SourceCard, $cListView)
            _aeReset()
        EndIf
        $fComboActive_2 = False
    ElseIf $fComboActive_2 = False And $fComboDrop = True Then
        ; Combo opened
        $fComboActive_2 = True
    EndIf

    If $fDoubleClicked Then
        DoubleClickFunc()
    EndIf

WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            _GUICtrlComboBox_AutoComplete($iIDFrom)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If $wParam = $cListView And DllStructGetData($tagNMHDR, 3) = -3 Then
        $fDoubleClicked = True
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _Blanker()
    $blankcount = _GUICtrlListView_GetItemCount($cListView)
    For $i = (($blankcount) - 1) To 0 Step -1
        If (_GUICtrlListView_GetItemText($cListView, $i)) = "" Then
            _GUICtrlListView_DeleteItem($cListView, $i)
        EndIf
    Next
    Sleep(50)
EndFunc   ;==>_Blanker

Func _catcher()

    If GUICtrlRead($cCombo_2) = "" Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Vendor.   ")
        Return False
    ElseIf GUICtrlRead($cCombo_1) = "" Then
        Return False
        MsgBox($MB_ICONWARNING, "", "   Data Error - Category.   ")
    ElseIf GUICtrlRead($cAmounts) = "" Or GUICtrlRead($cAmounts) = 0 Then
        MsgBox($MB_ICONWARNING, "", "   Data Error - Amount.   ")
        Return False
    EndIf
    Return True

EndFunc   ;==>_catcher

Func DoubleClickFunc() ;Deletes Record From Listview
    $fDoubleClicked = False
    Local $msgText = _GUICtrlListView_GetItemTextString($cListView, -1)
    $msgText = StringReplace($msgText, "|", "  ")

    ConsoleWrite($msgText & @CRLF)

    GUICtrlSetState($cCombo_1, $GUI_FOCUS)
    $statementfile = "" ;commented  out for test
EndFunc   ;==>DoubleClickFunc

Func _aeReset()
    GUICtrlSetData($cCombo_1, $sComboData_1)
    GUICtrlSetData($cCombo_2, $sComboData_2)
    GUICtrlSetData($cAmounts, "$$$")
    GUICtrlSetState($cCombo_1, $GUI_FOCUS)
EndFunc   ;==>_aeReset

Any use?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

Again, thanks for your solution.  YES, this works very very well and performs as desired.

So in an effort to better understand the scripting and learn something I have a question....

Was the basic issue a misapplication, on my part, of $GUI_EVENT_PRIMARYUP and really not needed? Or more than that?

Thanks again 

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Quote

Was the basic issue a misapplication, on my part, of $GUI_EVENT_PRIMARYUP and really not needed?

Not entirely - there are many ways to solve this particular puzzle. Your solution was very nearly working as required - and probably could have been perfected with a bit of effort - but I preferred a different approach where we limit our actions to events on the specific controls involved rather than using the more general $GUI_EVENT_PRIMARYUP event which might well be fired in other circumstances.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

I have one additional question, related to the thread. In your script you have:

If Number(GUICtrlRead($cAmounts)) = 0 Then

Upon executing the script, if the field is typed as (for example) 3.f56 or 35f.6 or 3f.56 the input will be accepted into the listview and viewed as such. But if I correctly read the help section the actual stored results(upon saving) would be different.  In this case the real intentional input would be 3.56 but if any of the three above were mistakenly entered and used in a computation it would have different results. Admittedly my OP did the same thing and I didn't catch it at the time of my question.

The StringRegExpReplace has totally confused me and may not even be the right direction, so I thought I'd ask.

What should I be doing to ensure the above is caught? If I use StringRegExpReplace I not only take out the "f" but also the decimal(which is needed and makes a difference). Basically if any non-numeric character except the . should be flagged.

Thanks and if you need me to start I different thread, let me know and I will oblige.

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Perhaps something like this:

Global $aTest[] = ["3.54", "35.4", "354", "3.f54", "3.542", "3..54"]

For $i = 0 To UBound($aTest) - 1
    ConsoleWrite($aTest[$i] & " - " & StringRegExp($aTest[$i], "^\d+(\.\d{1,2})?$") & @CRLF)
Next

That checks if the entry is a valid 0/1/2-place decimal input - what you would expect for a monetary value. If the test fails, then you can either remove any non-digit characters or, better in my opinion as the non-digit might be a mistype for a real digit, ask the user to re-enter the required value.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23 & Czardas

ask the user to re-enter the required value. "

I believe I was over thinking this. Your(M23) last statement makes the most sense.  I shouldn't try to correct unintentional errors.

Unless I have not understood the function, I should just use Isnumber and if the result is 0, msgbox it back to them for correct input and refocus the inputbox. If your experience says i will run into obstacles, pls let me know.

Thank you both for the answers.  I can see potential future use and now  learned something new.

 

Hobbyist

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