Jump to content

How to return specific data from a function


newcoder1010

Recommended Posts

Hi,

Every time I create an order I get a confirmation page with the below information. I need to be able to write a function which will return the data I am looking for
How can I write a Function that returns specific data?
    
Data I get after submission:
"Student ID: 100 Class ID: 99990444 Teacher ID: 610728"

Function Should return "Student ID: 100" after I request for student id. 
    
Calling funciton:

str = "Student ID: 100 Class ID: 99990444 Teacher ID: 610728"
myStudentID = CallFunction(str, "Student ID", "")
myClass = CallFunction(str, "Class ID", "")


 

Function CallFunction(completeString, startSearch, endSearch)
    startPos = InStr(1,completeString,startSearch)
    CallFunction = mid(CompleteString,startPos,endSearch)
End Function

Note: Number of digits are unknown for each ID. Also, there is a space after each ID. Above function will not work. I am having trouble how to write the function. Please advise. 

Edited by newcoder1010
Link to comment
Share on other sites

That data isn't a very helpful format, but I guess you can either use a regular expression, or just hard-code the lookup rules.  With a regular expression you could look for patterns where there are any number of letters or spaces, then a colon, then a space, then any number of digits.  If you hard code it then you'll need to look for the position of each space character and break up the string based on those.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...