0

I would need support for that. I guess it's an easy one but i would like to get different approach if possible. I have the following Function and i just want to return value. If possible within a string variable.

StrVal = "123 Test"

Function IsHaving(StrVal)
Set reg1 = New RegExp
reg1.Gloabl=True
reg1.IgnoreCase=False
reg1.Pattern="\d+"
Set mats = reg.Execute(StrVal)
For Each mat In mats
  return mat.Value
Next
End Function

And then passing the value returned in another string

StrNum = IsHaving(StrVal)

I would like to do this way but i am not sure that in vb i can return from a loop for ( within the Function). Some ideas on that ?

user692942
  • 16,398
  • 7
  • 76
  • 175
Chaoui05
  • 288
  • 1
  • 2
  • 11
  • `Function IsHaving(StrVal) as Collection` and add `mat.value` to the collection and return that at the end. You dont return, you need to set the value of the same name as the function so in your example `IsHaving=mat.Value` – Nathan_Sav Feb 18 '21 at 09:52
  • Could you illustrate that with an example maybe. I am not familiar with Collection. Thanks – Chaoui05 Feb 18 '21 at 09:54
  • 5
    Instead of `return mat.Value`, just use `IsHaving = mat.Value`. In vbscript, if you want to return a value, then you just need to write `name_of_function = value_to_return`. – Gurmanjot Singh Feb 18 '21 at 09:58
  • Does this answer your question? [Return value from a VBScript function](https://stackoverflow.com/questions/15667421/return-value-from-a-vbscript-function) – user692942 Feb 18 '21 at 10:05
  • Not really responding as i having a loop for in the Function – Chaoui05 Feb 18 '21 at 10:13
  • It's not really clear for me. Sorry. – Chaoui05 Feb 18 '21 at 10:25
  • 1
    Ok! I got it. Thanks. The notion of Collection is not needed here as i just have an unique string to return and not multiple. – Chaoui05 Feb 18 '21 at 10:41

0 Answers0