简体   繁体   中英

VBScript - “Type Mismatch” Error with InStr Function

I have a String like this:

"5/1/2017 7:11:15 PM | String is very long - part 1 - part 999 - 2017-04-28.dots, Replace Existing"

This is the sub string I want to find the position in main string:

"String is very long - part 1 - part 999 - 2017-04-28.dots"

I tried to find it using InStr Function like this:

MsgBox CStr(InStr("5/1/2017 7:11:15 PM | String is very long - part 1 - part 999 - 2017-04-28.dots, Replace Existing", "String is very long - part 1 - part 999 - 2017-04-28.dots", 1, 1))

The result I expected is 23 .

Instead of the result, it throws the following Error:

Type mismatch: '[string: "5/1/2017 7:11:15 PM"]' (Code: 800A000D)

As this error depicts, can't I use InStr Function to deal with Strings those have spaces?

Thanks in Advance.

See: https://www.w3schools.com/asp/func_instr.asp

You are giving InStr 4 parameters, which means it is expecting the first to be an integer indicating where in the string to start the search. So, since it is expecting an integer, and you're giving it a string, it throws the Type Mismatch.

Just move one of the 1 s to be the first argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM