View Full Version : need help
GoOgLe
03-20-2007, 05:01 AM
result1 = Input.GetText("Input1");
result6 = Input.SetSelection("Input1", 1, -1);
if result6 == "" then
Dialog.Message("Notice", "error", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
undot = Input.GetText("Input1");
cbsa1 = ComboBox.GetSelected("ComboBox4");
cbsa = ComboBox.GetItemData("ComboBox4", cbsa1);
Input.SetText("Input1", result1..""..result6.."");
Input.SetText("Input6", "");
end
i tried this code but it didnt work, why??? i just want to color highlighted text in input6.... not all the text in input6.... can someone help please ???
GoOgLe
03-20-2007, 08:29 AM
help help help :o
GoOgLe
03-20-2007, 03:15 PM
is it not possible with input object ????
GoOgLe
03-21-2007, 01:49 PM
Rizlauk can u help me please ????
RizlaUK
03-21-2007, 02:54 PM
ok, your on the right track, but you need to use input.getselected and not input.gettext, to get the text to be highlited
also forget about the 2 inputs, it gets confusing to the user and its a waist of time (i know, i made that mistake 1st time round), use just 1 input and edit the text within it,
you will need to translate the bbcode into html for it to preview, my bbcoder translation script had over 1400 lines of code so im not going to write it for you
heres a little sample of how to add the tags to the text (this is for the bold tag)
--get the selected string position
selString = Input.GetSelection("Input1");
--get the whole text of the input
strText = Input.GetText("Input1");
-- get the text b4 the selection
BeforSelection = String.Mid(strText, 0, selString.Start);
-- get the text after the selection
AfterSelection = String.Mid(strText, selString.End+1, -1);
-- do a little math to get the ammount of charas selected
sel = selString.End-selString.Start
-- get the selected string text
Selection = String.Mid(strText, selString.Start, sel+1);
-- set the text back into the input with the bold tags inplace
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
like iv said b4, this project wasent easy, it took me 3 months to do and i still wasent 100% happy with the results
heres a working example of the code above
RizlaUK
03-21-2007, 03:18 PM
but id say thanks coz you have prompted me to rewrite my bbcoder app, im sure with my experiance gained in the last year i can do a better job of it now :yes
GoOgLe
03-21-2007, 03:28 PM
thanks Rizlauk
thats work perfect
and if u want we can work together for the coder...
just pm me if u want
GoOgLe
03-21-2007, 03:55 PM
Rizlauk
can u help me with color palet ???
GoOgLe
03-21-2007, 04:07 PM
selected = ComboBox.GetSelected("ComboBox3");
if selected == 1 then
cbc = ComboBox.GetItemData("ComboBox3", 1);
selString = Input.GetSelection("Input1");
strText = Input.GetText("Input1");
BeforSelection = String.Mid(strText, 0, selString.Start);
AfterSelection = String.Mid(strText, selString.End+1, -1);
sel = selString.End-selString.Start
Selection = String.Mid(strText, selString.Start, sel+1);
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
end
why the code doesnt work ???
i get error:
On Click, Line6: attempt to index global 'selString (a nill value)'
RizlaUK
03-21-2007, 05:20 PM
the code i posted was pretty raw and had no error checking
you will need to add some "IF" and "ELSE" statments to handle any errors
the error you are getting is because no text in the input is selected so "selString" is returning a error
add a line "if selString ~= nil then"
selected = ComboBox.GetSelected("ComboBox3");
if selected == 1 then
cbc = ComboBox.GetItemData("ComboBox3", 1);
selString = Input.GetSelection("Input1");
if selString ~= nil then
strText = Input.GetText("Input1");
BeforSelection = String.Mid(strText, 0, selString.Start);
AfterSelection = String.Mid(strText, selString.End+1, -1);
sel = selString.End-selString.Start
Selection = String.Mid(strText, selString.Start, sel+1);
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
end
end
also, this is wrong
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
change to this
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
RizlaUK
03-21-2007, 08:42 PM
Hey, how you getting on
Heres a more stable code template for you, you will need Worm's Caret dll to make this code work, search the forum for it
this is for the basic bbcode tags
strText = Input.GetText(MainInput);
cPos=GetCaretPos(MainInput)
selString = Input.GetSelection(MainInput);
if selString ~= nil then
-- some text is selected so add the tags aroung the selection
BeforSelection = String.Mid(strText, 0, selString.Start);
AfterSelection = String.Mid(strText, selString.End+1, -1);
sel = selString.End-selString.Start
Selection = String.Mid(strText, selString.Start, sel+1);
Input.SetText(MainInput, BeforSelection..""..Selection..""..AfterSelection);
--[[on this line you need to edit the numbers, =3 ,[LEFT]=6 ,and so on
for each tag you create, this sets the cursor in the right place when the tag has been added]]
Input.SetSelection(MainInput, selString.Start+3, selString.End+3);
else
-- no text is selected so add the tags where the cursor is
BeforCaret = String.Mid(strText, 1, cPos);
AfterCaret = String.Mid(strText, cPos, -1);
--[[ same on this line, edit the numbers to suit the tag,
you will have to play with it a little bit to get it right for each tag]]
Input.SetText(MainInput, BeforCaret.."[B]"..AfterCaret);
Input.SetSelection(MainInput, cPos+4, cPos+3);
end
this is to get your lists up n running (NOTE: small bug in the code i cant track down, it leaves a single unrecognized character at the end of the string, if anyone could help with that id be greatful :yes )
strText = Input.GetText(MainInput);
cPos = GetCaretPos(MainInput)
BeforCaret = String.Mid(strText, 1, cPos);
AfterCaret = String.Mid(strText, cPos, -1);
count=1
ListItem = Dialog.Input("Ordered List", "Enter Item: 1", "", MB_ICONNONE);
if ListItem ~= "" and ListItem ~= "CANCEL" then
tbList = {}
Table.Insert(tbList, 1, "\r\n");
Table.Insert(tbList, 2, " "..ListItem);
while (ListItem ~= "") do
count=count+1
ListItem = Dialog.Input("Ordered List", "Enter Item: "..count.." , Leave Blank or Click Cancel To End The List", "", MB_ICONNONE);
if ListItem ~= "" and ListItem ~= "CANCEL" then
tbCount = Table.Count(tbList);
tbCount=tbCount+1
Table.Insert(tbList, tbCount, " "..ListItem);
else
break
end
end
Table.Insert(tbList, tbCount+1, "");
strList = Table.Concat(tbList, "\r\n", 1, TABLE_ALL);
Input.SetText(MainInput, BeforCaret..strList..AfterCaret);
strCount = String.Length(strList);
reloc=cPos+strCount+1
Input.SetSelection(MainInput, reloc, reloc+2);
end
GoOgLe
03-22-2007, 04:10 AM
hi again Rizlauk
it is going good but i want to ask u something... please c the attachment...
after i block something from the input i want to change the color but when i click combobox to choose the color... blocked text goes to normal and it doesnt paste color code
RizlaUK
03-22-2007, 08:26 AM
i dont get it, it works for me, select the color from the combo, click the button and it adds the code
if you want it to add the code when the combo is selected then move the code from the button to the combo on select event :yes
GoOgLe
03-22-2007, 08:48 AM
i know it works like that but if u want to add the color code with button click after selection from input then it doesnt work...
GoOgLe
03-22-2007, 09:04 AM
and also whats wrong with this code ?? i dont need text selection with image adding and if dont select text code doesnt work
image = Dialog.Input("WEB", "IMAGE:", "", MB_ICONQUESTION);
if (image ~= "CANCEL") then
selString = Input.GetSelection("Input1");
if selString ~= nil then
strText = Input.GetText("Input1");
BeforSelection = String.Mid(strText, 0, selString.Start);
AfterSelection = String.Mid(strText, selString.End+1, -1);
sel = selString.End-selString.Start
Selection = String.Mid(strText, selString.Start, sel+1);
Input.SetText("Input1", BeforSelection..""..image..""..AfterSelection);
end
end
RizlaUK
03-22-2007, 10:00 AM
your combo and button work fine for me, when ever i select anything from it or not
and also whats wrong with this code ??
theres nothing wrong with the code, its the way you are useing it
look at my above post and take the time to work out what each line dose and download worm's caret dll and amend the code to suit your needs, look the functions up in the manual if your not sure what thay do
use the caret dll to get the cursor position and add the image tags there, use the same method for the hyperlink, you will have to change your code for each type of tag you want use as the format varies
i have given you 2 very good examples of what i consider to be rather tricky code (as each of them took me a few hours to get right)
simple rules of thumb......if no text needs to be selected, dont have a if selected statment and find another way round it, ams is very vresitile, there is more than one way to achive a task, look at the 2 lots of code i posted and see how it works when there is no text selected,
i used worms caret dll to get the position and use string.mid to get the text b4 and after the current position and then reinsert the text with the tags added and relocate the caret to the end of the string that has just been inserted
GoOgLe
03-22-2007, 10:14 AM
image = Dialog.Input("WEB", "IMAGE:", "", MB_ICONQUESTION);
if (image ~= "CANCEL") then
Input.SetText("Caret Position", ""..image.."" .. GetCaretPos("Input1"))
Input.SetText("Caret Position", ""..image.."" .. GetCaretRow("Input1"))
Input.SetText("Caret Position", ""..image.."" .. GetCaretPosInRow("Input1"))
end
i tried to use worms dll i changed some codes but i could manage it !!!!
GoOgLe
03-23-2007, 07:19 AM
any help with worm's dll ????
GoOgLe
03-23-2007, 08:15 AM
perfect worm :yes
thank u so much
And here is the code to add a link... it will detect whether text is selected to use as the link or not. You'll have to replace the leading {URL] with [ URL ] without spaces. The forum wouldn't display that code
link = Dialog.Input("WEB", "LINK:", "", MB_ICONQUESTION);
if (link ~= "CANCEL") then
tblSelected = Input.GetSelection("Input1")
if tblSelected then
nPos = tblSelected.Start - 1
sLinkText = String.Mid(Input.GetText("Input1"), tblSelected.Start, tblSelected.End - tblSelected.Start + 1)
else
nPos = GetCaretPos("Input1")
sLinkText = link
end
if nPos == 0 then
Input.SetText("Input1", "{URL=\""..link.."\"]"..sLinkText.."{/URL]"..Input.GetText("Input1"))
elseif nPos == String.Length(Input.GetText("Input1")) then
Input.SetText("Input1",Input.GetText("Input1").. "{URL=\""..sLinkText.."\"]"..link.."{/URL]")
else
sBefore = String.Left(Input.GetText("Input1"), nPos)
if tblSelected then
sAfter = String.Mid(Input.GetText("Input1"), tblSelected.End + 1, -1)
else
sAfter = String.Mid(Input.GetText("Input1"), nPos + 1, -1)
end
Input.SetText("Input1", sBefore.."{URL=\""..link.."\"]"..sLinkText.."{/URL]"..sAfter)
end
end
GoOgLe
03-23-2007, 09:48 AM
stream = Dialog.Input("WEB", "HTTP:", "", MB_ICONQUESTION);
if (stream ~= "CANCEL") then
selString = Input.GetSelection("Input1");
if selString ~= nil then
strText = Input.GetText("Input1");
BeforSelection = String.Mid(strText, 0, selString.Start);
AfterSelection = String.Mid(strText, selString.End+1, -1);
sel = selString.End-selString.Start
Selection = String.Mid(strText, selString.Start, sel+1);
Input.SetText("Input1", BeforSelection..""..Selection..""..AfterSelection);
end
end
i am using this code to add a link
that works. The only difference is that mine allows you to enter a link without selecting text.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.