Jump to content

Enter text string longer than 256 characters in InputBox?


Recommended Posts

I control my Autoit script with a handheld QR-code reader, that contains specific commands in the text. It enters these as one text string (like keyboard entry) and then presses ENTER.

 

The problem I have is, that the text is longer than 256 characters, so InputBox truncates it. Is there a way to extend the limit or ose another form of entry, without having to enter fragments of the text separately (which the barcode reader can not do)?

Link to comment
Share on other sites

16 minutes ago, Evolutionnext said:

The problem I have is, that the text is longer than 256 characters, so InputBox truncates it

Does it have to be an InputBox, or would  GUICtrlCreateInput  also be possible ?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Link to comment
Share on other sites

I don't seem to have the 256 char limit; seems to be about 30000 characters. 

What version of AutoIt are you using?  Are you able to post a reproducer script so we can take a look?

 

Link to comment
Share on other sites

At least in version 3.3.14.0 , which I (still) use, characters will be truncated.

Local $sAnswer = InputBox("Input :", "QR-Code-Reader :", "", "", 600, 150)

; String to paste :
 ;1111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222233333333333333333333333333333333333333333333333333444444444444444444444444444444444444444444444444445555555555555555555555555555555555555555555555555566666666666666666666666666666666666666666666666666777777777777777777777777777777777777777777777777778888888888888888888888888888888888888888888888888899999999999999999999999999999999999999999999999999

MsgBox(4096, "InputBox Result :", $sAnswer)
ConsoleWrite($sAnswer & @CRLF)
ConsoleWrite("Length Answer = " & StringLen($sAnswer) & @CRLF)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

As just wrote Musashi, the resulting string returned by InputBox is truncated when too long.
You can probably type thousands of characters in the InputBox (I pasted 50 times "1234567890 " which is 50*11 length because of the space I added to separate the blocks, so it was 550 characters typed) and they where all in the box when controlling them (ctrl + right key moved from one block to the other, stop at 49, manually controlled the last one was 50th)

But look at the result after validation :

1147269144_MaxlengthreturnedbyInputboxis255.png.99cfd02bf11f312d5d6ab51fc64c3037.png

So max returned seems to be 255 (not 256 as stipulated by OP or 254 as read in the help file)
ConsoleWrite also indicates 255. Tested on AutoIt 3.3.14.5  &  3.3.16.0

ConsoleWrite(">> StringLen($sResult) = " & StringLen($sResult) & @crlf)
>> StringLen($sResult) = 255

 

Edited by pixelsearch
Link to comment
Share on other sites

43 minutes ago, pixelsearch said:

So max returned seems to be 255 (not 256 as stipulated by OP or 254 as read in the help file)

Yes, I can confirm that as well :).

Since you also tested it with the latest versions of AutoIt, I am a bit surprised that @spudw2k wrote :

5 hours ago, spudw2k said:

I don't seem to have the 256 char limit; seems to be about 30000 characters.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Moderators

Hi,

Have you tried using _GUICtrlEdit_SetLimitText to set a higher limit? An input control is just a single-line edit control.

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

Hi M23,
Great idea. Let me try that on an InputBox, especially I already tried it successfully since 2018 in an edit control in RegExpQuickTester (LazyCat + w0uter + mLipok for preventing CPU overheat) :

; 26 dec 2018 : replaced GUICtrlSendMsg($ebTest, $EM_LIMITTEXT, -1, 0) from 5 nov 2018, with _GUICtrlEdit_SetLimitText($ebTest, -1)

; GUICtrlSendMsg($ebTest, $EM_LIMITTEXT, -1, 0)   ; added to allow unlimited text size in edit control : ini file won't store this control anymore, a separate txt file will.
_GUICtrlEdit_SetLimitText($ebTest, -1) ; 26 dec 2018, seems better than precedent

 

Link to comment
Share on other sites

I tried M23's idea with no success : how to retrieve the InputBox handle when InputBox is a blocking function ?

I couldn't use AdlibRegister for that reason. As _GUICtrlEdit_SetLimitText requires a Control ID/Handle, it didn't work for me. Maybe someone will have another idea, that would be great !

The solution is probably to forget InputBox and use an input control, as suggested in several preceding posts.

Edited by pixelsearch
Link to comment
Share on other sites

16 minutes ago, pixelsearch said:

I tried M23's idea with no success : how to retrieve the InputBox handle when InputBox is a blocking function ?

I couldn't use AdlibRegister for that reason. As _GUICtrlEdit_SetLimitText requires a Control ID/Handle, it didn't work for me. Maybe someone will have another idea, that would be great !

The solution is probably to forget InputBox and use an input control, as suggested in several preceding posts.

