# Subst Drive BeforeAction Failure

**URL:** https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358
**Category:** Bugs
**Created:** [April 29, 2011, 12:44pm UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358 "2011-04-29T12:44:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nelsonwolf](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@nelsonwolf](https://www.finalbuilder.com/forums/u/nelsonwolf)
#### Post date: [April 29, 2011, 12:44pm UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358/1 "2011-04-29T12:44:51Z")

</div>

This worked in&nbsp;FB6, but in&nbsp;FB7 I&nbsp;get the error below:

JavaScript BeforeAction:

Action.VirtualDrive = CSSubstDrive.charCodeAt();  
&nbsp;

Action Messages:  
Error Executing script : BeforeAction  
EInvalidCast  
Invalid class typecast  
Line: 3  
Char : 1  
Error in BeforeScript : JavaScript, This Action did not execute.  
&nbsp;

If there is a better way to do this that will work for both, let me know.

-Nelson

---

<div class="post-metadata">

### Author: ![stephen.ryan](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stephen.ryan](https://www.finalbuilder.com/forums/u/stephen.ryan)
#### Post date: [April 29, 2011, 3:46am UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358/2 "2011-04-29T03:46:43Z")

</div>

Hi Nelson   
  
 The charCodeAt function actually returns an integer (the Unicode value of the character of the specified index, defaulting to zero if no index is specified). Not sure why this worked in FB6 (even when I use a run script action to perform a simple charCodeAt on a variable I get a number), however we have updated the scripting engine for FinalBuilder 7.   
  
 If you want to reference a character from a string you can use the charAt function which will return the character at the specified index.   
  
 Regards,   
 Steve

---

<div class="post-metadata">

### Author: ![nelsonwolf](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@nelsonwolf](https://www.finalbuilder.com/forums/u/nelsonwolf)
#### Post date: [April 29, 2011, 6:25am UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358/3 "2011-04-29T06:25:40Z")

</div>

I am trying to migrate from FB6 to FB7 and the easiest way to do that is to not convert all my scripts at once. So ideally I need something that will work in both versions. In FB6, it won’t take a char, only an int and now in FB7 it only takes a char not an int. Any ideas?

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [April 30, 2011, 10:51am UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358/4 "2011-04-30T10:51:40Z")

</div>

Hi Nelson   
  
 Ok, I have it working now under FB7 :   
  
 [https://www.finalbuilder.com/downloads/finalbuilder/aex6/FB700\_1197.exe](https://www.finalbuilder.com/downloads/finalbuilder/aex6/FB700_1197.exe)   
  
 There will probably be some corner cases where my scripting implementation doesn’t handle things as well as the old library, unfortunately I had no choice as the old library is full of assembler and doesn’t support unicode strings. It’s also something that’s not easily unit tested either.

---

<div class="post-metadata">

### Author: ![nelsonwolf](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@nelsonwolf](https://www.finalbuilder.com/forums/u/nelsonwolf)
#### Post date: [May 4, 2011, 2:46am UTC](https://www.finalbuilder.com/forums/t/subst-drive-beforeaction-failure/3358/5 "2011-05-04T02:46:44Z")

</div>

Confirmed fixed.   
  
 Thanks for working on my issues so quickly!   
  
 -Nelson
