Jump to content

Simple: StringLen(GuiCtrlRead($var))


Recommended Posts

I'm new to this Gui command so maybe I'm missing something basic. Why doesn't this give me StringLen()?

$a=GuiCtrlCreateInput($first,10,50,80,18)

$lena=StringLen(GuiCtrlRead($a))

MsgBox(0,"test",$lena,0)
Edited by myxomatosii
Link to comment
Share on other sites

Sorry.. I should've been more clear..

Its in a window in a working code but the MsgBox always returns 0.

I can't figure out what I'm doing wrong.

I just cut that out for simplicity, I'll include the whole section below.

Func getNames()
    local $first,$second,$third,$fourth,$fifth,$sixth,$seventh,$eighth
    global $a,$b,$c,$d,$e,$f,$g,$h
    GuiCreate("City Names",250,250)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("Please input each of your city names here",10,10)
    GuiCtrlCreateLabel("Please leave any extra boxes blank",10,30)
    GuiCtrlCreateLabel("First City",100,50)
    GuiCtrlCreateLabel("Second City",100,70)
    GuiCtrlCreateLabel("Third City",100,90)
    GuiCtrlCreateLabel("Fourth City",100,110)
    GuiCtrlCreateLabel("Fifth City",100,130)
    GuiCtrlCreateLabel("Sixth City",100,150)
    GuiCtrlCreateLabel("Seventh City",100,170)
    GuiCtrlCreateLabel("Eighth City",100,190)
    $a=GuiCtrlCreateInput($first,10,50,80,18)
    $b=GuiCtrlCreateInput($second,10,70,80,18)
    $c=GuiCtrlCreateInput($third,10,90,80,18)
    $d=GuiCtrlCreateInput($fourth,10,110,80,18)
    $e=GuiCtrlCreateInput($fifth,10,130,80,18)
    $f=GuiCtrlCreateInput($sixth,10,150,80,18)
    $g=GuiCtrlCreateInput($seventh,10,170,80,18)
    $h=GuiCtrlCreateInput($eighth,10,190,80,18)
    $lena=StringLen(GuiCtrlRead($a))
    While 1
        MsgBox(0,"test",$lena,0)
    WEnd
EndFunc
Link to comment
Share on other sites

  • Moderators

myxomatosii,

Look at this code, it should give you a clue:

GUICreate("Test", 200, 200)

$a=GuiCtrlCreateInput("", 10, 10, 80, 20)

GUISetState()

While 1
    If GuiCtrlRead($a) <> "" Then 
        $lena=StringLen(GuiCtrlRead($a))
        MsgBox(0,"test",$lena,0)
        ExitLoop
    EndIf
WEnd

GUICtrlDelete($a)


$b = InputBox("Input", "", "", "", 80, 50)
$lenb=StringLen($b)
MsgBox(0,"test",$lenb,0)

Ask if you have any questions.

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

myxomatosii,

Look at this code, it should give you a clue:

GUICreate("Test", 200, 200)

$a=GuiCtrlCreateInput("", 10, 10, 80, 20)

GUISetState()

While 1
    If GuiCtrlRead($a) <> "" Then 
        $lena=StringLen(GuiCtrlRead($a))
        MsgBox(0,"test",$lena,0)
        ExitLoop
    EndIf
WEnd

GUICtrlDelete($a)


$b = InputBox("Input", "", "", "", 80, 50)
$lenb=StringLen($b)
MsgBox(0,"test",$lenb,0)

Ask if you have any questions.

M23

Ok, so you declared that the input is by default blank space, but when the user changes it that interrupts the "If GuiCtrlRead($a) is not blank Then" statement.

Now I implemented this and it did work, I'm just not seeing much difference in the methodology, from my view both should have worked.

Is it just a format I should learn and accept or is there some logic behind it I am not seeing?

Link to comment
Share on other sites

myxomatosii,

Based on the fragment of html you posted originally (I just saw your post where you are just dumping the source to ini file)

This should work, Try testing it further by setting the $html (variable below) to the clipget() in your full code listing - you can then avoid saving the temp file entirely.

#include <GUIConstants.au3>
#include <array.au3>

