Sign in to follow this  
Followers 0
meisandy

Add multiple strings with one statement to a list box by lines.

5 posts in this topic

Hi,

I'm creating my own function at the minute that works with files, arrays and listboxes to search. But I suddenly thought if the function returns more than one result, how do I put all of them in the list view using 1 varible.

So does anyone know how to do that?

Share this post


Link to post
Share on other sites



I'm not sure I'm understanding exactly what you are trying to do (a little code might help), but I would start with string concatenation which can be achieved using the ampersand symbol...

For example this

$newword = "auto" & "it"
MsgBox(0,"The new word is",$newword)

Will result in a message box displaying "autoit"

You can also use variables instead of string literals.

-Aaron

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Okay, I've used quite a complex method but it works

So thanks anyway

EDIT: I'm short on time tonight, so I'll explain it tommorrow!

Edited by DjATUit

Share this post


Link to post
Share on other sites

One way you might add multiple lines to a ListBox:

#Include <GuiListBox.au3>


; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlListBox_AddMultiple
; Description ...: Add multiple strings to a ListBox
; Syntax.........: _GUICtrlListBox_AddMultiple($hWnd, $vText [, $vDelim])
; Parameters ....: $hWnd        - Handle to control
;                  $vText       - String, delimited string, or array that is to be added
;                  $vDelim      - First index to add if $vText is an array, or optional delimiter if $vText is a delimited string
; Return values .: Success      - Zero based index of last string added
;                  Failure      - -1
; Author ........: PsaltyDS @ www.autoitscript.com/forum
; Modified.......:
; Remarks .......: v1.0.0.0 25Aug10
;                  If $vText is a 1D array then $vDelim is the starting index (default 0).
;                  If $vText is a string then $vDelim is the delimiter used in StringSplit to get the items.
;                  If $vText is a string and $vDelim = "" then $vText is a single un-delimited item to add.
;                  If the list box does not have the $LBS_SORT style, the string is added to the end of the list,
;                       otherwise, the string is inserted into the list and the list is sorted.
; Related .......: _GUICtrlListBox_InsertString, _GUICtrlListBox_DeleteString, _GUICtrlListBox_AddFile, _GUICtrlListBox_AddString, _GUICtrlListBox_InitStorage
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlListBox_AddMultiple($hWnd, $vText, $vDelim = "")
    Local $aText, $iRET, $f_Fail = False
    If IsArray($vText) Then
        ; Add array
        $aText = $vText
        $vDelim = Int($vDelim)
    ElseIf $vDelim <> ""
        ; Add delimited string
        $aText = StringSplit($vText, $vDelim, 1+2) ; 1+2 = Entire string is a single delimiter, Return 0-based array
        $vDelim = 0
    Else
        ; Add simple
        Return _GUICtrlListBox_AddString($hWnd, $vText)
    EndIf
    
    For $n = $vDelim To UBound($aText) - 1
        $iRET = _GUICtrlListBox_AddString($hWnd, $aText[$n])
        If $iRET < 0 Then $f_Fail = True
    Next
    
    If $f_Fail Then 
        Return -1
    Else
        Return $iRET
    EndIf
EndFunc

This allows you to pass a delimited string or an array to provide multiple items. Internal to the function, they are still added one at a time, though.

;)


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

#5 ·  Posted (edited)

Hi I did it by dividing each string with "|" in the return of the function;

Then two add them I counted the number of "|" and used 'For...To...Next' to add!

Basically, It works anyway!

Edited by DjATUit

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  
Followers 0