How to convert multi-row textbox to ListBox

Source: Internet
Author: User

 

How to convert multi-row textbox to ListBox

Old strange answer:

This solution focuses on the broken lines in Textbox, which must be combined by CHR (13) + CHR (10). Therefore, CHR (13) should be used as the cutting judgment point:

Dim allstring as string
Dim singlestring as string
Dim sepstring as string
Dim I as long
Allstring = text1.text

For I = 1 to Len (allstring)
Singlestring = mid (allstring, I, 1)
If singlestring = CHR (13) then
'When CHR (13) is encountered, the split string is added to the ListBox.
List1.additem sepstring
Sepstring = ""
Else
If singlestring <> CHR (10) then
'Add the CHR (10) word by word to the sepstring
Sepstring = sepstring + singlestring
End if
End if
Next
'Add the last sepstring
List1.additem sepstring

Comments from CWW:

Split multi-line Textbox, which is limited to multiline textbox with keyin enter to wrap. If keyin does not wrap all the time under multiline, it is reached to the rightmost of textbox.
After the edge, the keyin word will be folded and changed to another line, which cannot be solved. Please check
Htmapi101.htm.

 

 

Returns the string of a row of textbox.
Source: CWW

This is done using em_getline message. What is more strange is that lparam points to the position of a string,
However, when the string is written, the first two bytes must store the maximum length allowed by the string.

'The following form requires a textbox and sets multiline = true, and a command buttonprivate sub commandemediclick () dim str5 as stringstr5 = getaline (text1, 1) 'Get the string of the second line, with 0 as the base end sub 'and below. basoption explicit const em_getline = & hc4 declare function sendmessage lib "USER32" alias "sendmessagea" _ (byval hwnd as long, byval wmsg as long, byval wparam as long, _ lparam as any) as long public function getaline (text1 as Textbox, byval NTX as long) as string dim str5 (255) as byte 'If your string> 255 bytes, add the byte array dim str6 as string, I as long str5 (0) = 255 'maximum length of the first two bytes of the string str5 (0) = 255 I = sendmessage (text1.hwnd, em_getline, NTX, str5 (0 )) if I = 0 then getaline = "" else str6 = strconv (str5, vbunicode) getaline = left (str6, instr (1, str6, CHR (0)-1) end if end Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.