Local $html, $aTemp, $aData[1][2], $Value, $City, $I, $J, $K, $Count = 0
$html = '<option class="avatarCities tradegood2" value="123456" selected="selected" title="[91:33]" >New York</option><option class="avatarCities tradegood1" value="7891011" title="[92:32]" >Chicago</option><option class="avatarCities tradegood2" value="121314" title="[91:33]" >Toronto</option><option class="avatarCities tradegood4" value="151617" title="[92:35]" >Boston</option><option class="avatarCities tradegood3" value="181920" title="[92:33]" >Los Angeles</option><option class="avatarCities tradegood1" value="212223" title="[89:34]" >Mexico City</option> </select>'

$aTemp = StringSplit($html, "value=", 1)
For $i = 1 to $aTemp[0]
    $Value = $aTemp[$i]
    $J = StringInStr($Value, '"', 0, 1, 2); Find Position of Second Quote
    $K = StringInStr($Value, "</option>")
    If StringLeft($Value, 1) = '"' AND $J > 0 AND $K > 0 Then
       $City = $Value
       $Value = StringMid($Value, 2, $J - 2)
       $J = StringInStr($City, ">")
       If $J > 0 Then
          $City = StringLeft($City, $K-1)
          $City = StringMid($City, $J+1, 1000)
          If UBound($aData) < $Count + 1 Then ReDim $aData[UBound($aData)+1][2]
         ;Msgbox(0, "City & Values Count=" & $Count, "$City=" & $City & @CRLF & "$Value=" & $Value)
          $aData[$Count][0] = $City
          $aData[$Count][1] = $Value
          $Count = $Count + 1
       EndIf
      EndIf
Next;$i

;_ArrayDisplay($aData, "City Values Array")

$Count = UBound($aData) - 1
$City = ""
For $I = 0 to $Count
    $City = $City & $aData[$I][0] & "|"
Next;$I
$City = StringTrimRight($City, 1)

$Main = GuiCreate("Main GUI", 400, 400, -1, -1)
GuiCtrlCreateLabel("Select City:",10,10)
$CityCombo = GUICtrlCreateCombo("", 80, 10, 100, 20)
GUICtrlSetData(-1, $City)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
           ExitLoop
    Case $CityCombo
         $City = GUICtrlRead($CityCombo)
         $Value = ""
        ; Can use _ArraySearch(...), but this code let's you know what is happening:
         For $I = 0 to $Count
               If $City = $aData[$I][0] Then
                  $Value = $aData[$I][1]
                  ExitLoop
               EndIf
         Next;$I
         Msgbox(0, "Value for City", "City = " & $City & @CRLF & "Value = " & $Value)
   EndSwitch
Wend
Link to comment
Share on other sites

I have one working. If you'd like to create an account on that game and test it, I'm going to try to write a second way of doing it and take the project in two directions. The one you suggested as an alternative to writing the .txt file DaRam. Here is the current WORKING (for me) code.

The current end result should be a MsgBox with the ID's of all of the user's cities which I will be using for the next step of the project.

;AutoItSetOption("TrayIconHide",1)
Func ikalaunch()
    Global $continuebutton,$ikabutton,$msg
    GuiCreate("Ikariam",150,100)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("Please login to Ikariam,",10,10)
    GuiCtrlCreateLabel("click continue once the",10,25)
    GuiCtrlCreateLabel("page is loaded.",10,40)
    $continuebutton=GuiCtrlCreateButton("Continue",10,60,65,20)
    $ikabutton=GuiCtrlCreateButton("www.ikariam.com",10,80,115,20)
    While 1
        $msg=GuiGetMsg()
        Select
            Case $msg=$continuebutton
                GuiSetState(@sw_hide)
                ExitLoop
            Case $msg=$ikabutton
                ShellExecuteWait("www.ikariam.com")
        EndSelect
    WEnd
EndFunc
Func ikasource()
    While 1
        If WinActive("Ikariam - World Alpha ")Then
            BlockInput(1)
            Send("^u")
            WinActivate("Source of: http://")
            Send("^a")
            Sleep(300)
            Send("^c")
            Sleep(300)
            FileWrite("foop.ini",ClipGet())
            WinClose("")
            BlockInput(0)
            ExitLoop
        EndIf
    WEnd
