Jump to content
Sign in to follow this  
newcoder1010

How to return specific data from a function

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...