checking a line of code in a file on quickbasic - passwords

I'm trying to make my program have a dialogue box with a password that has been set in a file. I need help having it scan a line of code in a file and if the password entry is true, then proceed.

This code gets a password and compares it to a password in a file:
INPUT "Password", x$
OPEN "password.dat" FOR INPUT AS #1
INPUT #1, y$
IF x$ = y$ THEN PRINT "Match": ' do stuff

Related

Getting value from text box in SAP application custom container

My requirement is to automate SAP flow using AutoIt. When I am trying to get the values(test) from below username textbox it is not getting the text box value and displaying an empty value. I want to get the value from the text box and I need to compare with string. Could you please help me out?
Output :
I already referred below links :
https://www.autoitscript.com/autoit3/docs/functions/ControlGetText.html
https://www.autoitscript.com/forum/topic/177533-get-text-from-a-button/
https://www.autoitscript.com/forum/topic/116065-get-text-from-active-window/
A screenshot of AutoIt finder tool :
My AutoIt code :
Run("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")
Local $hWnd = WinWaitActive("SAP Logon 740")
WinSetState($hWnd, "", #SW_MAXIMIZE)
ControlFocus("SAP Logon 740","","SAPTreeList1")
ControlTreeView("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","Expand","#0")
ControlClick("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","left",2,47,60)
Sleep(2000)
ControlClick("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","left",2,59,115)
Sleep(2000)
ControlClick("SAP Logon 740","","[CLASS:SysListView32; INSTANCE:1]","left",1,71,573)
Sleep(1000)
ControlClick("SAP Logon 740","","Log &On")
Sleep(3000)
Local $hNewWnd = WinWaitActive("SAP")
; Retrieve the classlist of the Notepad window using the handle returned by WinWait.
Local $sClassList = WinGetClassList("SAP")
#ConsoleWrite($sClassList)
; Display the classlist.
Sleep(3000)
ControlClick("SAP","","","left",1,179,56)
# MsgBox(0, "output", $sClassList)
Send("test")
Sleep(1000)
$wrd = ControlGetText("SAP","test","")
MsgBox(0,"Display",$wrd)
Control tab :
Please read about this and this.
#RequireAdmin ;sometimes this is required in order to be able to manipulate windows
Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
$wrd = ControlGetText("[TITLE:SAP]","",100);100 is id from the WindowInfo Tool
If #error Then $wrd = ControlGetText("[TITLE:SAP]","","[CLASS:Afx:68570000:1008; INSTANCE: 1]")
;This is the advanced method. Aslo shown in the WIndowInfo Tool.
MsgBox(0,"Display",$wrd)

Piping data to a pager

I have a code sample in Ruby that pipes data to a pager in order to print it in portions to STDOUT:
input = File.read "some_long_file"
pager = "less"
IO.popen(pager, mode="w") do |io|
io.write input
io.close
end
I have no problem in adopting this to Crystal like this:
input = File.read "some_long_file"
pager = "less"
Process.run(pager, output: STDOUT) do |process|
process.input.puts input
process.input.close
end
But if I change pager = "more" than the Ruby example still works fine, but the Crystal snippet dumps all the data, instead of serving it in portions. How can I fix it?
Crystal 0.25.0 [7fb783f7a] (2018-06-11)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
The more command tries to write it's user interface to stderr, so you need to forward that as well:
Process.run(pager, output: STDOUT, error: STDERR) do |process|
process.input.puts input
process.input.close
end
Since you are reading a long file, you might consider not reading it into memory, but instead to pass the file descriptor to the pipe:
input = File.open("log/development.log")
pager = "more"
Process.run(pager, input: input, output: STDOUT, error: STDERR)

Unable to save the file in specified location using Autoit

Followed the below steps to save a file in desired location:
Step1: Save As window getting opened(with the default downloads location, with file name as DOC)
Step2: entering the file name as "D:\temp\sample.pdf" (which is getting entered in the edit bar)
Step3: clicking the save button (button clicked, file downloaded in the default location rather than the "D:\temp" location)
I have created an .exe with the below .au3 script
WinWait("[CLASS:#32770]","",10)
Sleep(2000)
ControlSetText("Save As", "", "Edit1", $CmdLine[1])
Sleep(5000)
ControlClick("Save As", "", "Button1");
Sleep(5000)
On clicking save, it is getting saved in the default location rather than the specified location.
The below code, executing the script.
IO.popen('autoit_script.exe D:\temp') #Ruby Code
Is there a way to sort it out?
It depends on the software you are trying to automate but usually this happens because the software is not recognizing there is a change in the file save path box. The problem is in how ControlSetText works. Try using ControlSend with some error checking to make sure the file path you are try to set is getting put in right. Sometimes you have to play with a few different variations to see what works with the software you are automating. Here are two examples you can try:
Example one:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
ControlSetText($hWin, "", "Edit1", $CmdLine[1]) ;set text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", "{ENTER}")) ;should work like click button 1 but you will have to check
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf
Example two:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
While 1
ControlSetText($hWin, "", "Edit1", "") ;just makes sure there is no text in the control text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", $CmdLine[1])) ;set text using ControlSend
If ControlGetText($hWin, "", "Edit1") = $CmdLine[1] Then ExitLoop ;makes sure that the control got ALL of the text before exiting loop
WEnd
ControlClick($hWin, "", "Button1");
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf

AutoIt: run a program selected with FileOpenDialog?

I need to make a script that allows a user to run a software with certain parameters (that should be typed in). So, first step, select the exe. Second, a text input box should allow the user to enter the parameters. I can't get the first step done.
I tried with the second example found here: FileOpenDialog
The only modification is a Run command I added. When I run the script, I see the complete file path for the executable but nothing runs. I don't see an error either:
include <FileConstants.au3>
include <MsgBoxConstants.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select a single file of any type."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, #WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
If #error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
Else
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
; Replace instances of "|" with #CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", #CRLF)
; Display the selected file.
MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & #CRLF & $sFileOpenDialog)
Run($sFileOpenDialog)
EndIf
EndFunc ;==>Example
#include <FileConstants.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select a single file of any type."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, #WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
If #error Then
; Display the error message.
MsgBox(1, "", "No file was selected.")
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
Else
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
; Replace instances of "|" with #CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", #CRLF)
; Display the selected file.
MsgBox(1, "", "You chose the following file:" & #CRLF & $sFileOpenDialog)
Run($sFileOpenDialog)
EndIf
EndFunc ;==>Example
This works for me.
I dont know this "include MsgBoxConstants.au3" wich i think is unnecessary.
Lg Teifun2
You need to add the # before the include. Also the 2nd include has to be Constants.au3. When I do these changes I can successfully start any application with your code.
#include <FileConstants.au3>
#include <Constants.au3>

How to set default values for Tcl variables?

I have some Tcl scripts that are executed by defining variables in the command-line invocation:
$ tclsh84 -cmd <script>.tcl -DEF<var1>=<value1> -DEF<var2>=<value2>
Is there a way to check if var1 and var2 are NOT defined at the command line and then assign them with a set of default values?
I tried the keywords global, variable, and set, but they all give me this error when I say "if {$<var1>==""}": "can't read <var1>: no such variable"
I'm not familiar with the -def option on tclsh.
However, to check if a variable is set, instead of using 'catch', you can also use 'info exist ':
if { ![info exists blah] } {
set blah default_value
}
Alternatively you can use something like the cmdline package from tcllib. This allows you to set up defaults for binary flags and name/value arguments, and give them descriptions so that a formatted help message can be displayed. For example, if you have a program that requires an input filename, and optionally an output filename and a binary option to compress the output, you might use something like:
package require cmdline
set sUsage "Here you put a description of what your program does"
set sOptions {
{inputfile.arg "" "Input file name - this is required"}
{outputfile.arg "out.txt" "Output file name, if not given, out.txt will be used"}
{compressoutput "0" "Binary flag to indicate whether the output file will be compressed"}
}
array set options [::cmdline::getoptions argv $sOptions $sUsage]
if {$options(inputfile) == ""} {puts "[::cmdline::usage $sOptions $sUsage]";exit}
The .arg suffix indicates this is a name/value pair argument, if that is not listed, it will assume it is a binary flag.
You can catch your command to prevent error from aborting the script.
if { [ catch { set foo $<var1> } ] } {
set <var1> defaultValue
}
(Warning: I didn't check the exact syntax with a TCL interpreter, the above script is just to give the idea).