How to run BATCH code in VB.NET? - vb.net

I'd like to run some batch code when click on an button.
The thing is I want to create the batch file in VB.NET and not use external batch file.
Finally I want run this batch code - shown in an RichTextBox.
Also - is it possible to change some variables...I mean, for example
$program = "selectedfromlistbox" (in batch.bat)
depends on which "software" was selected in an ListBox.
So I need to paste the ListBox selection into batch.
Hope u understand :)
Thx for ur help!
Hannir

You can not run batch code within your application just like that.
You should create a temporary batch file (which then can be customized with values selected in your application) and execute that using the Process class.

Related

Load only select sections of Code in QlikView

I have a set of code that is rather large in Qlik. I have dates that are defined at the start of the script
i.e.
Let vBDate = Date(Date#('01/01/2015','MM/DD/YYYY'),'MM/DD/YYYY');
Let vEDate = Date(Date#('12/31/2015','MM/DD/YYYY'),'MM/DD/YYYY');
The entire code runs financial numbers based on a specific data source. Originally I had a version of this QVW for each data source. However, as often goes with financials the QVW constantly needs to be refined. So I merged them all into one code. I broke the Code up into different tabs so I can turn off the sources I don't want.
What I want to do is try to se a variable, either in the code, like this,
Let vROIType = 'Vendor';
or using the method answered in my first attempt at this question where the variable is defined on the designer side using a button.
The hope is that when the variable is set, then only the code associated with that variable will run in the reload and the other code will be skipped.
In my research I tried to create functions in the script and use code to call them, however the call would always error out. I also read about QVDs but many of my date variables are defined at the start of running it, and the QVD needs to be pre-run.
Any help would be appreciated.
As long as you wrap the appropriate sections of the script in the conditionals properly, this should accomplish it:
Create a variable via the Variable Overview window (ctrl + alt + v) like you mentioned to reference the correct script to be reloaded (vROIType)
Create a button or text box and set an action to change the value of the vROIType variable. You can just make two buttons so you can select the correct data source by clicking the appropriate button.
Either reload via the menu or create another text box/button with an action to reload your script.
Most importantly, use conditionals in your script to selectively run the correct portions based on the vROIType variable.
if vROIType = 'Vendor' then
Everything in the script you want run when the source is `Vendor`.
elseif vROIType = 'SomeOtherVendor' then
Everything in the script you want run when the source is ....
end if;
Upon reload, the script will look at the vROIType variable and use that to determine whether or not to run parts of the script. Here's a link to a simple example you can try if you have the paid version of Qlikview, otherwise it'll yell at you that you can't open third party .qvw's.

How to save RichTextBox text to a text resource file?

I have created a text file named 'Notes' in the resources of my project and want to load/save the text of a RichTextBox to it. I tried using MyProject.My.Resources.Notes in the path. It doesn't show any error in the code window but when I run it, it shows an error.
Here's what I'm using to load the text:
RichTextBox1.Text = System.IO.File.ReadAllText(MyProject.My.Resources.Notes)
Here's what I'm using for saving it:
System.IO.File.WriteAllText(MyProject.My.Resources.Notes, RichTextBox1.Text)
This is not a duplicate. I did not get an answer from the other question
Why don't you use a regular file which always works fine or a database?
Edit: maybe this helps?
www.dondraper.com/2011/01/easily-save-and-retrieve-application-and-user-settings-in-vb-net-or-c-apps/

Clearing Text on Certain Dates in VB

Ok, so I am working on the very last part of my program and I am wondering if this is possible in VB and how to do it. I was thinking it was probably going to turn into a big If Statement, but I am not sure on the code to be exact.
Basically what I am trying to do is have my program write a new line of text into a .txt file once a day, I got that going good, but now what I want the program to do is to clear the entire .txt file at the start of each month, while also writing to the .txt file after the clear on the same day.
Is this possible? If so, could I get some help on this? Thank you!
Seems to me that it's as simple as this:
If Date.Now.Date.Day = 1 Then
File.Create(Path).Close() ' replace with your path to the file
End If

Append multiple PDF files

I have about 600 PDF files that I want to add a single disclaimer page to the beginning of each of them. So, I need to find a way to merge two PDF documents where one file is always the same and and comes first and the second file is changing.
Please let me know how I can do this.
Thanks!
I found this:
http://gotofritz.net/blog/howto/joining-pdf-files-in-os-x-from-the-command-line/
So you could do something like this in a shell script:
#!/bin/bash
page1="disclaimer.pdf"
for f in {a.pdf b.pdf c.pdf}; do
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o "$f" "$page1" "$f"
done
You can wrap this in an Applescript or automator workflow it you like.
Combine an unknown PDF with a known PDF
Automator can do this. You would save it as an application, so that you can drop the second file onto it. Your steps would be something like:
Get Specified Finder Items: Add the known PDF document here, the one that is “always the same and comes first”.
Combine PDF Pages
Move Finder Items: To: Combined Files. This will create a randomly-named file in the folder “Combined Files” which you will need to create.
If this Automator workflow is saved as an application, you can drop your second, "changing" file onto the application icon. The workflow will combine the two, putting the named file first.
Loop this workflow for each dropped file
In order to do this on multiple files at once, you will need to create a second workflow that loops through each dropped file and calls the above workflow. This second workflow is also created as an application. It has only one step:
Run Workflow: choose the workflow created in the previous step, and process items in batches of 1 at a time using 1 workflow.
Give the files a more usable name
That’s the basics. The obvious drawback is that all of the files have random names. That can be fixed by grabbing the original filename into a variable, and saving the new, combined document using that name in your new folder.
First, add four new steps to the top of the first workflow, in front of “Get Specified Finder Items”:
Run AppleScript
Set Value of Variable: name the variable filepath.
Run AppleScript
Set Value of Variable: name the variable filename.
Get Value of Variable: filepath
The first two steps save the full path to the dropped PDF. The second two steps get just the filename portion. The fifth new step pops the full path back into the workflow so that it can be combined with the known disclaimer.
Set the AppleScript in step 1 to:
on run {input, parameters}
return input
end run
Set the AppleScript in step 3 to:
on run {input, parameters}
tell application "Finder"
set filename to name of file input
end tell
end run
Then, add a step at the end to rename the file. After Move Finder Items add *Rename Finder Items. Choose “Name Single Item”, “Full name to” and then drag the variable filename up to the text box.

Open a file and replace its content

I want to make a small program to make my life easier. I need the program to open a txt/ini file, delete everything inside it and write what I need.
For example I want a range of 123-353, in increment order:
[Pancake123]
info
info
info
[Pancake124]
info
info
info
Ahe "info info info" always stays the same in the same order, the only thing I want to change is the range and number of Pancake.
Keep in mind that it's my first program so I don't know anything about it, I just need a program like this to make my life easier.
Right click in your code somewhere and choose the Insert Snippets option. Then drill down to file system and eventually write all text. You can edit the model code create to write over your file. No need to open, delete, etc. just write over in stead of append.
Here is a typical result My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Text", True)
The last param should be False to write over the existing file, True appends.