Having trouble with a vbscript creating a new vbscript containing a variable from the original - vbscript

I am trying to make a vbs that creates a new vbs file, but im having some trouble with the creation of the second file.
Earlier in the first script it asks for your desired username, which is then assigned to a variable named user.
When it creates the second script, i want the user name to display in a message saying Welcome back [insert username here]. Please input a program value.
problem is, i cant get it to place your username inside of the new scripts code.
attempt 1
If VTCreate1 = 6 And VTCreate2 = 7 And VTCreate3 = 7 And VTCreate4 = 7 And VTCreate5 = 7 Then
Set objFile = objFS.CreateTextFile("C:\Users\Public\Desktop\Aeshnidae_1627374757.vbs")
objFile.WriteLine("vtcmd=inputbox(""Welcome back "")" & user & "("". Please input a program value."")")
attempt 1 results in the newly created script containing the following
vtcmd=inputbox("Welcome back ")Human(". Please input a program value.")
attempt 2
If VTCreate1 = 6 And VTCreate2 = 7 And VTCreate3 = 7 And VTCreate4 = 7 And VTCreate5 = 7 Then
Set objFile = objFS.CreateTextFile("C:\Users\Public\Desktop\Aeshnidae_1627374757.vbs")
objFile.WriteLine("vtcmd=inputbox(""Welcome back & user & . Please input a program value."")")
attempt 2 results in the following
vtcmd=inputbox("Welcome back & user & . Please input a program value.")
any idea how to get the desired username properly inside of the message?

Let's start with the final desired output line
vtcmd=inputbox("Welcome back xxxxxx. Please input a program value")
To place it inside a string variable (what we will later write) we need to quote the line and escape inner double quotes
"vtcmd=inputbox(""Welcome back xxxxxx. Please input a program value"")"
To replace the placeholder we need to cut our string
"vtcmd=inputbox(""Welcome back " ". Please input a program value"")"
close quote ^ ^ open quote
And concatenate the variable with the two strings
"vtcmd=inputbox(""Welcome back " & user & ". Please input a program value"")"
So, the final code line will be
objFile.WriteLine "vtcmd=inputbox(""Welcome back " & user & ". Please input a program value"")"

Related

SAP GUIXT - Pass Variable and run script

I would like to create an "input field" in SAP that uses the passed value within a vb script. To give a specific example, I would like to open FBL5N, pass an invoice into a field and view the invoice in VF03. The script to do that is ready and works for a hardcoded value of invoice or thru VBA.
Here is the GUI script part
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "print_inv" process="InvoiceScript.txt"
using MYINV = "V_inv"
Now, I don't know what to do for the inputscript part. I would like your assistance in this matter. Here is my first attempt:
Screen SAPLSLVC.0500
ApplyGuiScript template="VF03INV.vbs"
Enter
Thank you for your help and let me know if you need any precision.
Here are my sources of inspiration to get the above code :
http://www.synactive.com/tutor_e/lessonia03.html
http://www.synactive.com/docu_e/docia_process2.html
***if its possible to have a version that reads a value in clipboard, that would even be better.
After many attempts here is a solution:
Script(SAPLSLVC.0500.txt):
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "script" "/OVF03" process="startvf03.txt"
using INV = [V_inv] ' need this when opening new screen
InputScript (startvf03.txt):
parameter INV
Screen SAPMV60A.0101 'this is the VF03 screen
SET F[VBRK-VBELN] "&U[INV]" 'pass invoice # parameter
ApplyGuiScript "C:\guiXT\scripts\VF03INV.vbs"
VBScript (VF03INV.vbs):
inv = session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text
session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
session.findById("wnd[1]/tbar[0]/btn[37]").press
session.findById("wnd[0]/tbar[0]/okcd").Text = "pdf!"
session.findById("wnd[0]").sendVKey 0
'with some little extra here on how to save a pdf in SAP
'get new strings for locations (specific to my situation)
abc = session.findById("wnd[1]/usr/cntlHTML/shellcont/shell").Browserhandle.locationURL
beg = instr(abc,"C:")
cde = mid(abc,beg,9999)
dest = "C:\111\invoices\" & inv & ".pdf"
'changing from temp to a specific folder
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyfile cde, dest
'close the open file
session.findById("wnd[1]").close
session.findById("wnd[0]").close
Set fso = nothing
*the several If Not IsObject(application) Then you usually see were not necessary, but doesn't hurt to have them.
I hope this helps everyone learn Guixt
Within the VB script with the parameter "template" can you address a GuiXT variable as follows.
for example:
msgbox "&V[V_inv]"

VBScript Error 52 Bad file name or number

I have a VBScript which is used in Avaya CMS to generate a CSV every 3 seconds. This CSV is then read on each change by a node server.
Every now and then it will throw an error (Error 52) and it then requires someone to manually click OK on the prompt and then it continues.
I didn't write the initial script, but I have been trying to fix it so it doesn't throw this error.
As far as I understand, the issue is being caused when the script tries to write to the file when the node server is trying to read the file.
So far I have tried to fix this by making the file read only, then, in the script it makes it writeable, writes to it and makes it read only again.
I thought this had fixed the issue, but I have received Error 52 pop up again and now I am unsure.
Does anyone know if there is a way to get VB/Avaya to ignore the error? I was thinking something like putting On Error Resume Next before the line that writes the file?
I know ignoring errors is not good practice, but in this case, if it does ignore it, it just means the file wont be updated on this loop, but 3 seconds later it will loop again so it should be fine.
Script:
On Error Resume Next
cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports("Real-Time\Designer\Skill Status")
If Info Is Nothing Then
Else
b = cvsSrv.Reports.CreateReport(Info,Rep)
If b Then
Rep.RefreshInterval = 3
Rep.SetProperty "Split/Skill","5"
Set WshShell = CreateObject("WScript.Shell")
theHTMLLocation = "C:\wamp\www\wallboards\agent_status.csv"
theSleepFile = "C:\wamp\www\wallboards\sleep.vbs"
theTemplateLocation = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set gfile = fso.GetFile("C:\wamp\www\wallboards\agent_status.csv")
Do While Rep.Window.Caption <> ""
gfile.Attributes = 0
d = Rep.ExportData("C:\wamp\www\wallboards\agent_status.csv", 44, 0, False, True, True)
gfile.Attributes = 1
WshShell.Run "wscript.exe """ & theSleepFile & """", , True
Loop
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If
Set Info = Nothing
P.S - I left out some Parameters at that start of the file which I don't think are relevant, if someone thinks they are I will add them.

Create and show a PDF file from a Lotus Notes action

I'm using an action inside a form to create a Word document, using the CreateObject("Word.application") method, then I modify it to my liking and save it in a temp directory.
I can show the Word document as soon as it is created by calling nameOfTheDocument.visible(true), and by modifying the Save action I can save the newly created document as a PDF, however I can't find a way to show it to the user.
Trying to call visible(true) on the PDF object results in error "Instance member VISIBLE does not exist"
Hmmm... The best and right way - use OS file association.
I'm use java way:
//Win
Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filePath);
p.waitFor();
//MacOS.*Nix
Process p = Runtime.getRuntime().exec("/usr/bin/open " + filePath);
p.waitFor();
But you can call this command on Lotusscript:
Shell({rundll32 url.dll,FileProtocolHandler } & fullFilePath,1)
'or
Shell({/usr/bin/open } & fullFilePath,1)
We have used the Shell command to launch PDFs in the past. Something like the below. The only downside to this is if the location of the executable changes (whether from upgrade or change to a different program) the code breaks.
Dim ProgPath$, FilePath$
Dim result As Integer
'Path of the executable
ProgPath$ = |"C:\Program Files (x86)\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe"|
'Path of the file to open
FilePath$ = | "C:\TestFile.PDF"|
result = Shell(ProgPath$ & FilePath$,1)

0x800a0005 Error when using OpenAsTextStream

My intention is to write every output line to a log file for archive purposes. Instead of writing to a file using OpenTextFile() and Write(), and then closing at the end of the script, I would like to write to the file as the script executes. If for whatever reason, the script is terminated before it has a chance to close the file, I worry I will lose those logs.
To achieve this, here is what I have attempted:
'Master Logs
Dim MasterLogFileName, MasterLogFile, MasterLogFileStream
Const ForAppending = 8
Const TristateUseDefault = 2
Function Write(text)
Wscript.StdOut.Write text
Set MasterLogFileStream = MasterLogFile.OpenAsTextStream(ForAppending, TristateUseDefault)
MasterLogFileStream.Write text
MasterLogFileStream.Close
End Function
'Create a Master Log file to write to
MasterLogFileName = "LogFile.log"
fso.CreateTextFile(MasterLogFileName)
Set MasterLogFile = fso.GetFile(MasterLogFileName)
Write("Test writing!")
Write("Test writing 2!")
However, I receive the following error:
0x800a005 - Microsoft VBScript runtime error: Invalid procedure call or argument
On this line:
Set MasterLogFileStream = MasterLogFile.OpenAsTextStream(ForAppending, TristateUseDefault)
When executing the Write() Function for the second time, using this line:
Write("Test writing 2!")
As specified by Lankymart and JosefZ, the reason this wasn't working was because I specified 2 for TristateUseDefault, instead of -2, as per the OpenAsTextStream method specifies.

Password Changer using VAccess

Hey I am working on a password changer. User logs in ( successfully), loads a global var with user initials, then launch a password expired form. I try and use those initials on the password expired form to retrieve user info from DB.
vaUserLog.FieldValue("USERINIT") = UserInitials
vaUserLog.GetEqual
vaStat = vaUserLog.Status
vaStat keeps giving me an error of 4. I am using pervasive v9. Connection with VA looks like:
With vaUserLog
.RefreshLocations = True
.DdfPath = DataPath
.TableName = "USERLOG"
.Location = "USERLOG.MKD"
.Open
If .Status <> 0 Then
ErrMsg = "Error Opening File " + .TableName + " - Status " + str$(.Status) + vbCrLf + "Contact IT Department"
End If
End With
In DB table, USERINIT is Char, 3. UserInitials is a String.
Probably missing something small but can't think right now. Any help is appreciate. Lemme know if you require more info.
Cheers
Status 4 means that the record could not be found. In your case, it could be the case of the value being searched is wrong, there's a different padding (spaces versus binary zero), or that the UserInitials value just isn't in the data file.
You can use MKDE Tracing to see what's actually being passed to the PSQL engine. Once you've done that, make sure the value you're using works through the Function Executor where you can open the file and perform a GetEqual.
Here are my suggestions:
- Make sure you're pointing to the right data files.
- Make sure you're passing the right value into the GetEqual (by setting the FieldValue).

Resources