Hello,
When I load some text file, how can I get positon of selected string using mouse and selecting with it?
example:
asdfghjklqwertzuiopyxcvbnm
len=12
Printable View
Hello,
When I load some text file, how can I get positon of selected string using mouse and selecting with it?
example:
asdfghjklqwertzuiopyxcvbnm
len=12
f = instr(1,"asdfghjklqwertzuiopyxcvbnm","e") would return the location of "e" within the string...the 1 at the start tells it where to start looking (so when you get 12, you can search from 12+1 for the next occurence :-))
If you have this in a TextBox, try this:
To select for example the next 3 characters, try this:VB Code:
MsgBox Text1.Selstart
VB Code:
Text1.SelLength=3
No, still not working.
Maybe I need to change text property!? :confused:
This should work, unless you have your TextBox named differently than Text1. .SelStart returns the position your are currently at in a TextBox, .SelLength returns the selection length, in your case 1.
What *exactly* do you need? My code would search the text for the specified text while Gavio's should return the start location of the selected text (but not the length of the selected text)
Well, maybe I didnt explain good.
I need only start position on selected text.
qwertzuioijhgfdfghhbvcxcdfvbhgvcfd
dfghjhgfdfghjuztrfgbnvcxysdfghhgfd
werfvbhgfghjuizjkmokjnhbv[COLOR=Navy]cdsdfgtre
ertzutrertzuugfdsdfdscfrftgrdsxfreftf
position is = 84
just example
And using gavio's code when I load file, I get 3 times message "0"
@,your code is OK, but text is changing so I cant use it
Text is changing? As in you need an updated value each time it is changed? If so, try using the _change event and putting it in there...every time the text changes it'll be re-checked and updated
My bad, gavio's code work's but how to make it work directly when I press
with mouse click in text. It works OK
This is from *memory* so I can't guarantee it'll work...check to see if there's a mousedown event for the textbox, and if so you can use that (it'll wait for you to click the mouse button)
Guessing here but you actually want the MOUSEUP event, because you'll want to highlight the text THEN get the data returned
Hope it helps :-P
That's what i thought ;)Quote:
Originally Posted by VB Client/Server
VB Code:
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then '... End If End Sub
Exactly, thanx for your helpQuote:
Originally Posted by smUX
I will try to search for more options how this can be done without using
command button.
Great, thanx to U both... :wave:Quote:
Originally Posted by gavio
Don't forget to rate our posts :-)
And glad I could help
I just rate both of U, thanx
And maybe 2 more Q:
How to remove all characters that I dont want in my text.
1. Q :Characters like ":#",
2. Q :to allow load in text only capital leters and numbers ( small leters remove or get message )
Thanx once again
1. text1 = replace(text1,":#","") will replace all ":#" with ""
2. in text1_change you could put some sort of data validator which checks all characters...something that checks each letter in order against a string of allowed letters. Someone else might be able to help you there better than me, it's not something I've really tried much
Try this:
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii >= 65 And KeyAscii <= 90) And _ Not (KeyAscii >= 49 And KeyAscii <= 57) And _ Not (KeyAscii = 32) And Not (KeyAscii = 8) Then KeyAscii = 0 End Sub
Reffering to my last post, KeyAscii = 32 is rather optional; it allows the "space" button to be pressed. If you're looking for specific input of numbers and capital letters, the use of "space" key isn't such a good idea :)
And another alternative is:
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) if instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",chr(keyascii))=0 then keyascii = 0 End Sub
This allows A-Z and 0-9 and nothing else...and this is MUCH more customisable (you can add any letters to the string that you want and it'll allow them in the program)
Thank U both for your time and u'r help. :wave: