Determining if a object exists

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Determining if a object exists

Post by rasimmer »

Been quiet in the HTA forum, everyone must be developing in PowerShell forms or something!!! In the HTA I'm working on, I'm listing folders that meet certain criteria. Based on the number of folders returned I'm doing diffrent things. No folders (0) stops the whole thing. One folder I populate the cell innertext with data and assign it an id "td_SelectedProfile". If there is more than 1, then I create a dropdown called "drp_Profiles". Here is the code.


Select Case arrProfiles.Count Case 0 objCell.InnerHTML = "Lotus Notes Profile:" Set objCell = objRow.InsertCell() objCell.InnerText = "No Profiles Found" Case 1 objCell.InnerHTML = "Lotus Notes Profile:" Set objCell = objRow.InsertCell() objCell.InnerText = arrProfiles(0) objCell.ID = "td_SelectedProfile" Case Else objCell.InnerHTML = "Lotus Notes Profiles:" Set objCell = objRow.InsertCell() Set objSelect = Document.createElement("SELECT") objSelect.ID = "drp_Profiles" objCell.appendChild(objSelect) For Each strProfile in arrProfiles Set objOption = Document.createElement("OPTION") objOption.Text = strProfile objOption.Value = strProfile drp_Profiles.Add(objOption) NextEnd Select



Now the issue is that basically this data is written to a DIV. I overwrite that DIV through steps of the HTA. If I do:

If IsObject(drp_Profiles) Then
strSelection = drp_Profiles.Value
Else
strSelection = td_SelectedProfile.InnerText
End If

If drp_Profiles was never created, the code works fine. If I created drp_Profiles but overwrite the DIV and the code runs again, I get:

"Object doesn't support this property or method 'drp_Profiles'"

What is the "proper" way to handle this?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Determining if a object exists

Post by jvierra »

Also note that you mention cells and rows but no code to determine what these things are.

Are you using a table? Without code your question is nearly impossible to address.


Create a simple example of the code that is failing maybe using buttons to drive the case statement.

User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Determining if a object exists

Post by rasimmer »