I came to the same conclusion but was not brave enough to write it :lol:. With controls like GUICtrlCreateInput you have a handle/controlID and can use _GUICtrlEdit_SetLimitText without problems. With InputBox this corresponding access is missing (but I don't want to exclude that experts know a workaround for this).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Moderators

Hi,

Quote

I came to the same conclusion but was not brave enough to write it

Do not be afraid to say something in these cases - I am neither omniscient nor prone to retaliation!

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

Based on Martin's script, 330 char's returned, but well... not sure it's worthwhile to complicate it like this, when a simple input control would do it without timers & the whole register gang :

; Based on Martin's script :
; https://www.autoitscript.com/forum/topic/71070-inputbox-tecting-changes/?tab=comments#comment-520293

Global $answer2
Local $handle = DllCallbackRegister("_ReadIPBox", "int", "")
Local $SetTimer = DllCall("User32.dll", "int", "SetTimer", _
    "hwnd", 0, "int", 0, "int", 500, "ptr", DllCallbackGetPtr($handle))[0]

Local $answer = InputBox("Question", "Where were you born?", "Planet Earth")

DllCallbackFree($handle)
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $SetTimer)

MsgBox(0, "InputBox 'fake return' (len = " & StringLen($answer2) & ")", $answer2)

;================
Func _ReadIPBox()
    If WinExists("Question") Then
        $answer2 = ControlCommand("Question","Where were you born?","Edit1","GetLine", 1)
        ; ConsoleWrite($answer2 & @CRLF)
    EndIf
EndFunc

1339697007_Inputboxfakereturnlongerthan255chars.png.1fecc97182fe7cd6222fac3f57524d74.png

Edited by pixelsearch
Link to comment
Share on other sites

Here another way to interact with an input box :

#include <WinAPISys.au3>
#include <GuiEdit.au3>
#include <WinAPIConstants.au3>
#include <WinAPIProc.au3>

Example()

Func Example()
  Local $hProc = DllCallbackRegister(CbtHookProc, "int", "int;int;int")
  Global $hHook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProc), 0, _WinAPI_GetCurrentThreadId())
  Local $iRet = InputBox("Test", "Test")
  ConsoleWrite(StringLen($iRet) & @CRLF)
  _WinAPI_UnhookWindowsHookEx($hHook)
  DllCallbackFree($hProc)
EndFunc   ;==>Example

Func CbtHookProc($nCode, $wParam, $lParam)
  If $nCode = 5 Then ; 5=HCBT_ACTIVATE
    $hWnd = HWnd($wParam)
    ControlSetText($hWnd, "", "Static1", "Cooler stuff here")
    ControlSetText($hWnd, "", "Button1", "Alright now")
    ControlSetText($hWnd, "", "Button2", "Forget it !")
    $hCtrl = ControlGetHandle($hWnd, "", "Edit1")
    ConsoleWrite($hWnd & "/" & $hCtrl & @CRLF)
    _GUICtrlEdit_SetLimitText($hCtrl, 500)     ; does not work
  EndIf
  Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>CbtHookProc

As you can see, we can modify pretty much everything we want, except the text limit (although the informations are exact as per au3info ).  Which makes me say, that AutoIt truncates it to 255 characters (maybe because of its buffer size).  It is in fact 256 (not 255) because you need to have a chr(0) at the end. ;)

Link to comment
Share on other sites

That's impressive, bravo Nine :)
I've never been "hooked" on this hook chain (it seems complicated !) but see how it allows to do great things in your script. I really should try it on some personal examples.

If I got it right, it's not Jon's limitation, but that limitation of 255 chars seem to come directly from Microsoft InputBox, see what their link indicates concerning InputBox :

The text box accepts only 255 characters. The return string is truncated to 254 characters

Strange MS indicates 254 characters too, when all tests return 255 valid chars (as in my very 1st pic far above)

Edited by pixelsearch
Link to comment
Share on other sites

Yes you are right, that is a MS limitation (sorry AutoIt). 

Hooks are quite fun.  You can achieve many things very elegantly since it based on event notifications. 

In fact, I just tested another way, very cool result (using your previous idea)

Func CbtHookProc($nCode, $wParam, $lParam)
  If $nCode = 5 Then ; 5=HCBT_ACTIVATE
    $hWnd = HWnd($wParam)
    ControlSetText($hWnd, "", "Static1", "Cooler stuff here")
    ControlSetText($hWnd, "", "Button1", "Alright now")
    ControlSetText($hWnd, "", "Button2", "Forget it !")
    $hCtrl = ControlGetHandle($hWnd, "", "Edit1")
    ConsoleWrite($hWnd & "/" & $hCtrl & @CRLF)
    _GUICtrlEdit_SetLimitText($hCtrl, 500)     ; does not work
  ElseIf $nCode = 4 Then ; HCBT_DESTROYWND
    $hWnd = HWnd($wParam)
    ConsoleWrite(StringLen(ControlGetText($hWnd, "" ,"Edit1")) & @CRLF) ; works perfect when user clicks OK
  EndIf
  Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>CbtHookProc

:)

Edited by Nine
Link to comment
Share on other sites

18 hours ago, pixelsearch said:

Maybe he didn't test the return value, but only the fact he could paste much more than 255 in the box ?

He'll tell us... maybe :)

Ah, yes.  I assumed the limitation with filling the edit control.  The result is indeed truncated to 255 characters.  Interesting behavior.  ControlGetText and _GUICTrlEdit_GetText seem to work fine.  I wonder what method is being used to return the value.

image.thumb.png.da7576ba289ae7b11bca4c797bafa8f9.png

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