EndFunc
Func readwrite()
;add gui here to get city names
    $cityiduno=StringMid(FileReadLine("foop.ini",351),39+$lena,6)
    $cityiddos=StringMid(FileReadLine("foop.ini",351),141+$lena+$lenb,6)
    $cityidtres=StringMid(FileReadLine("foop.ini",351),224+$lena+$lenb+$lenc,6)
    $cityidcuatro=StringMid(FileReadLine("foop.ini",351),301+$lena+$lenb+$lenc+$lend,6)
    $cityidcinco=StringMid(FileReadLine("foop.ini",351),381+$lena+$lenb+$lenc+$lend+$lene,6)
    $cityidseis=StringMid(FileReadLine("foop.ini",351),465+$lena+$lenb+$lenc+$lend+$lene+$lenf,6)
;$cityidsiete=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityidocho=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityidnueve=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityiddiez=StringMid(FileReadLine("foop.ini",351),48,6)
    MsgBox(0,"Test",$cityiduno&" "&$cityiddos&" "&$cityidtres&" "&$cityidcuatro&" "&$cityidcinco&" "&$cityidseis&".",0)
    FileDelete("foop.ini")
;FileRecycleEmpty("")
EndFunc
Func getNames()
    Global $lena,$lenb,$lenc,$lend,$lene,$lenf,$leng,$lenh
    global $a,$b,$c,$d,$e,$f,$g,$h
    GuiCreate("City Names",250,250)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("Please input each of your city names here",10,10)
    GuiCtrlCreateLabel("Please leave any extra boxes blank",10,30)
    GuiCtrlCreateLabel("First City",100,50)
    GuiCtrlCreateLabel("Second City",100,70)
    GuiCtrlCreateLabel("Third City",100,90)
    GuiCtrlCreateLabel("Fourth City",100,110)
    GuiCtrlCreateLabel("Fifth City",100,130)
    GuiCtrlCreateLabel("Sixth City",100,150)
    GuiCtrlCreateLabel("Seventh City",100,170)
    GuiCtrlCreateLabel("Eighth City",100,190)
    $a=GuiCtrlCreateInput("",10,50,80,18)
    $b=GuiCtrlCreateInput("",10,70,80,18)
    $c=GuiCtrlCreateInput("",10,90,80,18)
    $d=GuiCtrlCreateInput("",10,110,80,18)
    $e=GuiCtrlCreateInput("",10,130,80,18)
    $f=GuiCtrlCreateInput("",10,150,80,18)
    $g=GuiCtrlCreateInput("",10,170,80,18)
    $h=GuiCtrlCreateInput("",10,190,80,18)
    $dbtn=GuiCtrlCreateButton("Done",100,210,60,25)
    While 1
        Local $msg=GuiGetMsg()
        If GuiCtrlRead($a) <> "" Then
            $lena=StringLen(GuiCtrlRead($a))
        EndIf
        If GuiCtrlRead($b) <> "" Then
            $lenb=StringLen(GuiCtrlRead($b))
        EndIf
        If GuiCtrlRead($c) <> "" Then
            $lenc=StringLen(GuiCtrlRead($c))
        EndIf
        If GuiCtrlRead($d) <> "" Then
            $lend=StringLen(GuiCtrlRead($d))
        EndIf
        If GuiCtrlRead($e) <> "" Then
            $lene=StringLen(GuiCtrlRead($e))
        EndIf
        If GuiCtrlRead($f) <> "" Then
            $lenf=StringLen(GuiCtrlRead($f))
        EndIf
        If GuiCtrlRead($g) <> "" Then
            $leng=StringLen(GuiCtrlRead($g))
        EndIf
        If GuiCtrlRead($h) <> "" Then
            $lenh=StringLen(GuiCtrlRead($h))
        EndIf       
        If $dbtn=$msg Then ExitLoop
    WEnd
EndFunc

ikalaunch()
ikasource()
getNames()
readwrite()
Link to comment
Share on other sites

  • Moderators

myxomatosii,

I was trying to point out the fundamental difference between an Input control and an InputBox control.

An Input control does not halt the script. Trying to read it immediately after creation as you did in your first post:

$a=GuiCtrlCreateInput($first,10,50,80,18)
$lena=StringLen(GuiCtrlRead($a))
MsgBox(0,"test",$lena,0)

will obviously return 0 as there is no time for the user to put anything into the Input before it is read. The only way to allow time for the user to enter data is by using a While...WEnd loop ( or something similar) and waiting until the contents meet some predetermined criterion - see my code above.

InputBox, on the other hand, pauses the script until the user is ready before continuing, thus giving unlimited time to enter data into the InputBox. In this case the return value is set to what the user has entered and you will get the StringLen without problem.

I hope that is clearer.

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

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