Open the HTA, click Next, then Back, then Next again and the error pops up.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> <META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1"> <title>Example</title>
<style type="text/css"> body { font-family:Verdana; font-size: 12px; color: #49403B; background: #FFFFFF; scroll:no; }
hr { color: #666666; }
input.text, option { font-size: 18px; background-color: #FFFFBB; }
table {
font-size: 12px; text-align: center; }
th, .hdr { font-size:12px; font-weight:bold; background-color:green; color:#FFFFFF; text-align:center; padding: 5px; margin-top:0px; } td {
padding: 2px; }
.success { color:blue; }
.fail { color:darkred; font-size: 14px; font-weight: bold; } .ini { color: green; font-weight: bold; font-size: 16px; }
/* BUTTONS */
.buttons a, .buttons button{ display:block; /*float:left;*/ width: 150px; margin:0 7px 0 0; /*background-color:#f5f5f5;*/ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#99CCFF, EndColorStr=#FFFFFF); border:1px solid #000000; border-top:1px solid #eee; border-left:1px solid #eee; /*line-height: 30px;*/ font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif; font-size:100%; line-height:130%; text-decoration:none; font-weight:bold; color:#000000; cursor:pointer; padding:5px 10px 6px 7px; /* Links */ } .buttons button{ width:auto; overflow:visible; border:1px solid #000000; padding:4px 10px 3px 7px; /* IE6 */ }
*:first-child+html button[type]{ padding:4px 10px 3px 7px; /* IE7 */ } .buttons button img, .buttons a img{ margin:0 3px -3px 0; padding:0; border:none; width:16px; height:16px; }
/* STANDARD */
button:hover, .buttons a:hover{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#66CCCC, EndColorStr=#FFFFFF); border:1px solid #3399CC; color:#336699; } .buttons a:active{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#3399CC, EndColorStr=#FFFFFF); border:1px solid #6299c5; color:#fff; }
/* POSITIVE */
button.positive, .buttons a.positive{ color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#66FF66, EndColorStr=#FFFFFF); border:1px solid #000000; } .buttons a.positive:hover, button.positive:hover{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#66ff00, EndColorStr=#FFFFFF); border:1px solid #006600; color:#529214; }
.buttons a.positive:active{ color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#66FF66, EndColorStr=#FFFFFF); border:1px solid #000000; }
/* NEGATIVE */
.buttons a.negative, button.negative{ color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FF3366, EndColorStr=#FFFFFF);*/ border:1px solid #000000; } .buttons a.negative:hover, button.negative:hover{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FF0066, EndColorStr=#FFFFFF); border:1px solid #FF0000; color:#FF3300; } .buttons a.negative:active{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FF0000, EndColorStr=#FFFFFF); border:1px solid #FF0000; color:#ccc; }
fieldset { /*background-color:#e9f9ac;*/
border-width:1px 1px 1px 4px; border-style:solid; border-color:green;
font-family:Arial, Helvetica, sans-serif; font-size:12px;
/*margin:5px 0px 5px 5px;*/ /*position:relative;*/ /*display:block;*/ /*padding: 0px 2px 2px 2px;*/
}
fieldset legend{ filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=green, EndColorStr=#FFFFFF); color: #ffffff; border-width:1px 1px 1px 4px; border-color:green; border-style:solid;
font-weight:bold; text-transform:uppercase; font-size:90%; text-align:center;
width:186px; padding:3px 5px; margin:0px 0px 10px -5px; position:relative; top: -14px; }
</style>
<script type="text/vbscript">
Dim intStep : intStep = 2Dim blnRunOnce : blnRunOnce = False
'Dim objWSHShell : Set objWSHSHell = CreateObject("WScript.Shell")Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")Dim objWSHNetwork : Set objWSHNetwork = CreateObject("WScript.Network")
Dim strComputer : strComputer = UCase(objWSHNetwork.ComputerName)Dim objComputer, strSelectedProfile
Sub Window_Onload() Center_HTA 600, 620 Go_Last()End Sub
Sub Center_HTA( widthX, heightY ) self.ResizeTo widthX, heightY self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2End Sub
Sub Clear_Form() Location.Reload(True)End Sub
Sub HTA_Close() self.close()End Sub
Sub Do_Submit() If Window.Event.KeyCode = 13 Then Do_Next()End Sub
Sub Go_Last() Select Case intStep Case 2 'btn_Next.InnerHTML = "Next<img src='file:////CCANET/EB/APPSINFO/Scripting_Images/famfamfam_icons/action_forward.gif' alt=''/>" btn_Next.ClassName = "positive" div_Status.InnerHTML = "" div_StepPane.InnerHTML = xml_Step_1.InnerHTML txt_Computer.Value = strComputer txt_Computer.Focus intStep = intStep - 1 btn_Last.Disabled = True btn_Next.Disabled = False 'If IsObject(drp_Profiles) Then Set drp_Profiles = Nothing Case 3 div_Status.InnerHTML = "" div_StepPane.InnerHTML = xml_Step_2.InnerHTML intStep = intStep - 1 btn_Last.Disabled = False btn_Next.Disabled = False End SelectEnd Sub
Sub Do_Next() Select Case intStep Case 1 strComputer = txt_Computer.Value
div_StepPane.InnerHTML = xml_Step_2.InnerHTML intStep = intStep + 1 btn_Last.Disabled = False div_Status.InnerHTML = "" If Get_Computer_Info = True Then ' ************************************** ' ' ******** ERROR HERE ********* ' ' ************************************** ' If IsObject(drp_Profiles) Then 'MsgBox "drp_Profiles exists" strSelectedProfile = drp_Profiles.Value Else strSelectedProfile = td_Profile.InnerText End If 'btn_Next.InnerHTML = "<img src='file:////CCANET/EB/APPSINFO/Scripting_Images/famfamfam_icons/script_go.png' alt=''/> Start Copy" btn_Next.ClassName = "" Else btn_Next.Disabled = True End If Case 2 div_Status.InnerHTML = "" document.GetElementById("tbl_Buttons").style.display="none" div_StepPane.InnerHTML = xml_Step_3.InnerHTML intStep = intStep + 1 div_Status.InnerHTML = "<font class='success'>You are working on profile " & strSelectedProfile & " on " & strComputer & "</font>" End SelectEnd Sub
Function Get_Computer_Info() Get_Computer_Info = True Set objRow = objTableBodyLC.InsertRow()
Set objCell = objRow.InsertCell() objCell.InnerText = "Logged on (" & strComputer & "):" objCell.classname="hdr" Set objCell = objRow.InsertCell() objCell.InnerText = objWSHNetwork.UserName
If objFSO.FolderExists("" & strComputer & "C$Documents And Settings") Then
Dim arrProfiles : Set arrProfiles = CreateObject("System.Collections.ArrayList") On Error Resume Next Set colFolders = objFSO.GetFolder("C:Documents And Settings").SubFolders If Err.Number = 0 Then For Each objFolder in colFolders If blnRunOnce = False Then arrProfiles.Add objFolder.Name Else If Ucase(objFolder.Name) = UCase(objWSHNetwork.UserName) Then arrProfiles.Add objFolder.Name End If End If Next
Set objRow = objTableBodyLC.InsertRow() Set objCell = objRow.InsertCell() objCell.classname="hdr"
Select Case arrProfiles.Count Case 0 objCell.InnerHTML = "Profile:" objCell.Style.BackgroundColor = "red" objCell.Style.Color = "black" Set objCell = objRow.InsertCell() objCell.InnerText = "No Profiles Found" div_Status.InnerHTML = "<font class='fail'>No Profiles meeting criteria found on remote device.</font>" Get_Computer_Info = False Case 1 objCell.InnerHTML = "Lotus Notes Profile:" Set objCell = objRow.InsertCell() objCell.InnerText = arrProfiles(0) objCell.ID = "td_Profile" div_Status.InnerHTML = "<font class='success'>Only one profile meets the criteria on the remote device.</font>" Case Else objCell.InnerHTML = "Lotus Notes Profiles:" objCell.Style.BackgroundColor = "yellow" objCell.Style.Color = "black" Set objCell = objRow.InsertCell() Set objSelect = Document.createElement("SELECT") objSelect.ID = "drp_Profiles" objCell.appendChild(objSelect) For Each strProfile in arrProfiles Set objOption = Document.createElement("OPTION") objOption.Text = strProfile objOption.Value = strProfile drp_Profiles.Add(objOption) Next div_Status.InnerHTML = "<font class='fail'>Multiple Profiles found that meet criteria, please choose a profile. CLICK BACK.</font>" btn_Next.Disabled = True End Select Else div_Status.InnerHTML = "<font class='fail'>Unable to connect to C:Documents And Settings.</font>" Get_Computer_Info = False End If Else div_Status.InnerHTML = "<font class='fail'>Unable to connect to C:Documents And Settings.</font>" Get_Computer_Info = False End If blnRunOnce = TrueEnd Function
Sub Sleep(seconds) If Not IsObject(objFSO) Then Set objFSO = CreateObject("Scripting.FileSystemObject") If Not IsObject(objWSHSHell) Then Set objWSHShell = CreateObject("WScript.Shell") strSleepFile = objWSHShell.ExpandEnvironmentStrings("%TEMP%Sleeper.vbs") If Not objFSO.FileExists(strSleepFile)Then Set objFile = objfso.CreateTextFile(strSleepFile, 2, True) objFile.Write "WScript.Sleep WScript.Arguments(0)" objFile.Close objWSHSHell.Run strSleepFile & " " & (seconds * 1000),0 , True End If objWSHSHell.Run strSleepFile & " " & (seconds * 1000),0 , TrueEnd Sub
Sub Reset_Field() document.getElementById("txt_Computer").style.background="#FFFFBB" div_Status.InnerHTML = ""End Sub
</script><hta:application applicationname="Template" border="dialog" borderstyle="normal" caption="Template" contextmenu="yes" icon="no.ico" maximizebutton="yes" minimizebutton="yes" navigable="yes" scroll="no" selection="yes" showintaskbar="yes" singleinstance="yes" sysmenu="yes" version="1.0" windowstate="normal"></head> <body> <center>
<table> <tr> <td style="text-align:left;"><h3>Example</h3></td> </tr> </table> <hr width="90%"> <br> </center> <div id="div_StepPane" style="height: 300px;"></div> <center> <br> <div id="div_Status" style="height: 25px;"></div> <br> <br> <table id="tbl_Buttons" style="display:block;"> <tr> <td class="buttons"> <a href="#" class="positive" id="btn_Last" onClick="Go_Last()"> Back </a> </td> <td class="buttons"> <a href="#" class="positive" id="btn_Next" onClick="Do_Next()"> Next </a> </td> </tr> </table> <br> </center> </body><xml id="xml_Step_1"> <p> Basically this is setup a wizard. A user enters a computername and the HTA goes to the remote computer and sees it meets certain criteria. When doing so, the computer could have nothing, one, or multiple matches. So, when you click next, the HTA will emulate connecting to a computer with multiple matches populating a dropdown (drp_Profiles). The next page with the dropdowns will basically provide validation information that it is the correct computer, but for the sake of argument it's wrong and we hit "BACK" to enter another computer and then click "NEXT" again and you'll see the error. </p> <p> What I'm basically trying to do is determine if a dropdown (drp_Profiles)was used or if I just put the data in a table cell (td_Profile). I thought just using IsObject() would work, but since I'm not destroying the object when I replace the HTML in the DIV. I have considered a couple of options and am just looking for direction on what would be the "correct" way to do it (or even a wizard interface like this in general): <ul> <li>When hitting back, reload the hta. Only problem is the computer name would be erased</li> <li>Use Dom to delete the table and all children (assume this will delete the drp_Profiles object)</li> <li>Set a blnFlag or variable that will indicate which was used and have an If so only the correct object is queried for a value</li> </ul> </p> <br> <br> <center> <table> <tr> <td>Computer Name:</td> <td><input type="text" class="text" id="txt_Computer" size="15" onkeyDown="Do_Submit" onFocus="Reset_Field()"></td> </tr> </table> <small style="color:red;">** This value is not used in the example, it will only query the local computer. **</small> </center></xml>
<xml id="xml_Step_2"> <br> <br> <br> <br> <br> <fieldset> <legend>Test:</legend>
<table id="objTableLC" style="width:75%;"> <tbody id="objTableBodyLC"> </tbody> </table> </fieldset></xml>
<xml id="xml_Step_3"> Start doing work here </xml>
</html>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Determining if a object exists

Post by jvierra »

Why o why won't anyone post humongous files as attachments. Cut and paste her eis very difficult.

I get this:
Unable to connect to C:Documents And Settings.
This topic is 14 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked