Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert JS to VB

Status
Not open for further replies.

spazman

Programmer
May 29, 2001
500
CA
I've been having problems with the following script. I get a type mismatch when I call it from a VB script, I cannot figure it out but I would like to do is convert the script to VB. So 1 is it possible, and 2 how do you do it.

function func_addselectitem(itmText, itmValue)
{
with(document.<% =strFormName %>.DeleteMatter)
{
options[options.length] = new Option(itmText, itmValue);
}
return true;
}

In case you are wondering the script that calls it looks like this;

MatterCookie = ReadVariable(&quot;DMatter&quot;)
if MatterCookie <> &quot;&quot; Then
aryMattersSelected = Split(MatterCookie, &quot;, &quot;)
for i = 0 to Ubound(aryMattersSelected)
strValue = aryMattersSelected(i)
strItem = Left(aryMattersSelected(i), 6)
func_addselectitem strItem, strValue
next
End if

Any and all help is appreciated.
 
Okay I changed theVB Script to look like this

MatterCookie = ReadVariable(&quot;DMatter&quot;)
if MatterCookie <> &quot;&quot; Then
aryMattersSelected = Split(MatterCookie, &quot;, &quot;)
Set objOpt = document.CreateElement(&quot;OPTION&quot;)
a = 2
for j = 0 to Ubound(aryMattersSelected)
strItem = aryMattersSelected(j)
strValue = Left(aryMattersSelected(j), 6)
objOpt.Value = strItem
objOpt.Text = strValue
document.<% =strFormName %>.DeleteMatter.add objOpt
document.<% =strFormName %>.DeleteMatter.selectedIndex = a
a = a + 1
next
Set objOpt = Nothing
End if

It adds the element but overwrites it with the next one in the array, does anyone know how to tell it to just add it, not replace it?
 
Never mind here it is working;

MatterCookie = ReadVariable(&quot;DMatter&quot;)
if MatterCookie <> &quot;&quot; Then
aryMattersSelected = Split(MatterCookie, &quot;, &quot;)

a = 2
for j = 0 to Ubound(aryMattersSelected)
Set objOpt = document.CreateElement(&quot;OPTION&quot;)
strItem = aryMattersSelected(j)
strValue = Left(aryMattersSelected(j), 6)
msgbox strItem & VbCrLf & strValue
objOpt.Value = strItem
objOpt.Text = strValue
document.<% =strFormName %>.DeleteMatter.add objOpt
Set objOpt = Nothing
document.<% =strFormName %>.DeleteMatter.selectedIndex = a
a = a + 1
next
End if

If you are wondering why a = 2 to begin with I hava blank value so the selectbox does not grow and shrink when value are added and deleted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top