Jump to content
Sign in to follow this  
dreamzboy

List Box Static Word Wrap and Indent

Recommended Posts

I have a list box control that allows me to see the output as the script runs.  Since I control those outputs, I want the message to display neatly inside the list box without scrolling all the way to the right to read the text.  I don't need anything fancy that calculates the length as I can just send a message from a new line.  Sound simple enough but I'm having trouble getting the function to issue @CRLF and indent properly.  I've already read through >this thread but it's not what I was looking for.

This line did not enter a new line.

GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!" & @CRLF & "  Remove white space and/or extra entry before trying again." & @CRLF)

While this line only gave me 1 tab.

GUICtrlSetData ($log_label, @TAB & @TAB & @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)

Also tried the below but no help either.  It complained about the $aTabs.  I declared $aTabs[1] = [100] at the top (commented out) when trying this method.

GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!" & @CRLF)
_GUICtrlListBox_SetTabStops ($log_label, $aTabs)
_GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)

Here's my code.  All you have to do is click on the "Generate" button and you'll see what I mean.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListBox.au3>
#include <array.au3>
#include <constants.au3>

Opt ("TrayIconDebug", 1)

Local $ribcl_temp = '', $xml_temp, $i, $j
Local $hn_input, $ip_input, $pw_input
Local $host_Count, $ip_Count, $pw_Count
Local $msg, $success, $password, $hostname, $ip_address
Local $log_label, $generate_btn, $clrLog_btn
Local $test_str0 = "dl360g7-25" & @CRLF & "dl360g7-26"
Local $test_str1 = "10.112.15.22" & @CRLF & "10.112.15.23" & @CRLF & "10.112.15.24"
Local $test_str2 = "pass1" & @CRLF & "pass2" & @CRLF & "pass3"
;Local $aTabs[1] = [100]

GUICreate ("Test", 600, 450)

GUICtrlCreateLabel ("1.  Enter hostname (ex: dl360g7-25):", 30, 70, 250, 20)
GUICtrlSetFont (-1, 10)
$hn_input = GUICtrlCreateEdit ("", 30, 90, 215, 70)
GUICtrlSetData ($hn_input, $test_str0)
GUICtrlCreateLabel ("2.  Enter iLO static IP address:", 30, 180, 250, 20)
GUICtrlSetFont (-1, 10)
$ip_input = GUICtrlCreateEdit ("", 30, 200, 215, 70)
GUICtrlSetData ($ip_input, $test_str1)
GUICtrlCreateLabel ("3.  Enter iLO default password:", 30, 290, 200, 20)
GUICtrlSetFont (-1, 10)
$pw_input = GUICtrlCreateEdit ("", 30, 310, 215, 70)
GUICtrlSetData ($pw_input, $test_str2)
$log_label = GUICtrlCreateList ("", 300, 90, 270, 292, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL))
$generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 400, 150, 30)
GUICtrlSetFont (-1, 10)
GUICtrlCreateLabel ("version 2.0", 530, 425, 70)
GUICtrlSetColor (-1, 0x0000cd)
$clrLog_btn = GUICtrlCreateButton ("Clear Log", 385, 400, 100, 30)
GUICtrlSetFont (-1, 10)

GUISetState ()

Do
   $msg = GUIGetMsg()

   Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $generate_btn

        ; Check entry simliarity on all fields
        $hostname = StringSplit (GUICtrlRead ($hn_input), @CRLF, 3)
        ;MsgBox (0, "Before", $hostname)
        $hostname = StringStripWS ($hostname, 3)
        ;MsgBox (0, "After", $hostname)
        $host_Count = UBound ($hostname)
        $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3)
        $ip_Count = UBound ($ip_address)
        $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3)
        $pw_Count = UBound ($password)

        If ($host_Count = $ip_Count And $ip_Count = $pw_Count And $host_Count = $pw_Count) Then
            ;Msgbox($mb_ok,'TRUE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  It works!")
            For $i = 0 To $host_Count - 1
                ;MsgBox (0, "", $hostname[$i]
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $hostname[$i] & @CRLF)
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $ip_address[$i] & @CRLF)
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $password[$i] & @CRLF)
            Next
        Else
            ;Msgbox($mb_ok,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!" & @CRLF & "  Remove white space and/or extra entry before trying again." & @CRLF)
            GUICtrlSetData ($log_label, @TAB & @TAB & @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)
        Endif

#cs
        Else
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!")
            MsgBox (48, "Error", "One or more fields does not match!  Please check the entries and try again.")
        EndIf
#ce

        _GUICtrlListBox_UpdateHScroll ($log_label)
        Sleep (1000)

    Case $msg = $clrLog_btn
        GUICtrlSetData ($log_label, "") ; Clear log file
   EndSelect
Until 0

Cheers,

Dreamzboy

Edited by dreamzboy

Share this post


Link to post
Share on other sites

dreamzboy,

Listbox is a single line control - you need to use an Edit control if you want multiple line entries. And if a line is too long for the control you need scrollbars to see it. :)

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

 

Share this post


Link to post
Share on other sites

Doh!  :mad2:

If you can elaborate on how to use these 2 codes, it would do what I need.  I'm mainly interested in getting the tab to work.  I can manually enter a new line by coding another "_GuiCtrlListBox_AddString" or "GuiCtrlSetData".

From the GUICtrlListBox example, the columns are evenly distributed by the tab stop.  I'd like to set up that tab stop.

Edit:  I already have my horizontal and vertical scroll in place and that is working.

_GUICtrlListBox_SetTabStops ($log_label, $aTabs)
_GUICtrlListBox_AddString ($log_label, @TAB & " Remove white space and/or extra entry before trying again." & @CRLF)
Edited by dreamzboy

Share this post


Link to post
Share on other sites

I somewhat figured it out.

I need to declare 4 elements array to be used with _GUICtrlListBox_SetTabStops; however, when that function is called, it looks like this:

Local $aTabs[4] = [3, 30, 0, 0]

_GUICtrlListBox_SetTabStops ($log_label, $aTabs)
_GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC  & "  Error - One or more fields doesn't match!")
_GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry before trying again.")

- Output -

 

Remove white space and/or extra entry before trying again.

12:16:52  Error - One or more fields doesn't match!

I wonder why the order flipped?

Edited by dreamzboy

Share this post


Link to post
Share on other sites

Figured it out.  Here's a working code in case anyone need to refer to it in the future.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListBox.au3>
#include <array.au3>
#include <constants.au3>

Opt ("TrayIconDebug", 1)

Local $ribcl_temp = '', $xml_temp, $i, $j
Local $hn_input, $ip_input, $pw_input
Local $host_Count, $ip_Count, $pw_Count
Local $msg, $success, $password, $hostname, $ip_address
Local $log_label, $generate_btn, $clrLog_btn
Local $test_str0 = "dl360g7-25" & @CRLF & "dl360g7-26" & @CRLF & "dl360g7-27"
Local $test_str1 = "10.112.15.22" & @CRLF & "10.112.15.23" & @CRLF & "10.112.15.24"
Local $test_str2 = "pass1" & @CRLF & "pass2" & @CRLF & "pass3"
Local $aTabs[4] = [3, 29, 0, 0] ; Define your tab stop

GUICreate ("Test", 600, 450)

GUICtrlCreateLabel ("1.  Enter hostname (ex: dl360g7-25):", 30, 70, 250, 20)
GUICtrlSetFont (-1, 10)
$hn_input = GUICtrlCreateEdit ("", 30, 90, 215, 70)
GUICtrlSetData ($hn_input, $test_str0)
GUICtrlCreateLabel ("2.  Enter iLO static IP address:", 30, 180, 250, 20)
GUICtrlSetFont (-1, 10)
$ip_input = GUICtrlCreateEdit ("", 30, 200, 215, 70)
GUICtrlSetData ($ip_input, $test_str1)
GUICtrlCreateLabel ("3.  Enter iLO default password:", 30, 290, 200, 20)
GUICtrlSetFont (-1, 10)
$pw_input = GUICtrlCreateEdit ("", 30, 310, 215, 70)
GUICtrlSetData ($pw_input, $test_str2)
$log_label = GUICtrlCreateList ("", 300, 90, 270, 292, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL, $LBS_USETABSTOPS)) ; Add option $LBS_USETABSTOPS to enable tab stop
$generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 400, 150, 30)
GUICtrlSetFont (-1, 10)
GUICtrlCreateLabel ("version 2.0", 530, 425, 70)
GUICtrlSetColor (-1, 0x0000cd)
$clrLog_btn = GUICtrlCreateButton ("Clear Log", 385, 400, 100, 30)
GUICtrlSetFont (-1, 10)

GUISetState ()

Do
   $msg = GUIGetMsg()

   Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $generate_btn

        ; Check entry simliarity on all fields
        $hostname = StringSplit (GUICtrlRead ($hn_input), @CRLF, 3)
        $host_Count = UBound ($hostname)
        ; MsgBox (0, "", $host_Count)
        $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3)
        $ip_Count = UBound ($ip_address)
        ; MsgBox (0, "", $ip_Count)
        $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3)
        $pw_Count = UBound ($password)
        ; MsgBox (0, "", $pw_Count)

        If ($host_Count = $ip_Count And $ip_Count = $pw_Count And $host_Count = $pw_Count) Then
            ;Msgbox($mb_ok,'TRUE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  It works!")
            For $i = 0 To $host_Count - 1
                ;MsgBox (0, "", $hostname[$i]
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $hostname[$i] & @CRLF)
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $ip_address[$i] & @CRLF)
                GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $password[$i] & @CRLF)
            Next
        Else
            ;Msgbox($mb_ok,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            ;_GUICtrlListBox_SetTabStops ($log_label, $aTabs)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!" & @CRLF)
            _GUICtrlListBox_SetTabStops ($log_label, $aTabs)
            _GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry ")
            _GUICtrlListBox_AddString ($log_label, @TAB & "  before trying again.")
            ;GUICtrlSetData ($log_label, @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)
        Endif

        _GUICtrlListBox_UpdateHScroll ($log_label)
        Sleep (1000)

    Case $msg = $clrLog_btn
        GUICtrlSetData ($log_label, "") ; Clear log file
   EndSelect
Until 0
Edited by dreamzboy

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
    • By TheAutomator
      I'm working on a script that needs to work with a huge database inside a combobox.
      I'm looking for the best way to link a multidimensional array to that data to load that data on to textfields.

      example:
      combo item 0 = "A", data = [index linked to combo item 0] [1,0,5,4,87,9,"xyz"]
      combo item 1 = "B", data = [index linked to combo item 1] [1,6,5,4,87,9,"zzz"]
      combo item 3 = "A", data = [index linked to combo item 3] [1,6,4,4,87,9,"aaa"] ; yes also double items!
      Would also like to be able to delete and add items on the fly btw..
      Local $INDEX[0][10] ; ubound wil be resized like a stack while loading from a textfile ;inside gui: local $Combo = GUICtrlCreateCombo('...', 10, 10, 290, 25) ;gui loop: While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo display() ; how do i link my array index to the combo labels to know what to show in the textfields? ; NOTE: (there are duplicate items in the combobox!) EndSwitch WEnd Any toughs are welcome.
      I was thinking about using _GUICtrlComboBox_GetCurSel($Combo) and use that integer to refer to the index (dimension 1) of the array 
      Thanks, TheAutomator
       
    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules) System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
×
×
  • Create New...