Results 1 to 17 of 17

Thread: [RESOLVED] Just Checking ..

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Resolved [RESOLVED] Just Checking ..

    if there is another way to do this .. or is this pretty much it?

    The sentence can look like this .. item in bold is the text needed

    05/24/06 16:00 -- Start working on #1

    VB Code:
    1. iPos = (InStr(sTemp, "-- ") + 3)                    ' START POINT
    2. iPoe = InStr(iPos, sTemp, " ")                      ' END POINT
    3. sTemp = Trim$(Mid$(sTemp, iPos, (iPoe - iPos)))     ' GET TEXT

  2. #2
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Just Checking ..

    for that example surely your code is ok... what are the other records?
    noister
    <advertising link removed by moderator>

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Just Checking ..

    just an example sentence, just wanted to see if there was another way I havent seen yet, on getting specific text out of a sentence .. this is pretty much the way ive always done it in vbscript .. was curious if there was any other method in VB :-)

    thanks ..

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Just Checking ..

    Well, you can use the Split function to split up a string by a specified separator, in your case you should probably use space. But in this particular case I think you should go with what you've got.

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

    Re: Just Checking ..

    If you did use split, and you always had a "-- " before it you could always look for that and have the next item in the array or you could do an instr then right from what the instr returns and split then array(1) would be your word...but it's all just faffing around for what is basically easiest to do your current way. I would even go out on a limb and say that it is how everyone here does it :-)
    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.

  6. #6
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526

    Re: Just Checking ..

    For sTemp = "05/24/06 16:00 -- Start working on #1"

    If you wanted to use Split, this should return "Start":

    VB Code:
    1. your_result = Split(Split(sTemp, "--")(1), " ")(1)
    Do canibals not eat clowns because they taste funny?

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Just Checking ..

    Quote Originally Posted by doofusboy
    For sTemp = "05/24/06 16:00 -- Start working on #1"

    If you wanted to use Split, this should return "Start":

    VB Code:
    1. your_result = Split(Split(sTemp, "--")(1), " ")(1)
    thanks, thats what I was looking for .. didnt knowi could use split like that .. cool thanks .

    Rory

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Just Checking ..

    As I've already mentioned earlier, I wouldn't use Split for this purpose. Even though it may look cool with a one-liner like the above it consumes more memory and runs much slower then the code you used from start.

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

    Re: [RESOLVED] Just Checking ..

    It was something I was previously unaware of though...could be useful.

    Rory, if you parse words out of strings often, consider putting your code into a function...that way you use one line to call the 3 lines you need actioned...all you'd have to give the function is the original source string, start and end points and it should return the required word :-)
    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.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Just Checking ..

    Thats good to know also Joacim .. and smux Ill see if i can just put it in a function ..
    Last edited by rory; Jun 15th, 2006 at 11:26 AM.

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

    Re: [RESOLVED] Just Checking ..

    it shuold be as simple as "private function getparse(source as string, start as string, end as string) as string" with "getparse=results" (results would be whatever you call the string that you put the results into...to return results from a function you use {function name} = {results to return}
    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.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Just Checking ..



    VB Code:
    1. sTemp = StripText(sTemp, "-- ", " ")
    2.  
    3. '// CUT TEXT FROM STRING
    4. Public Function StripText(ByVal source As String, _
    5.     ByVal start As String, ByVal finish As String) As String
    6.     Dim iPos As Integer, iPoe As Integer
    7.     iPos = (InStr(source, start) + Len(start))
    8.     iPoe = InStr(iPos, source, finish)
    9.     StripText = Trim$(Mid$(source, iPos, (iPoe - iPos)))
    10. End Function
    Last edited by rory; Jun 15th, 2006 at 12:04 PM.

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

    Re: [RESOLVED] Just Checking ..

    *almost* right...iPos line...you have +3...it needs to be + len(start) as start length is variable length now :-)

    Also, do you need trim$ on the mid$? If you NEED it and never need untrimmed data returned, stay with it...just remember if you use it in other projects (that's the beauty of subs...you can use them elsewhere easily) just remember you trim it too :-)
    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.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Just Checking ..

    yep your right there .. ;-)
    i had that originally, took it out .. der yah go .. :-))

    Actually i use common functions in VBscript more than i do in VB ..
    but then vbscript doesnt give us as much to work with ..

    Yeah i think we need Trim in this case ..

    here's another i use all the time .. brought over from vbscript ..
    i usually put them all in modCommon.bas,
    theres tons of database related ones i use..

    VB Code:
    1. '// CHECK FILE EXISTS FSO METHOD
    2. Public Function DoesFileExist(ByVal rFile As String) As Boolean
    3.     Dim objFso 'As FileSystemObject (reference)
    4.     On Error Resume Next
    5.     Set objFso = CreateObject("Scripting.FileSystemObject")
    6.     If (objFso.FileExists(rFile)) Then
    7.         DoesFileExist = True
    8.     End If
    9.     Set objFso = Nothing
    10. End Function

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

    Re: [RESOLVED] Just Checking ..

    "doesfileexist" is a bit like a sledgehammer to crack a nut when you can just as easily use dir(filename) :-)

    "if dir("c:\filename.txt") then" should work just as well, I believe :-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.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Just Checking ..

    Dir wont work if there is no string .. if it is blank for example. like if you dont hard code it in there .. it will still return TRUE. It works if you know for sure you have entered the file path manually. Most cases it will be fine ..

    example ...
    VB Code:
    1. Private sFile As String
    2.  
    3. Private Sub Command1_Click()
    4.     If Len(Dir$(App.Path & "\" & sFile)) Then
    5.         Debug.Print "Exists: " & App.Path & "\" & sFile
    6.     End If
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10.     If Len(Dir$(sFile)) Then
    11.         Debug.Print "Exists: " & sFile
    12.     End If
    13. End Sub
    Last edited by rory; Jun 15th, 2006 at 12:47 PM.

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Just Checking ..

    That's simply because if you pass an empty string to the Dir function it looks for any file in the current directory and returns the first it finds. In other words it's the same thing as doing Dir("*.*"). But you can easily code around that by first checking if the passed string actually contains anything (using the Len function). You should also use error checking in the function if you use the Dir function since it might raise error 53 (File not found). Just try passing a string that only contains a space to it.
    Last edited by Joacim Andersson; Jun 15th, 2006 at 02:00 PM.

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