Jump to content
Sign in to follow this  
yxrkt

GuiCtrlEditGetLine() problems.

Recommended Posts

yxrkt

When i use guictrleditgetline in my scripts it dosnt return the entire line.

anyone else with this problem.

or is it just me or my computer ? :)

#Include <GuiEdit.au3>
GuiCreate('',260,260)
$h_edit = guictrlcreateedit('First line lala'&@CRLF&"Second line lala"&@CRLF&"Third line lala",1,1,250,250)
guisetstate()
$totlines = _GUICtrlEditGetLineCount ( $h_edit )
for $i = 0 to $totlines
    msgbox(0,'',_GUICtrlEditGetLine($h_edit, $i))
Next

post-21466-1178713644_thumb.jpg

Share this post


Link to post
Share on other sites
Azazel

you are right yxrkt, it seems there is a bug in this function :D

it seems that the size of the line you read depend of the last one

as you can see if you add 2 spaces after "Third line lala " the second line is displayed correctly

very strange :)

#Include <GuiEdit.au3>
GuiCreate('',260,260)
$h_edit = guictrlcreateedit('First line lala'&@CRLF&"Second line lala"&@CRLF&"Third line lala  ",1,1,250,250)
guisetstate()
$totlines = _GUICtrlEditGetLineCount ( $h_edit )
for $i = 0 to $totlines
    msgbox(0,'',_GUICtrlEditGetLine($h_edit, $i))
Next

Share this post


Link to post
Share on other sites
PsaltyDS

Yeah. Bug for Gary to work on. I modded the demo so I could see multiple results and with Prod It clips the last character off the second line. With Beta 3.2.3.6 it only gives 8 characters on every line, and in Beta 3.2.3.14 we're back to clipping the last character of the the second line:

#include <guiconstants.au3>
#Include <GuiEdit.au3>
GUICreate('', 260, 305)
$h_edit = GUICtrlCreateEdit('1st line.' & @CRLF & "Second line lalalala" & @CRLF & "Third line lalalala", 5, 5, 250, 250)
$h_butt = GUICtrlCreateButton('SHOW', 105, 265, 50, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $h_butt
            $totlines = _GUICtrlEditGetLineCount($h_edit)
            $Text = ""
            For $i = 1 To $totlines
                $Text &= "Line:" & $i & @TAB & _GUICtrlEditGetLine($h_edit, $i) & @CRLF
            Next
            MsgBox(0, 'Demo', $Text)
    EndSwitch
WEnd

:D

Edit: This is listed as a Bug Report (Fixed), but curiously the thread was closed on news it was GOING to be fixed, not that it already was... :)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
SmOke_N

Does this give the output you want?

#include <guiconstants.au3>
#Include <GuiEdit.au3>
GUICreate('', 260, 305)
$h_edit = GUICtrlCreateEdit('1st line.' & @CRLF & "Second line lalalala" & @CRLF & "Third line lalalala", 5, 5, 250, 250)
$h_butt = GUICtrlCreateButton('SHOW', 105, 265, 50, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $h_butt
            $totlines = _GUICtrlEditGetLineCount($h_edit)
            $Text = ""
            For $i = 1 To $totlines
                $Text &= "Line:" & $i & @TAB & _GUICtrlEditGetLine_Debug($h_edit, $i) & @CRLF
            Next
            MsgBox(0, 'Demo', $Text)
    EndSwitch
WEnd

Func _GUICtrlEditGetLine_Debug(ByRef $h_Edit, $i_line)
    Local $i_index = _GUICtrlEditLineIndex($h_Edit, $i_line)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $length = _GUICtrlEditLineLength($h_Edit, $i_index - 1);Changed from _GUICtrlEditLineLength($h_Edit, $i_index)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $struct_Buffer = DllStructCreate("short;char[" & $length + 2 & "]")
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    DllStructSetData($struct_Buffer, 1, $length, 1)
    If IsHWnd($h_Edit) Then
        _SendMessage($h_Edit, $EM_GETLINE, $i_line - 1, DllStructGetPtr($struct_Buffer))
        If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Else
        GUICtrlSendMsg($h_Edit, $EM_GETLINE, $i_line - 1, DllStructGetPtr($struct_Buffer))
        If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    EndIf
    Local $struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))    
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Return DllStructGetData($struct_String, 1)
EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
PsaltyDS

Does this give the output you want?

Nope. Works correctly with Prod, fails with Beta 3.2.3.14. First and second line showed first eight characters only, third line one less than that.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
SmOke_N

Nope. Works correctly with Prod, fails with Beta 3.2.3.14. First and second line showed first eight characters only, third line one less than that.

:D

:D I'm a little behind on my betas (works with 3.2.3.2 :) )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
GaryFrost

Try this one

Func _GUICtrlEditGetLine(ByRef $h_Edit, $i_line)
    If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $i_index = _GUICtrlEditLineIndex($h_Edit, $i_line - 1)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $length = _GUICtrlEditLineLength($h_Edit, $i_index)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $struct_Buffer = DllStructCreate("short;char[" & $length + 2 & "]")
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    DllStructSetData($struct_Buffer, 1, $length, 1)
    If Not IsHWnd($h_Edit) Then $h_Edit = GUICtrlGetHandle($h_Edit)
    Local $v_ret = DllCall("user32.dll", "int", "SendMessageA", "hwnd", $h_Edit, "int", $EM_GETLINE, "int", $i_line - 1, "ptr", DllStructGetPtr($struct_Buffer))
    If $v_ret[0] = $EC_ERR Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Return DllStructGetData($struct_String, 1)
EndFunc   ;==>_GUICtrlEditGetLine

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
PsaltyDS

Where is _IsClassName()???

:)

Edit: Oops... downloaded 3.2.4.1 and I have _IsClassName() now.

The GuiEdit.au3 included with 3.2.4.1 still causes the same problem, but I renamed the one you just posted to _GUICtrlEditGetLineBet() so it wouldn't conflict with the one in the include file, and it worked!

#include <guiconstants.au3>
#Include <GuiEdit.au3>
GUICreate('', 260, 305)
$h_Edit = GUICtrlCreateEdit('1st line.' & @CRLF & "Second line lalalala" & @CRLF & "Third line lalalala", 5, 5, 250, 250)
$h_butt = GUICtrlCreateButton('SHOW', 105, 265, 50, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $h_butt
            $totlines = _GUICtrlEditGetLineCount($h_Edit)
            $Text = ""
            For $i = 1 To $totlines
                $Text &= "Line:" & $i & @TAB & _GUICtrlEditGetLineBeta($h_Edit, $i) & @CRLF
            Next
            MsgBox(0, 'Demo', $Text)
    EndSwitch
WEnd

Func _GUICtrlEditGetLineBeta(ByRef $h_Edit, $i_line)
    If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $i_index = _GUICtrlEditLineIndex($h_Edit, $i_line - 1)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $length = _GUICtrlEditLineLength($h_Edit, $i_index)
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $struct_Buffer = DllStructCreate("short;char[" & $length + 2 & "]")
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    DllStructSetData($struct_Buffer, 1, $length, 1)
    If Not IsHWnd($h_Edit) Then $h_Edit = GUICtrlGetHandle($h_Edit)
    Local $v_ret = DllCall("user32.dll", "int", "SendMessageA", "hwnd", $h_Edit, "int", $EM_GETLINE, "int", $i_line - 1, "ptr", DllStructGetPtr($struct_Buffer))
    If $v_ret[0] = $EC_ERR Then Return SetError($EC_ERR, $EC_ERR, "")
    Local $struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError($EC_ERR, $EC_ERR, "")
    Return DllStructGetData($struct_String, 1)
EndFunc   ;==>_GUICtrlEditGetLineBeta

:D

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×