Solved

How do i pull information from one HTA to another?

Posted on 2008-10-07
4
290 Views
Last Modified: 2013-11-05
I am creating a set of HTA files that will be part of a user creation process.

The current code I have will pull up a second window for the manager information to be entered using this when the box is checked:

Public Function contStatus_OnClick()
            
            Set objShell = CreateObject("Wscript.shell")
            objShell.run ("mshta.exe \\testenv\User_Creation\Information\ManInfo.hta")

End Function


I need to pull the variables from that second window into the existing (parent) hta for mass input into an excel doc.

Here is the base function for the second HTA box:

Public Function contInfo_OnClick()

      if cInfo.manager_fname.value = "" then
            msgbox("Please re-enter the manager information")
            contInfo_OnClick = False
      elseif cInfo.manager_lname.value = "" then
            msgbox("Please re-enter the manager information")
            contInfo_OnClick = False
            
      End if
                  
            strMgrFN = cInfo.manager_fname.value
            strMgrLN = cInfo.manager_lname.value
            strMgrSAM = strMgrFN & "." & strMgrLN
      
            strM = cInfo.month.value
            strD = cInfo.date.value
            strY = cInfo.year.value

            strExpireDate = strM & "/" & strD & "/" & strY

            MgrInfo strMgrSAM, strExpireDate

window.close()

End Function
0
Comment
Question by:dhalliday
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 22663471
Hi dhalliday,

The two HTA's are unaware of each other, and so cannot directly pass information.  You're best best is to run the second HTA using:

objShell.run ("mshta.exe \\testenv\User_Creation\Information\ManInfo.hta", 1, True)

so that the code in the first HTA waits for the second HTA to close.  Then, the idea behind that is that the second HTA writes the data to a text file, which the first HTA then picks up once the code has resumed (after the second has been closed).

So, the code in the first one would be something like:

'=================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
objShell.run ("mshta.exe \\testenv\User_Creation\Information\ManInfo.hta", 1, True)
strManagerFile = "ManagerInfo.txt"
If objFSO.FileExists(strManagerFile) = True Then
   Set objFile = objFSO.OpenTextFile(strManagerFile, intForReading, False)
   While Not objFile.AtEndOfStream
      strLine = objFile.ReadLine
      If Left(strLine, 12) = "First Name: " Then txt_mgrfirst.Value = Trim(Mid(strLine, 12))
      If Left(strLine, 11) = "Last Name: " Then txt_mgrlast.Value = Trim(Mid(strLine, 11))
   Wend
   objFile.Close
   objFSO.DeleteFile strManagerFile, True
Else
   MsgBox "Unable to find " & strManagerFile
End If
'=================

and the code in the second would be something like:

'=================
Set objFSO = CreateObject("Scripting.FileSystemObject")
strManagerFile = "ManagerInfo.txt"
Set objFile = objFSO.CreateTextFile(strManagerFile, True)
objFile.Write "First Name: " & txt_mgrfirst.Value & vbCrLf
objFile.Write "Last Name: " & txt_mgrlast.Value
objFile.Close
window.Close
'=================


Regards,

Rob.
0
 

Author Comment

by:dhalliday
ID: 22669858
Rob,

First, thank you for the input.  I am still in the learning phase with VBScript and am greatful for the assistance.

When i try to implement this i am running into a error on the objShell.run line where it tells me i can't use parentheses when calling a sub.


Thanks,

Dhalliday
0
 

Author Closing Comment

by:dhalliday
ID: 31503988
Thanks again for your help
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22673128
Thanks for the grade.

For the above error, just change this:
objShell.run ("mshta.exe \\testenv\User_Creation\Information\ManInfo.hta", 1, True)

to this
objShell.run "mshta.exe \\testenv\User_Creation\Information\ManInfo.hta", 1, True

just by removing the brackets around the Run argument.

Regards,

Rob.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now