extracting details from string

scoob8254

Registered User.
Local time
Today, 08:46
Joined
Mar 2, 2008
Messages
76
hello,

hit a snag which im sure can be resolved easily enough but i cant seem to work it out.

basicaly im pasting contents of en email into a txt box and want to extract certain info into txt boxs, sort of like an autocomplete,

i dont want to read the emails directly before anybody suggests that as the people who use this db get the emails via different methods,

luckily even tho im not the worlds greatest coder the email is set out ina way that makes it quite easy for me to get most of the info, even with my limited coding knowledge, the one im having a prob with is the web address, as when its pasted in the txt box as its on a different line so it loses its spaces, and i cant use the instr fucntion to find the - after the address, as i keep getting the error, invalid call, procedure or argument

id also like to know if theirs a more effiecient or prof way of achieving what im trying to do. a copy of the emails is pasted below my code and is always the same format

any help as usual much appreciated

Private Sub cmdAuto_Click()

Dim sBody As String
Dim sp As String
Dim ep As String
Dim sExtract As String

'get body
sBody = Me.txtBody
'get opponent name
sp = (InStr(1, sBody, "v")) + 1
ep = InStr(1, sBody, "has")
ep = ep - sp
sExtract = Mid(sBody, sp, ep)
Me.txtOpp = sExtract
'get date
sp = (InStr(1, sBody, "Date:")) + 5
ep = InStr(1, sBody, "Time:")
ep = ep - sp
sExtract = Mid(sBody, sp, ep)
Me.txtDate = sExtract
'get map
sp = (InStr(1, sBody, "Map:")) + 4
ep = InStr(1, sBody, "Server:")
ep = ep - sp
sExtract = Mid(sBody, sp, ep)
Me.txtmap = sExtract
'get Server
sp = (InStr(1, sBody, "Server:")) + 7
ep = InStr(1, sBody, "Password:")
ep = ep - sp
sExtract = Mid(sBody, sp, ep)
Me.txtserver = sExtract
'get webaddress <------------------------- problem bit
sp = (InStr(1, sBody, "http:")) - 1
ep = InStr(1, sBody, "-")
ep = ep - sp
sExtract = Mid(sBody, sp, ep)
Me.txtleague = sExtract
End Sub




#############
copy of email below
#############

************************************
ENEMY DOWN - MATCH ACCEPTED
************************************

The match between snipers v Syn^
has been accepted by the_ravendalian

Date: Sep 3rd 2009
Time: 20:00
Map: de_nuke
Server: 213.108.31.79:27020
Password: blahblah
Rules: PCW,MR15,5v5,XAC Mandatory,

------------------------------------------------
http://www.enemydown.co.uk/fixture.php?id=701675
------------------------------------------------
 
Last edited:
#############
copy of email below
#############

------------------------------------------------
http://www.enemydown.co.uk/fixture.php?id=701675
------------------------------------------------
the thing you need to know is...what is the char between the web address and that long annoying "-----------------" string at the end? if it's a space, this will work:
PHP:
mid(sbody, 

instr(sbody, "http://"), 

(len(sbody)-instr(sbody, "http://")-instrrev(sbody, " ")))
if it's another char other than a space, replace the " "section with whatever char is there:
PHP:
instrrev(sbody, " "
. if the "----------" string comes immediately after the webaddress, and it's ALWAYS the same length or very close, which in this case it seems like it would be, comming from a uniform source, this will most likely work:
PHP:
mid(sbody, 

instr(sbody, "http://"), 

(len(sbody)-instr(sbody, right(sbody, 55))+instr(right(sbody, 55), "-")))
 
hi thanks for your reply. ive tried several variations of my own code ,

and just tried your code

mid(sbody,

instr(sbody, "http://"
),

(
len(sbody)-instr(sbody, right(sbody, 55))+instr(right(sbody, 55), "-"
)))


i get the same results as im currently getting the --------- is always at the end of the url, even if i try manualy setting the mid function witht he start and end characters the annoying hyphens are still their which they shouldnt be as i manualy counted the end postion for the mid function grrr

below is an example of the result i get with yours and my code, (although to be fair your code does look far more prof :D )
http://www.enemydown.co.uk/fixture.php?id=701675--------------
 
below is an example of the result i get with yours and my code, (although to be fair your code does look far more prof :D )
http://www.enemydown.co.uk/fixture.php?id=701675--------------
if that's what you're getting, add the number of annoying "-"s you see there to the appropriate part of the code and cut the rest of them off. what can't you do that?

it also could have to do with where you're getting it from...a textbox? what r the props of the box? problem could be there...
 

Users who are viewing this thread

Back
Top Bottom