Search code examples
stringvbscriptgetformatgetstring

Get the double part from string with vbscript


I want to create a barcode with vbscript that will be decoded from my company's erp (my company devides the nubers with 10000. The barcode should have this type of look: 99XXXXXXXXXQQQQQQQQPPPPP where: X is my barcode, Q is quantity, and P is the price. With concatenation I have:

Result = 99 & [sheet$.BARCODE] & right("00000000" & quantity*10000, 8) & right("00000" & VBScript1*10000,5)

Now VBScript1 has this style, because it is used elsewhere in the program:

VBScript1 = "PRICE: "& FormatCurrency([sheet$.TIMH SAKOYLAKI]/[sheet$.SAKOYLAKI TWN]*1.3*(Round((40*CDbl(zyg))/CDbl([sheet$.GR/40 TEM]))),2)

so the output of VBScript1 is like Price: $0,40

Now my question is how to extract from the string the number only and then multiply it by 10000, in order to use it above?

For my example I want Price: Price: $0,40 to be used as 04000 in barcode.


Solution

  • Use Split() on $ to get the numerical part of (e.g.) "Price: $0,40", deal with the decimal comma, pad on the left:

    >> s = "Price: $0,40"
    >> p = CDbl(Replace(Split(s, "$")(1), ",", "."))
    >> t = Right(String(5, "0") & p * 10000, 5)
    >> WScript.Echo t
    >>
    04000
    >>