Open a file and replace its content - vb.net

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.

Related

How to trace an output in Access back to the section of VBA code that produced it

I am working on updating an Access database with this year's new data. I did not write the code that goes along with it, and am trying to find out where the formula is for an output (ratios) that the VBA code produces. Is there a way to trace back where the output came from?
I've tried just doing CTRL F to find the word "ratio" in the code but it's so long I can't pin down exactly where it's coming from.
No error messages
In debug mode you can step through the code step by step by pressing F8. You should be able to find the origin of every data export that way.
If the outputed data is a result of calculations I would check every query in the database. One of these probably takes care of those ratio's.

Applescript in reverse?

& thanks for all the tips i've had here... this site is ace!
My question is, basically, how to correctly write my script. I've written an applescript, that works great for 1 variable, but i'll need to add hundreds of variables, and that'll currently mean adding hundreds of "if" statements.
So my script queries a FileMaker database & receives an input field (which is variable), i then want to open a the related textEdit file & read the text.
ie... FileMaker Pro returns "123", so i want to open textEdit file "123".
However, my script currently says If text returned is "123" then do this, else if text returned is "234" do this, else if text returned is "345" do this. To write this script with hundreds of "Ifs" doesn't make sense, but i can't get my head around swapping my script to say - returned value is "123" so use file 123.
Does anyone have a suggestion?
Thanks

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.

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Pick a random name from a text file in VB

I have a file that has names of competitors. I want to write a VB code that selects a random name from the file.What I need is show the names moving quickly once I press enter it will select the name. I hope you got the idea.
If i understand your problem correctly you want to show every names on the file to the user on a button which name is chances rapidly.
If you want to do this little trick you need to load all the names from the file at the begging and keep them in a array so you will not need to reconnect to the file, that contains your names, every time you change the name of the button
Once you get the names you will need to create an infinite loop and attach a timer so the loop will wait for a specific time to change the name of the button.
last thing that you need to do is write a set of code under the button. That breaks the loop and gives the name of the button which was the assigned name at the time of the clicking.
I hope that helps you!
Have a good day