Results 1 to 20 of 20

Thread: [RESOLVED] Count Len in text file?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Count Len in text file?

    If you have this in a TextBox, try this:

    VB Code:
    1. MsgBox Text1.Selstart
    To select for example the next 3 characters, try this:

    VB Code:
    1. Text1.SelLength=3

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Count Len in text file?

    No, still not working.
    Maybe I need to change text property!?

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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.

  6. #6
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    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

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    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

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  11. #11
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Count Len in text file?

    Quote Originally Posted by VB Client/Server
    My bad, gavio's code work's...
    That's what i thought

    VB Code:
    1. Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = 1 Then
    3.         '...
    4.     End If
    5. End Sub

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Count Len in text file?

    Quote 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.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Count Len in text file?

    Quote Originally Posted by gavio
    That's what i thought

    VB Code:
    1. Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = 1 Then
    3.         '...
    4.     End If
    5. End Sub
    Great, thanx to U both...

  14. #14
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    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

  16. #16
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  17. #17
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] Count Len in text file?

    Try this:

    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     If Not (KeyAscii >= 65 And KeyAscii <= 90) And _
    3.         Not (KeyAscii >= 49 And KeyAscii <= 57) And _
    4.             Not (KeyAscii = 32) And Not (KeyAscii = 8) Then KeyAscii = 0
    5. End Sub

  18. #18
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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

  19. #19
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] Count Len in text file?

    And another alternative is:

    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2. if instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",chr(keyascii))=0 then keyascii = 0
    3. 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.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    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
  •  



Click Here to Expand Forum to Full Width