VB.NET Recreating the console.readline function in a form application - vb.net

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()

Related

How to make an input box in VBS that is always open?

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.

Stuck in infinite loop. Any way to break vba into Code when Control+Break doesn't work

I have code stuck.
It might be in an infinite loop.
Not sure.
Is there a way to break the program to stop at the current line of code that it is running on?
I'd like to avoid shutting down excel because I want to be able to catch where in the loop it is, and by going into the code, I will be able to tell how much processing was done. I would like to break into the code, if possible.
It is stuck on hour glass.
Ctrl+Break doesn't seem to work
Seems like the running code has hijacked all the quota that cpu is giving to excel.
If there is nothing I can do now, is there something in the future I can do to where I can more easily break into the code?
I'm thinking that an intermittent wait within a loop might be a feasible solution.
In the future, include a DoEvents inside the loop. It will run a little slower, but you will be able to use Ctrl+Break to stop it from running.
Create a progress dialog when entering the loop and include a Cancel button. Within your loop check for the Cancel signal/event. This also gives you some flexibility on how you react to the Cancel - you could stop the loop and display key information in a new dialog box (for example).
Basic steps to achieve what I have described (not necessarily the most elegant or the most re-useable, but simple enough for those of lesser experience):
create a modeless (not modal) Form with either suitable labels or a progressbar item (for
visual effect). Include a public property (Boolean) for Cancel (e.g.
boolCancel)
Place a button on form and onClick set boolCancel = True
In your main code, show the form just before your problem loop.
while in your loop you can update some label or progress bar on the
form so that you have a visual indication of whether the loop is
doing something of value or if it is now simply spinning its wheels.
How you do this depends on what your loop is doing.
Also while in your loop check your boolCancel value. If true then
display any state information you want and break from the loop.
If your loop ends normally, hide/unload the progress dialog.

Capital Only Edit Control

Having a bit of a problem doing this and not sure of it can be done. I have an edit control that a user types into, I would like for the input to be all in capital letters. I tried having a custom action on the edit control to get the property, convert to capital letters and set the property again each time a letter is set but it does not work. I guessed it wouldn't but no harm in trying..:)
Has anyone else solved this? I would like to do it without having a button to press if possible. The dialog in question is a twin dialog if that helps at all.
Thanks for your help
It's not possible using the native built-in Windows Installer UI. The underlying MaskedEdit Control is primitive. There are no events to tie into to validate and modify as the characters are entered. You can only ToUpper() the property when the user clicks Back or Next.
The alternative would be to go with an external UI handler which is a lot of learning and work.

Script in IE to Insert Text at Cursor (in or out of IE)

I need to take text already obtained and stored in a variable and place it in another window: IE or any other windows application.
Context:
An asynchronous application is running in IE, most likely in the background, and when an event fires in the application, certain text needs to be inserted wherever the cursor/carrot is.
I am not restricted to any particular technology so if it even needs to be an ActiveX component I am open to anything.
This is something due for a project by the end of the week so ANY suggestions/ideas are VERY welcome.
Thank you in advance.
You'll need to write an ActiveX control that calls the SendInput function.
However, this sounds like a dumb idea. What are you trying to do?

VBA Status Bar

I am working on a Word VBA macro app for 80 or so users. The office has high staff turnover, so training suffers, and so one of the self imposed requirements for this project is comprehensive, friendly documentation. However, to supplement this, and to save newbies having to open up a 100 page document when they want to try something new, I want a status bar on every userform (there are five) that provides contextual help. I find tooltips annoying.
I don't have a lot of experience, so I was wanting to
Essentially, I have a file containing every status string. (This is currently a text file, but I was wondering if I should use a spreadsheet or csv for ease of editing by other staff in future.) Every control has a MouseMove event which refers to a function: getStatus(cID) that opens the file, grabs the line and displays it in the status label. It also grabs a few parameters from the same line in the file, such as whether the label is clickable (to link to a page in the help file), and what colour the label should be.
So a few questions really:
Will the application be slow if a userform is constantly referring to a file? It feels fine to me, but I've been in it far too long, and I'm the only user accessing that file. There will be 80 constantly accessing it.
Is MouseMove over a control the best way? Should I instead use co-ordinates?
Most importantly (in terms of me having to do as little work as possible) is there some way to do this so that I do not have to have a MouseMove event on every single control? I have a good few hundred or so controls, each with their own identifier (well, not yet, but they will if this is the only way to do it). Maybe when the form loads I could load ALL the possible status lines so they're ready for whenever the control is moused over. But then, maybe the loading time is negligible?
Appreciate any ideas or thoughts - especially if VBA already has a whole range of functions to do this already and I'm just trying to reinvent the wheel. I can't use the application status bar, because the user rarely sees the application itself.
Thanks!
EDIT:
It is for both data entry, clicking around and a bit of document generation.
It is a controlled environment so macro security issues aren't a big concern for me - and if something goes wrong it's someone else's fault or problem :)
Is this data entry app or do they just click stuff? Because often the field with focus is different to the item the mouse is hovering over, this can cause a lot of confusion.
Constantly reading from a file is a huge waste of time and resources - it is much better to load them only once into an array or collection when the form is loaded.
On MouseMouse event is better than coordinates because you can move things around without worrying. It's a lot of code but you should be able to generate most of that if you have a list of control names because the code should be identical.
ie
Sub Control_MouseMove()
DisplayStatus(Control)
End sub
I would consider the StatusText property and ControlTipText property of controls for this kind of help.
StatusText
This example sets the status bar help text for the form field named "Age."
With ActiveDocument.FormFields("Age")
.OwnStatus = True
.StatusText = "Type your current age."
End With
ControlTipText
This can be assigned from the property sheet for the control.
Private Sub UserForm_Initialize()
MultiPage1.Page1.ControlTipText = "Here in page 1"
MultiPage1.Page2.ControlTipText = "Now in page 2"
CommandButton1.ControlTipText = "And now here's"
CommandButton2.ControlTipText = "a tip from"
CommandButton3.ControlTipText = "your controls!"
End Sub