Queener

count fields that contain string

8 posts in this topic

#1 ·  Posted (edited)

I have 14 fields and I was wondering is there an easier way to count the fields that contain Child?

If guictrlread($textbox1) = "Child" then
$xcountchild = $xcountchild + 1
endif

etc...

So those are my current codes, but is there an easier way to could?

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



How do you set this variables?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

$textbox1, $textbox2, etc... for textboxes

$xcountchild is to call all variables that the textboxes contain the string child.


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

I mean: Do they get set using a GUI?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

yes. I also fixed my code during reading the textbox lol

 

I tried, but it's not working because I would think I needed to declare it as an object.

 

$x = 0
    
    For $x = 0 To 14
      If guictrlread($InputName($x)) = "Child" Then
        $xchild = $xchild + $x
        
      EndIf
    Next
    MsgBox(0, "", $xchild)

 

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

Assign the IDs returned from GUICtrlCreate* to an array and then loop thorugh this array doing a GUICtrlRead one each ID.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Queener,

See if this makes sense...

#include <StaticConstants.au3>
#include <GuiConstantsEx.au3>

Local $gui010 = GUICreate('Find ""Child""',200,500)

Local $inputname[14]

For $1 = 0 To 13
    $inputname[$1] = GUICtrlCreateLabel('', 10, $1 * 30 + 10, 90, 20, $SS_SUNKEN)
Next

For $1 = 0 To Random(0, UBound($inputname) - 1, 1)
    GUICtrlSetData($inputname[$1], 'Child')
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            ExitLoop
    EndSwitch
WEnd

Local $xchild

For $x = 0 To 13
    If GUICtrlRead($inputname[$x]) = "Child" Then ; <--- you were using $inputname as a function, use it as an array
        $xchild += 1
    EndIf
Next
MsgBox(0, "", $xchild)

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Wow, exactly what I'm looking for... My 60 lines became less than 12 lines. LoL

 

Thanks for the help. Much appreciated.

 

 

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

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