| View previous topic :: View next topic |
| Author |
Message |
cancandodo Advanced Cheater
Reputation: 0
Joined: 09 Mar 2012 Posts: 70
|
Posted: Mon Feb 13, 2023 8:41 am Post subject: how to write listbox's item by Text or clipoard? |
|
|
for ex:
my clipoard's text is
"aa
bb
cc
dd
ee
"
===================
if i use "listbox1.item[0]=readFromClipboard()"
result is
listbox1.item[0]=aabbccddee
i want to paste this text to listbox1
resul↓↓↓↓↓
listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
listbox1.item[4]=ee
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Mon Feb 13, 2023 9:44 am Post subject: |
|
|
This will split the text in the clipboard by space and then add each word to the listbox.
| Code: |
if f then f.destroy(); f = nil end
f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()
l = createListBox(f)
l.Width = f.Width
l.Height = f.Height
function addWordsToList(listbox)
local c = readFromClipboard()
if c == nil then return end
-- Split copied text by space and add each word
-- To the listbox
for w in c:gmatch('([^%s]+)') do
listbox.Items.Add(w)
end
end
addWordsToList(l)
|
|
|
| Back to top |
|
 |
cancandodo Advanced Cheater
Reputation: 0
Joined: 09 Mar 2012 Posts: 70
|
Posted: Mon Feb 13, 2023 10:04 am Post subject: |
|
|
| LeFiXER wrote: | This will split the text in the clipboard by space and then add each word to the listbox.
| Code: |
if f then f.destroy(); f = nil end
f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()
l = createListBox(f)
l.Width = f.Width
l.Height = f.Height
function addWordsToList(listbox)
local c = readFromClipboard()
if c == nil then return end
-- Split copied text by space and add each word
-- To the listbox
for w in c:gmatch('([^%s]+)') do
listbox.Items.Add(w)
end
end
addWordsToList(l)
|
|
this code has a problem
if text inclued blank ,it will be output "enter"
for ex
aa bb
cc dd
i want to
listbox1.item[0]=aa bb
listbox1.item[1]=cc dd
but use this code,the result is
listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Mon Feb 13, 2023 10:30 am Post subject: Re: how to write listbox's item by Text or clipoard? |
|
|
| cancandodo wrote: | for ex:
...
i want to paste this text to listbox1
resul↓↓↓↓↓
listbox1.item[0]=aa
listbox1.item[1]=bb
listbox1.item[2]=cc
listbox1.item[3]=dd
listbox1.item[4]=ee |
I did as you requested, albeit not totally error free.
| Code: |
if f then f.destroy(); f = nil end
f = createForm(getMainForm())
f.Name = 'frmLB'
f.Caption = 'List'
f.Width = 200
f.Height = 250
f.CenterScreen()
l = createListBox(f)
l.Width = f.Width
l.Height = f.Height
function addWordsToList(listbox)
local c = 'aa bb cc dd ee'--readFromClipboard()
if c == nil then return end
-- Split copied text by space and add each word
-- To the listbox
local i = 0
local s = ''
for w in c:gmatch('([^%s]+)') do
if w then
s = s:sub(2,#s) .. ' ' .. w
i = i + 1
end
if i == 2 and s ~= nil then
listbox.Items.Add(s)
s = ''
i = 0
end
end
end
addWordsToList(l)
|
Definitely not the best way to do this, but it works. If the text is blank then the form will be blank naturally.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1533
|
Posted: Tue Feb 14, 2023 8:20 am Post subject: |
|
|
Simple gluing procedure:
| Code: | ClipboardText = [[dd
bb
aa
cc
ee]]
writeToClipboard(ClipboardText)
if UDF1 then UDF1.Destroy() end
UDF1 = createForm()
list1 = createListBox(UDF1)
function TableView(text)
exTbl = {}
sl = createStringList()
sl.Text = text
for i=0, sl.Count -1 do
exTbl[i+1] = sl[i]
end
--sort table a.. z
table.sort(exTbl)
return exTbl
end
list1.OnClick=function()
aa = TableView(readFromClipboard())
for i,k in pairs(aa) do
list1.items[i-1] = k
end
end |
List selection, testing and shortcut option:
| Code: | ClipboardText = [[dd
bb
aa
cc
ee]]
writeToClipboard(ClipboardText)
if UDF1 then UDF1.Destroy() end
UDF1 = createForm()
list1 = createListBox(UDF1)
list1.Name = "list1"
list1.MultiSelect = true
list2 = createListBox(UDF1)
list2.Top = list1.Height + 10
list2.Name = "list2"
local listEx = ""
function TableView(text)
exTbl = {}
sl = createStringList()
sl.Text = text
for i=0, sl.Count -1 do
exTbl[i+1] = sl[i]
end
--sort table a.. z
table.sort(exTbl)
return exTbl
end
list1.OnMouseDown=function() listEx = list1 end
list2.OnMouseEnter=function() listEx = list2 end
function pasteList()
sleep(200)
if listEx=="" then
showMessage("Please click on a list and choose!")
else
answer = messageDialog("Selected list: "..listEx.Name.. ". Do you confirm?", mtWarning, mbYes, mbNo)
if answer == mrYes then
aa = TableView(readFromClipboard())
for i,k in pairs(aa) do
listEx.items[i-1] = k --Clear list and update
end
listEx = ""
end
end
end
if pasteKey1 then pasteKey1.Destroy() pasteKey1=nil end
pasteKey1 = createHotkey(pasteList, VK_CONTROL,VK_V) |
You can choose the suitable one.
If you find it necessary, I can add an option to update (replace) the selected text.
_________________
|
|
| Back to top |
|
 |
|