|
-
Jun 15th, 2006, 12:59 AM
#1
Thread Starter
PowerPoster
[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:
iPos = (InStr(sTemp, "-- ") + 3) ' START POINT
iPoe = InStr(iPos, sTemp, " ") ' END POINT
sTemp = Trim$(Mid$(sTemp, iPos, (iPoe - iPos))) ' GET TEXT
-
Jun 15th, 2006, 01:03 AM
#2
Fanatic Member
Re: Just Checking ..
for that example surely your code is ok... what are the other records?
noister
<advertising link removed by moderator>
-
Jun 15th, 2006, 01:36 AM
#3
Thread Starter
PowerPoster
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 ..
-
Jun 15th, 2006, 04:01 AM
#4
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.
-
Jun 15th, 2006, 06:50 AM
#5
PowerPoster
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.
-
Jun 15th, 2006, 07:30 AM
#6
Fanatic Member
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:
your_result = Split(Split(sTemp, "--")(1), " ")(1)
Do canibals not eat clowns because they taste funny? 
-
Jun 15th, 2006, 08:29 AM
#7
Thread Starter
PowerPoster
Re: Just Checking ..
 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:
your_result = Split(Split(sTemp, "--")(1), " ")(1)
thanks, thats what I was looking for .. didnt knowi could use split like that .. cool thanks .
Rory
-
Jun 15th, 2006, 10:28 AM
#8
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.
-
Jun 15th, 2006, 10:39 AM
#9
PowerPoster
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.
-
Jun 15th, 2006, 11:15 AM
#10
Thread Starter
PowerPoster
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.
-
Jun 15th, 2006, 11:32 AM
#11
PowerPoster
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.
-
Jun 15th, 2006, 11:41 AM
#12
Thread Starter
PowerPoster
Re: [RESOLVED] Just Checking ..
VB Code:
sTemp = StripText(sTemp, "-- ", " ")
'// CUT TEXT FROM STRING
Public Function StripText(ByVal source As String, _
ByVal start As String, ByVal finish As String) As String
Dim iPos As Integer, iPoe As Integer
iPos = (InStr(source, start) + Len(start))
iPoe = InStr(iPos, source, finish)
StripText = Trim$(Mid$(source, iPos, (iPoe - iPos)))
End Function
Last edited by rory; Jun 15th, 2006 at 12:04 PM.
-
Jun 15th, 2006, 11:54 AM
#13
PowerPoster
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.
-
Jun 15th, 2006, 12:17 PM
#14
Thread Starter
PowerPoster
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:
'// CHECK FILE EXISTS FSO METHOD
Public Function DoesFileExist(ByVal rFile As String) As Boolean
Dim objFso 'As FileSystemObject (reference)
On Error Resume Next
Set objFso = CreateObject("Scripting.FileSystemObject")
If (objFso.FileExists(rFile)) Then
DoesFileExist = True
End If
Set objFso = Nothing
End Function
-
Jun 15th, 2006, 12:31 PM
#15
PowerPoster
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.
-
Jun 15th, 2006, 12:41 PM
#16
Thread Starter
PowerPoster
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:
Private sFile As String
Private Sub Command1_Click()
If Len(Dir$(App.Path & "\" & sFile)) Then
Debug.Print "Exists: " & App.Path & "\" & sFile
End If
End Sub
Private Sub Command1_Click()
If Len(Dir$(sFile)) Then
Debug.Print "Exists: " & sFile
End If
End Sub
Last edited by rory; Jun 15th, 2006 at 12:47 PM.
-
Jun 15th, 2006, 01:55 PM
#17
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|