【问题标题】:vbscript adds Option to drop box and knocks out javascript function updatelist HTA Filevbscript 将 Option 添加到 drop box 并敲掉 javascript 函数 updatelist HTA 文件
【发布时间】:2012-02-28 09:28:00
【问题描述】:

大家好,这里有一个 HTA 文件。有一个 vbscript 读取文件并基于此将选项添加到下拉框。稍后在此 HTA 文件中有 javascript,它使用更新列表和其他功能根据第一个保管箱中的选择来更新第二个保管箱。 vbscript 仅编辑第一个 Dropbox。我没有收到任何错误,但我的 Javascript 不再进行任何选择,它只是一直使用相同的选择。怎么修?这里有一些代码。

编辑:首先我要非常感谢您的工作 Teemu。你花了这么多时间在我的问题上。尊重。但是是的,真的但是。剧本是最好的,我已经按照你说的设置了一切。所以第 27 行有一个小错误:customers[cust].createReleaseOptions(cust); 我已经对错误和我的设置做了一张图片: For image klick here!

希望你能再帮我一次:)

【问题讨论】:

  • 很难用这个信息说。你也可以发布Option 声明吗?
  • 呃,这不是我的意思,而是Option的构造函数。我不确定optionName 包含什么,但似乎你在定义object.select2.options[x] twice. First in Option`-object,然后在你的原始代码中再次定义两行。
  • 请不要发送整个代码,只发送Option函数。
  • 我写了整个代码,因为不知道 Option 函数是什么。对不起,我只能编程一点 C#
  • 好像根本没有Option-function,只能找到VBScript中的空声明。因此optionNameundefined。奇怪你没有收到任何错误信息。

标签: javascript vbscript hta


【解决方案1】:
<html>
<head>
<title>CATIA Starttool</title>
<HTA:APPLICATION 
     ID="myCATIA" 
     APPLICATIONNAME="myCatia"
     SCROLL="no"
>

//****** Open last used environment and set it as default selection
<script type="text/javascript">
<!-- THESE 5 FUNCTIONS REPLACE ALL MISSING CODE

// Reads textfile, file is created automatically, if not exist
function readCustomers(){
var fso,iStream,cust,n,tarr;
customers={};
fso=new ActiveXObject('Scripting.FileSystemObject');
iStream=fso.OpenTextFile('C:/Temp/CAD_Kunde.txt',1,true);
cust=iStream.ReadLine();
for(n=0;!iStream.AtEndOfStream;n++){
    tarr=iStream.ReadLine().split(';');
    customers[n]=new Customer(tarr);        
}
iStream.Close();
customers[0].selectionElement.selectedIndex=cust;
    customers[cust].createReleaseOptions(cust);
window.activeCustomer=cust;
return;
}

// Customer (environment) constructor function
function Customer(txt){
    var n,x=0;
    this.selectionElement=document.getElementById('select1');
    this.customerName=txt[0];
    this.catiaRelease=[];
    for(n=1;n<txt.length-1;n++){
        this.catiaRelease[n-1]=txt[n];
        x++;
    }
    this.len=x;
    this.defaultOption=parseInt(txt[txt.length-1]);
    this.selected=false;
    this.createCustomerOption();
}

// Creates customer (environment) options
Customer.prototype.createCustomerOption=function(){
    var opt;
    opt=document.createElement('OPTION');
    opt.text=this.customerName;
    opt.value=this.customerName;
    this.selectionElement.add(opt);
    return;
}

// Creates release options
Customer.prototype.createReleaseOptions=function(idx){
    var target,n,opt;
    target=document.getElementById('select2');
    target.length=0;
    for(n=0;n<this.len;n++){
        opt=document.createElement('OPTION');
        opt.text=this.catiaRelease[n];
        opt.value=this.catiaRelease[n];
        target.add(opt);    
    }
    target[this.defaultOption].selected=true;
    //target[0].selected=true; // Move comment line above, if this option is used
    window.activeCustomer=idx;
    return;
}

// Saves textfile
function saveCustomers(){
var fso,oStream,n,m,str='',cust=document.getElementById('select1');eos=cust.length;
fso=new ActiveXObject('Scripting.FileSystemObject');
oStream=fso.OpenTextFile('C:/Temp/CAD_Kunde.txt',2,true);
oStream.WriteLine(cust.selectedIndex);
for(n=0;n<eos;n++){
    str='';
    str+=customers[n].customerName+';';
    for(m=0;m<customers[n].len;m++){
        str+=customers[n].catiaRelease[m]+';';
    }
    str+=customers[n].defaultOption;
    oStream.WriteLine(str);
}
oStream.Close();
}


//***********

function OpenAction(object) {
   self.resizeTo(299,299);
   OpenActionVB();
   readCustomers();

}
//********

function RunScript(object) {
   saveCustomers();
   BetriebssystemKommando(object.select1.options[object.select1.selectedIndex].value,
                          object.select2.options[object.select2.selectedIndex].value,
                          select3=document.getElementById('OSName'),
                          object.select4.options[object.select4.selectedIndex].value,
                          object.select5.options[object.select5.selectedIndex].value,
                          object.select6.options[object.select6.selectedIndex].value);
}
//******** checking 64-Bit or 32-Bit

OS = navigator.userAgent;
if (OS.indexOf("Win")!=-1) { 
if ((OS.indexOf("Windows NT 5.1")!=-1) || (OS.indexOf("Windows XP")!=-1)) 
OSName="Win XP"; 
else if ((OS.indexOf("Windows NT 7.0")!=-1) || (OS.indexOf("Windows NT 6.1")!=-1)) 
OSName="Win 7"; 
else
OSName="Win Ver. Unknown"; 
// selection based on 64-Bit or 32-Bit
if ((OS.indexOf("WOW64")!=-1) || (OS.indexOf("x64")!=-1) || (OS.indexOf("Win64")!=-1) || (OS.indexOf("IA64")!=-1)) OSName= "DEFAULT_64"
else OSName="DEFAULT"
}
//********
//--></script>

<script language="vbscript">

Sub OpenActionVB( )

  cdiWorkDirRoot="C:\CDI"
  cdiBinaryRoot="i:\cad\catiav5\CDI"


  '*** CDI Software im Zugriff ?

  set objFSO = createObject("Scripting.FileSystemObject")
  If objFSO.FolderExists(cdiBinaryRoot) then


    '*** CDIWORK Rootverzeichnis anlegen

    If not objFSO.FolderExists(cdiWorkDirRoot) then
      objFSO.CreateFolder( cdiWorkDirRoot )
    End if

    '*** CDIWORK Rootverzeichnis Vollzugriff für alle aus der Gruppe BGST-GL-PDMUSR

    Set objShell = CreateObject("WScript.Shell")
    If objFSO.FolderExists(cdiWorkDirRoot) Then
      intRunError = objShell.Run("%COMSPEC% /c Echo J| cacls " & cdiWorkDirRoot & " /e /c /g BAT\BGST-GL-PDMUSR:F ", 2, True)
      intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & cdiWorkDirRoot & " /e /c /g BAT\BGST-GL-PDMUSR:F ", 2, True)
    End If

    '*** CDIWORK Benutzerverzeichnis anlegen

    Set objWSHNetwork = CreateObject("WScript.Network")
    userName=objWSHNetwork.UserName

    If not objFSO.FolderExists(cdiWorkDirRoot&"\"&userName) then
      objFSO.CreateFolder( cdiWorkDirRoot&"\"&userName )
    End if

    '*** CDIWORK Verzeichnisstruktur im Benutzerverzeichnis anlegen


    If not objFSO.FolderExists(cdiWorkDirRoot&"\"&userName&"\"&"WORK") then
      objFSO.CreateFolder( cdiWorkDirRoot&"\"&userName&"\"&"WORK")
    End if

    If not objFSO.FolderExists(cdiWorkDirRoot&"\"&userName&"\"&"INDEX") then
      objFSO.CreateFolder( cdiWorkDirRoot&"\"&userName&"\"&"INDEX")
    End if

    If not objFSO.FolderExists(cdiWorkDirRoot&"\"&userName&"\"&"LOG") then
      objFSO.CreateFolder( cdiWorkDirRoot&"\"&userName&"\"&"LOG")
    End if

    If not objFSO.FolderExists(cdiWorkDirRoot&"\"&userName&"\"&"RFCTRACEDIR") then
      objFSO.CreateFolder( cdiWorkDirRoot&"\"&userName&"\"&"RFCTRACEDIR")
    End if
  End if
End Sub
//*****************
Sub BetriebssystemKommando(Kunde,Version,Typ,Task,LocalSettings,LocalCache )

    Set objFS = CreateObject("Scripting.FileSystemObject")
    strTmpName = "C:\Temp\CAD_Kunde.txt"
    Set objScript = objFS.CreateTextFile(strTmpName)

    objScript.Write Kunde
    objScript.Write select1


strCmdLine = "i:\metaph\pdmsetup & muxstart & dspstart -d & i:\catiav5\start\V5start.bat " & Kunde & " " & Kunde & "_" & OSName & " " &  Version & " " & Task & " " & " I:\catiav5\start " & LocalSettings & " " & LocalCache

   objScript.Close


   Set objShell = CreateObject("WScript.Shell")

   objShell.Run(strCmdLine)


End Sub

</script>

</head>

<body onload="OpenAction()" >

<style>
BODY
{
   background-color:buttonface;
   font-family: Helvetica;
   font-size: 10pt;
   margin-top: 10px;
   margin-left: 10px;
   margin-right: 10px;
   margin-bottom: 10px;
}
</style>
<form name="formname">  
<table style="width: 100%;" border="0" cellpadding="2"
 cellspacing="0">
  <tbody>
    <tr>
      <td>         
      Environment <br>
      </td>
      <td>
        <select name="select1" id="select1" size="1" onchange="customers[this.selectedIndex].createReleaseOptions(this.selectedIndex);">
      </select>
      </td>
    </tr>
    <tr>

    </tr>
    <tr>
      <td>
      Release
      </td>     
      <td>
            <select name="select2" size="1" onchange="customers[activeCustomer].defaultOption=this.selectedIndex;">
      </select>
      </td>
    </tr>

    <tr>
      <td>
      Task
      </td>     
      <td>
      <select name="select4" size="1">
      <option value="DEFAULT">DEFAULT</option>
      <option value="AL2">AL2</option>
      <option value="DMU">DMU</option>
      <option value="EHD">EHD</option>
      <option value="FEM">FEM</option>
      <option value="IPPRO">IPPRO</option>
      <option value="EHD">EHD</option>
      <option value="KIN">KIN</option>
      <option value="NC">NC</option>
      <option value="ZADMIN">ZADMIN</option>
      </select>
      </td>
    </tr>
<tr>
      <td>
      Delete user settings
      </td>     
      <td>
      <select name="select5" size="1">
      <option value="1">YES</option>
      <option value="0">NO</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>
      Delete local cache
      </td>     
      <td>
      <select name="select6" size="1">
      <option value="1">YES</option>
      <option value="0">NO</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>        
      </td>     
      <td>
      <input id=runbutton  class="button" type="button" value="Run"  name="run_button"  onClick="RunScript(document.formname)">
      </td>
    </tr>
  </tbody>
</table>
</form>


</body>
</html>

这应该可以工作。将您的 CAD_Kunde.txt 格式化如下:

1
BEHR;B18 SP4;B18 SP7;0
AUDI;B19 SP3;0
BMW;B19 SP3;0
BIT;B18 SP4;B19 SP3;B16 SP9;0

第一行 = 从零开始的索引指向上次使用的环境。

其他线路: 首先是您的环境名称,然后是所有版本,最后的数字是从零开始的索引,该版本是活动的。所有值都以分号分隔,不允许在行尾出现空格或其他非打印字符(ENTER 除外)。文件中的最后一行应该是空行,并且只有一个

代码不受文本文件中错误的保护。不允许使用分号作为数据。

环境和发布也很容易维护,只需将它们更新到文本文件中即可。

程序会记住选择框上的所有点击,并在每次点击 Run 时保存文件。如果需要,可以轻松添加额外的保存按钮。如果不想保存单击的释放,请在createReleases-function 中切换注释。

【讨论】:

  • 好的,我点击了链接并找到了一个代码。我刚刚将我的路径添加到文本文件中。我必须在哪里添加代码以及如何将返回值广告到下拉框 select1 并选择它作为默认值?&lt;script language="JavaScript"&gt; function ReadFiles() { var fso, ts, s; var ForReading = 1; // Read the contents of the file. ts = fso.OpenTextFile("c:\\Temp\CAD_Kunde.txt", ForReading); s = ts.ReadLine(); ts.Close(); } &lt;/SCRIPT&gt;
  • 请对您的原始问题进行补充。由于 cmets 太多,我已经要求我将此对话移至聊天。
  • 问题是无法使用聊天,因为我没有足够的声誉
  • @user1225282 我从您的代码中发现了一些问题。在编辑的答案中,有一些解决问题的建议。希望你能理解我蹩脚的英语。
  • 我无法解决您的第二点问题。我知道我必须删除 objOption.selected="selected" 但我必须添加。
猜你喜欢
  • 1970-01-01
  • 2018-10-27
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-14
相关资源
最近更新 更多