I'm writing a VBS program where there is a while loop, but it's not easily breakable because it's not seen in the task manager easily (Not enough time to find it in the background processes because of the program). So, my solution was to make a simple input box that is always open which allows you to break the loop by typing Q. But, I can't find a way to allow the code in front of the input box code to run without having an input in the input box (Yes, No, Cancel). Any help? I'm new to VBS.
Related
I'm trying to code a VB program that when a button is pressed the system returns all text boxes, variables and forms to how they were when the program first loaded up.
I have managed to do it manually but there must be a faster and better way to do it. I'm being graded on this program any help is appreciated
There are a half-dozen answers to this. "Open a second instance" "Have a pause" Etc. I'm not looking for that.
I'm looking for the user of the workbook to be able to manipulate the workbook while the macro is running. I've seen this working before, where the user could scroll around, change tabs, even add and remove data, all while the macro was running. Unfortunately, I couldn't get permission to look at the code (And committing CFAA violations ins't my cup of tea), so I have no idea how they did it.
How can you enable a user to edit the workbook as macros are running? For a specific example, I have Conway's Game of Life running. Users select cells to flip live/dead, then can run a macro to run the entire thing. I think it'd be nice for users to be able to change cells as the macro is running. (which is a second on select macro)
Thank you
Sorry just reread the question. I wouldn't expect the permutation to run for very long - not long enough to interrupt really.
But if it does, then the advice about using lots of DoEvents stands.
The other option is that you can use the OnTime event to have a "heartbeat"
VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds
You can set the timer to say 3 seconds. Every time the OnTime event occurs you do one step of your permutation. In the three seconds in between they can edit.
Refactor your macro to use Events. In which case, you would have a series of event handlers (instead of one monolithic macro) to respond to various triggers. This is assuming that the macro is influenced by what the user is doing in the worksheet.
One way of (sort of) doing this is to use a Modeless Userform (UserForm.Show vbModeless)
The user form stays visible but the VBA stops running when the form is shown and the user can then interact with Excel. Then when the user clicks a button on the form the code behind the button starts running again.
So in reality the user is either interacting with Excel or interacting with the form ...
Is it possible to create a macro in MS Office (in this case Word) that will change other macro code? I was trying to find information but no results.
I have a doc which works as a template. Content of template is changed and then saved to another file. However it is important to have current date in it. It cannot be self-updated. Those docs go to folder of people and it is important to know when they get the document, so it must be simply data (or something that does not update).
I was thinking about an on-start event macro that would input current date and on exit it would ask "Do you want self-update functionality" Yes / No
If Yes, delete that event. However I have no idea if it is possible. If it is I still don't know how to search for it.
No this is not possible. In VBA, unlike some lower level languages when you define an event you can not disable it, even using other VBA code.
In C# or VB.NET, Java or C++ you can disable an event by un-wiring it from the handler, but this is not possible in VBA.
Maybe if you be more clear on what you need I can give you a better answer.
I am building a text based game, and thought of using a form instead of a console as i usually do.
So i started rebuilding a console - i created 2 text boxes, one as output and one as input.
I got the following problem while doing this:
In a console application you can use console.readline() in line.
E.g.: Dim str as String = console.readline()
now i need this effect in the form application, where i wait for the user pressing enter in the input box and getting the text he wrote.
E.g.: I ask for the character name and the user has to type it in the input box, now i need the name he typed in some way.
EDIT:
i guess i will need some way to wait for a event to raise without blocking the ui thread.
I appreciate any help solving this, Mylo.
To use the form as a console, you need to have your readLine method to wait for the event of the user hitting enter in the TextBox control, to do it without blocking the UI thread you need to use multithreading (hard) or tasks (difficult, easy with async programming), it's not an easy feat, so i think is better to use an old thrustworthy System.Console for this job.
However if you want to give it a try, there are some third party controls that may do it, like this one: http://www.codeproject.com/Articles/9621/ShellControl-A-console-emulation-control, there are others in Code Project so you may want to dig deep there and find one that you like.
Edit
This is a small async loop, note that i use also await.
do
await Task.Delay(100)
loop while (ReadingLine)
I think you're greatly overthinking this, my friend. The textbox is called TextBox1, on default.
So, to capture the data inside the text box, you say:
Dim someIdentifier As String = TextBox1.Text
And now you've captured the data in a variable, just like when you would capture it using
Console.ReadLine()
I need to update an Access VBA app with around 30 forms in it.
I have to amend a screen that seems to have been set up right at the start of the app, it uses a lot of SQL tables. Is there an way of finding my way to the start of the code?
I come from a procedural coding background and I am unused to code that doesn't have a start and an end; I also know a bit of VB, some ASP, some .Net and general computing.
When something "automagically" happens upon opening an Access database, it is almost always because
A "startup form" has been specified. (In Access_2010 that's done in File > Options > Current Database > Display Form.) ...or...
The database has a Macro named AutoExec which is automatically run when the database is opened (unless you bypass it by holding the [Shift] key down while opening).
In addition to #Gord's answer, there's a few things you need to know. I'm going to give you the quick & dirty version.
First, there's 2 types of code in Access. VBA & macros. Sometimes what's called a macro, is really VBA.
In Access, a macro is a set of instructions to do something to the database. It's very limited in what it can do. These are often used by novices who don't know how to program in VBA.
VBA is the real powerhouse behind the scenes. It can do everything a macro can do, but a whole lot more.
Access uses an Event-Driven / Object-Oriented (at least close enough for this discussion) interface. Do a Google search on those meanings. But very quickly, the listbox on a form is an object. It has properties (like width), methods (add an item), and events (click on an item).
To see the code, for macros look to to your navigation window to your left. For VBA (modules), look to the same window, or just press Alt-F11. VBA can be used standalone in a module, or behind the scenes of a form or report.
Once you get the hang of it, you'll find Access to be a handy RAD tool for small projects.
Good luck.
It appears that you already have found the form that opens when the app starts (if not, check out Gord Thompson's answer).
The first things that happen when an Access Form opens (the "start of the code", as you called it) are the Load and Open events.
If there is any code in this form that is connected to these events, then it's in the Form_Load() and Form_Open() functions in the code of the form.