Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pause and wait for user input??? 2

Status
Not open for further replies.

dlingo

Programmer
Nov 19, 2001
60
US
I'm writing an application that tests 1 text file for any words that are contained within another text file. The idea behind the application is to search one test file that contains 1 word per line and store these words in an array variable. Each time a word is found the second text file is searched for any occurence of the same word. I'm using two Do While Loops (1 to search each text file). The 1st DO loop goes until a word is found in the first text file and then calls the next DO loop to search the second file. When the word is found in the 2nd text file I want to pop-up a form allowing user input before moving on to the next occurence. Basically, I want to break out of the DO Loop, wait for user input, and then return right where I left off. How can I do this? I don't want to use a MsgBox....I need to use a form... Thanks in advance.
 
create a form that prompts for user input.
create a global variable that holds the result.


Use this code to show your form
MyForm.Show vbmodal

WHen the user clicks Ok or whatever set the value to the global variable and then unload the form.

Code will execute as normal once MyForm has been unloaded
 
It would be a lot easier to use the standard function "InStr()".
 
bjd4jc,

That sounds like exactly what I need to do and I'm already using the MyForm.show option to show the user input form that I created. The problem is that each time it finds a word it shows the form (I can see that in debug mode), but doesn't wait for user input before checking the next word. What do you mean create a form that prompts for user input? How is this done? What do you mean by vbmodal?
 
You might want to use and inputbox(). this will wait until the user answers the question and presses enter.
 
bjd4jc is right on

the vbmodal is the key to making this work. vbmodal instructs the OS to suspend all application processing execept within that window. The only thing that I would add, is a DoEvents

MyForm.Show vbmodal
DoEvents

After the user enters the input on the form, you need to Unload the form and processing will resume at the line following the .show and/or doevents
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
CajunCenturion and bjd4jc,

We are definately on the right track. vbmodal was the key. There is a pause for user input for each occurrence of a word, which is what I wanted. However, based upon the user inputs (IGNORE, or RECORD) I want to record the incidents of each word to a text file that is viewable by the program user once execution is completed. However, in vbmodal mode permission to write to a text file is denied.

I do something like this:

UserInput Form Code:

Public Sub cmdRECORD_Click()
Unload UserInputForm
Call MyModule.AppendText("Record")
End Sub

MyModule Code:

Public Sub AppendText(UserInput)
If UserInput = "Record" Then
Dim fso, txtfile
result_file = myfile.txt
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso_OpenTextFile(result_file, 8, 0)
* txtfile.WriteLine "Some stuff here"
End Sub

* Permission Denied '70' occurs here.

I can't understand why since I've unloaded the form before calling the subroutine. Any help?
 
The permission error is not due to the modal form.

You might try adding a True to create the file if it doesn't exist like the following:

Set txtfile = fso_OpenTextFile(result_file, 8, True, 0)

and you should also close the file after the write.

txtfile.close
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Sorry, I kind of dropped out of this.. I had a meeting to attend and several problems popped up after that and I am just now looking at all the responses.

I think Cajun is right in that the permission error is not due to vbModal.

Let me know if you need some more help.

Brian
 
I only have one more problem. Since the User Input form is in modal form (I think). Clicking on the X (upper right corner) does not close the form it continues the DO loop. Is there a way to allow the X to close the form even when in modal form.

I also wanted to thank the two of you. You all have been a HUGE help!

 
Clicking on the X in the corner can not be done on the parent form when the child is vbModal. It can be done on the child form though.

Are you wanting the Do loop to stop when the user clicks on the X on the User Input form or when they click on the "Do Loop" form? What are you wanting to happen when the X is clicked?
 
I've figured it out now. Thanks again guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top