|
-
Sep 2nd, 2006, 06:42 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Count Len in text file?
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
-
Sep 2nd, 2006, 06:45 AM
#2
PowerPoster
Re: Count Len in text file?
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 :-))
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 06:49 AM
#3
Re: Count Len in text file?
If you have this in a TextBox, try this:
To select for example the next 3 characters, try this:
-
Sep 2nd, 2006, 06:56 AM
#4
Thread Starter
Hyperactive Member
Re: Count Len in text file?
No, still not working.
Maybe I need to change text property!?
-
Sep 2nd, 2006, 06:58 AM
#5
Re: Count Len in text file?
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.
-
Sep 2nd, 2006, 07:00 AM
#6
PowerPoster
Re: Count Len in text file?
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, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 07:04 AM
#7
Thread Starter
Hyperactive Member
Re: Count Len in text file?
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
-
Sep 2nd, 2006, 07:10 AM
#8
PowerPoster
Re: Count Len in text file?
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
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 07:12 AM
#9
Thread Starter
Hyperactive Member
Re: Count Len in text file?
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
-
Sep 2nd, 2006, 07:31 AM
#10
PowerPoster
Re: Count Len in text file?
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
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 07:33 AM
#11
Re: Count Len in text file?
 Originally Posted by VB Client/Server
My bad, gavio's code work's...
That's what i thought 
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
-
Sep 2nd, 2006, 07:33 AM
#12
Thread Starter
Hyperactive Member
Re: Count Len in text file?
 Originally Posted by smUX
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
Exactly, thanx for your help
I will try to search for more options how this can be done without using
command button.
-
Sep 2nd, 2006, 07:36 AM
#13
Thread Starter
Hyperactive Member
Re: Count Len in text file?
 Originally Posted by gavio
That's what i thought
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
Great, thanx to U both...
-
Sep 2nd, 2006, 07:47 AM
#14
PowerPoster
Re: [RESOLVED] Count Len in text file?
Don't forget to rate our posts :-)
And glad I could help
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 07:53 AM
#15
Thread Starter
Hyperactive Member
Re: [RESOLVED] Count Len in text file?
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
-
Sep 2nd, 2006, 07:59 AM
#16
PowerPoster
Re: [RESOLVED] Count Len in text file?
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
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 08:07 AM
#17
Re: [RESOLVED] Count Len in text file?
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
Last edited by gavio; Sep 2nd, 2006 at 08:12 AM.
-
Sep 2nd, 2006, 08:17 AM
#18
Re: [RESOLVED] Count Len in text file?
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
-
Sep 2nd, 2006, 08:34 AM
#19
PowerPoster
Re: [RESOLVED] Count Len in text file?
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)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 2nd, 2006, 10:40 AM
#20
Thread Starter
Hyperactive Member
Re: [RESOLVED] Count Len in text file?
Thank U both for your time and u'r help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|