Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Open/Close Program


I'm trying to write a program that will be able to open a file, apply values from the file in an array, close that file. If I try to open another file and apply a different number of values to the same array (even if I redimension it first), I get a 'Subscript out of range' error.

I think the best way around this error is if I can simply restart the program.
Is there a way to run a separate vb program that will close the current program, and re-open it?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Close.. Open Program
I use the shell program to open my internet explorer.... Now I want to close it by clicking a button on my program... How can I do this.. does any one could give me a code.. thanks

Close Program If There Are 2 Of Them Open.
Well. I am designing a new program and it's a trial run with only one allowed per machine. so you can't have like 30 open.

do you know how to make it so it closes if there are two projects open

Open A Program And Wait To Close
somebody else posted this code. sorry i can't remember who to give credit, but here it is.

thing is i find msiexec returns 0, even if the patch is not applied (eg cos app version is newer than patch for example).... anybody know how to capture this????




Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As _
Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As _
Long, lpExitCode As Long) As Long
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400


Private Sub Main()

Dim htask As Long
Dim hProcess As Long
Dim exitCode As Long

htask = Shell("msiexec /p ""C:updatertestPatchPackage.msp"" /qn")
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, htask)

Do
' relinquish this CPU time slice
DoEvents
' query for exit code
GetExitCodeProcess hProcess, exitCode
Sleep 100
MsgBox exitCode
Loop While exitCode = STILL_ACTIVE

MsgBox "Exit code = " & exitCode, vbInformation

End Sub

Open A Program And Wait To Close
Hi, I have this question, I have a example on one VB book in my home, I'm currenctly in work, how I can open a program and stops the code execution until be closed. ???

Thanks !!

Use SHELL To Open A Program, But What To CLOSE It ?
OK, I have a stupid question ....


I want to close a program I call from my app. I cant figure it out !

Lets say I use Shell to open it, and get its AppId ... How can I use that AppId to close that instance of that program ?

I have tried and tried to even use AppActivate and sendkeys, but for some unknown reason appactivate wont work anymore from my app. Says error 5, object not found or some stupid crap. But regaurdless, I dont care about appactivate, I just want to close the AppId I call from shell.... Not a hard problem, right ? :-)

Ok, and another quick question is, lets say I shell IEXPLORE.EXE and want to send a new string to the SAME APPID, not a new instance of the program (Navigate to another site from THE app I called, not a new one) - how can that be acomplished ? I dont even know where to begin with that one...


Thanks to all !

BaLLZaCH
ballzach@ballzach.com

Visual Basic 5 and 6

Open A Program And Wait To Close (using ShellExecute)
Hi, I posted this before, but this have a one little thing more:


I need to open programs using ShellExecute (API) instead of Shell (VB), because I'm trying to open a MSI Installer File (Visual Installer File), and if I use Shell don't works. Is there some process to make this ??


Thanks in advance !!

How Can I Open, Paste, Save, And Close A Program?
How can I open a program (in this case notebook or word), paste text from a textbox into notebook, save it as a text document and close notebook? Prefferably, with just using one command button. Thanx.

Close Previous Instance Then Open Same Program
Most posts I've searched come somewhat close to my problem, but don't address it squarely.

My program is called RevLook and takes a phone number passed in from a command prompt as a parm, invokes a reverse lookup page on the Web, pastes the number on the page, and submits the query. The reverse lookup engine then displays the results in my WebBrowser Control.

Next the program will be manually called the same way with a different phone number, at which time I want to close the first page (instance) before invoking a reverse lookup page on the Web, etc., once again displaying the results of the lookup of the 2nd number.

I'm missing something because both windows show up with the most recent, of course, having focus. How can I close out the first window, then display the next? My code follows:

Option Explicit

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByValhwnd As Long, _
  ByValwMsg As Long, ByValwParam As Long, ByVallParam As String) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, _
  ByVal lpWindowName As Any) As Long

Private Sub Form_Load()
        Dim lngWin as Long
        If App.PrevInstance = True Then
           lngWin = FindWindow(vbNullString, "RevLook")
           SendMessage lngWin, WM_CLOSE, 0&, 0&
        End If
    
    Dim strTelno As String, strArea As String, strPhone As String
    ' capture the parm passed in and parse
    strTelno = Command()
    strArea = Left(strTelno, 3)
    strPhone = Right(strTelno, 7)

      With WebBrowser1
        .Navigate "http://www.anywho.com/rl.html"
        Do Until .Busy = False
            'This just makes sure the page is loaded
            DoEvents
        Loop
        
        'Put phone number in search page and execute
        .Document.All("npa").Value = strArea
        .Document.All("telephone").Value = strPhone
        .Document.All("btnsubmit").Click
        
    End With
    
End Sub


Thanks for any help or ideas.

Keeping A Checkbox Checked Even When You Close And Open The Program
I want to be able to make one of my checkmark boxes that are checked stay checked and if it is not checked, stay not checked (I'm talking about when you close and open the program, its state stays the same). Also I need to be able to decrypt what is in the textbox...If you need to know this is an option to save the password, and Ive already got it to save to an ini file but I need to encrypt that and have the program decrypt that. Any help?

Should I Have 100s Of Winsock Connections Open/close.. Or Keep Them Open (hard Q)?
Hello
Ive got a server to which many clients connect to.

They each are given a few tasks to complete - which may or may not take a long time to finish, and after each task is done they send back the result.

This has caused massive amounts of problems for me. Right now I keep the connections open all the time. My server listens on one particular winsock control on a particular port to which all clients connect. It then accepts the connection request thru a second array of winsocks, so each client is connected to the server via the array via one connection.

There is generally no problem sending out the tasks thru that single connection/client - but receiving is a problem. The client may need to send back a few hundred kb at a time but since it was completing several tasks at once - it is not always received correctly. My guess is because taskA is sending data thru the connection at the same time as taskB - and the data isnt received right (each task sends its data via a <start> and an <end> string so I know where the start/end of data is and when transmission is over). Its important to note that the tasks are multithreaded (via a 3rd party control)

The data is sent in one line per task. winsock.SendData theResult. But many tasks can complete at around the same time. I thought that VB would wait until the data was completely sent (for one lines code) before moving on... but I dont think this is happening. I even tried adding a DoEvents but to no avail - I still cant receive the data properly. Maybe winsock is 'skipping over' some data - I dont know. (Kinda like when if you 'break' the application winsock does not get incoming data and when you resume it still wont pick it up)

So Ive got 2 options..
1) Somehow figure out how to receive data properly when multiple tasks finish on a client at around the same time and they send data at the same time - basically making the program send the data of a task and not continue until the data has been sent, then send another tasks data.

2) Use many connections. Basically the max # of tasks running at once will be about 10. So the idea is to have another winsock array of 10, each dedicated to one task, and when a task is completed - connect thru the winsock array, send the data, and when the server receives it - it disconnects.

3) A mixture of 1 and 2 - have the 10 winsocks connect to the server and be open at the same time, then I can just send data and receive via a specific winsock array control and there is no problem distinguishing taskA from taskB from taskC on a client, or client from client.

But honestly.. I dont know if its 'bad' to have lots of connections open and close all the time. And I dont know if its 'bad' to have thousands of connections open at the same time either..

What do you guys think?

Open An Excel Worksheet, Close It, Perform Cleanup And Open It Again - Can't Do It
The attached code allows the user to browse for an excel file, open it, and then the code automatically closes it and performs cleanup on the excel objects. I seems to work fine the first time the user opens an excel file, but if the user tries to open an excel file a second time, there is an error. Why is this?

Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?

Thanks in advance.


-Jer

Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?

Thanks in advance.


-Jer

Close Program After Excel Program Executes
I am having a problem unloading my program after I complete an automation to excel process. Basically I pump a bunch of data to an excel workbook, save it as a file name, shut down excel. Now I want to close the exe, but it is not unloading. What am I missing (maybe I need to set focus back to the exe, how can I do that if that is the case?)

Thanks!

oapp.ActiveWorkbook.SaveAs FileName:="\master log" & Format(Now, "m-d-yyyy") & ".xls"
oapp.Quit

Set oapp = Nothing

Unload Me

Close Then Re-open App
I am trying to find a solution that will close and then re-open a vb app if it is idle for more than 30 mins
The reason is because I was told that vb apps don't release memory so I want to sort of "auto release or refresh the memory" any ideas?

Open Close
When i user this code to open a file:

Code:
Open FName For Input As #1
Input #1, Data
Close #1
Edit1.Text = Data
It opens the first line or up to the next ','. What is the correct method for opening a file?

Open/close Cd-rom
how do you open/close the cd-rom in vb5?

Close An Open Exe From A Different Exe
How do I close an open Exe from another Exe?
Once I close this Exe I want to delete this Exe from another Exe, Please let me know as to how can I do this?

How Do You Close An Open App?
If I want to close something with code, and I know its running, like ms word or something, how would I go about doing that?

Open/Close Cd Rom
hey..how can i open and close the cdrom using a command button?

Close And Open Again ...
how i can close my program and open it again ...

On Close Open App
how do i do something like on close of application or on error open "shell code here"

How To Open/close CD-ROM?
Hi

Does anybody know how to open/close CD-ROM?

I'm really a amatuer so..............

Thnx!

Netherlands

Close Exe That's Open?
I need to close an Exe that's already running. I know the window title, and the name of the exe. Thanks for any help!

If Open Then How To Close
In my code I'm creating a log file of some of the events I'm trying to track. Every now and then when the program checks to see if the log file exists it flags that its open then immediately exist the sub. Meanwhile it missed an entry. The error I receive tells me that the log file is open when checking for the existance.

What am I missing:


Code:

'declaration
Public strChecker As String

'create migration logs
Public Sub LogName()

Dim strLog As String
Dim Location As String


Location = App.Path & ""
strLog = Location & strLogName & ".log"

strChecker = strLog
FileExists
If intTest <> 0 Then
Open strLog For Append As #1
Else
Open strLog For Output As #1
End If

'the information for the log goes below

end sub

''if intTest=0, then there is no file to replace. Anything else means it exists.
Public Sub FileExists()

intTest = Not (Dir(strChecker) = "")
strChecker = ""

End Sub




If the log file was left open for some reason intTest returns a -1 indicating the fileexists, thats good, but when it returns to the if then above and tries to append the file it jumps out.

Is there a way to check to see if "c:crap.log" is open before appending then close it.

TIA,

Close All IEs Open
Anyone have a code to closes all instances of IE open,not just the active one?

Thanks

CD Open And Close
does anyone know how you can open and close the cd-rom drive with visual basic?

Launch/close Program For Another Program
I help out at a Boys & Girls Club in their computer lab. They recently got a copy of Sim City 3000 donated, but this program is having issues with their Windows XP OS. If you go here, "SimCity 3000 restarts spontaneously when exiting", you can see the problem we are encountering. I was wondering if writing a small program to launch SimCity 3000, then catch it when it exits and force it to close down programmatically is possible? If so, how difficult would it be? I assume it would require several various API calls.

Program Still In Process When Close Program
Hi There,

I've come across a strange but annoying bug, but i cannot seem to track it down. when I close my program (its been compiled), the program still stays in the process (Ctrl+Alt+Delete).

Would this be some sort of memory Leekage???

The strange thing is this happens in one form only that i can figure out becuase the other forms don't do it.

Stranger thing is that both, or i should say all forms are build on the same building structure.


Code:
'This is in the Form_Load Sub

Set Me.Picture = LoadPicture(App.Path + "ImagesPODFormWindowPODFormWindow.bmp")
PicXButton.Picture = LoadPicture(App.Path + "ImagesSharedXButtonShaded.bmp")
Set CmdCancel.TopPicture = LoadPicture(App.Path + "ImagesSharedhanddown.bmp")
Set CmdGoToPrint.TopPicture = LoadPicture(App.Path + "ImagesSharedhandup.bmp")

Also i have built a usercontrol that as you can see adds a bitmap to it and manipulates it(Transparent, blending etc), should i be using lets Say UserControl_Terminate to do some clean up stuff

the pig..

? On Open / Close Files In VB
Hi,
I have a text file (see below) that I only care for "Port x/xx" at the end of each line. This is the output of a Cisco switch from issuing the "show logging buffer 1023" command and the output is being captured to a text file.
What is the best way to remove all the duplicated "Port x/xx" on each line?
Based on my limited VB experience, I can only think of opening 2 files within VB. 1) being input and the other being output. Read the text file one line at a time and using a string command to keep only "Port x/xx" and write that info into a second file. In the end, I will have the second file that contains all the "Port x/xx" with no similar entries.
I notice using open/close files in VB is time consuming imagine there are 25 of such logs I have to go through. Are there different or quicker methods to get this done?

Thanks in Advance,

Log file starts here
==============
2004 Mar 09 09:34:05 %PAGP-5-PORTTOSTP:Port 3/14 joined bridge port 3/14
2004 Mar 09 09:34:25 %PAGP-5-PORTFROMSTP:Port 3/14 left bridge port 3/14
2004 Mar 09 09:34:33 %PAGP-5-PORTTOSTP:Port 3/14 joined bridge port 3/14
2004 Mar 09 10:02:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 10:03:46 %PAGP-5-PORTTOSTP:Port 2/28 joined bridge port 2/28
2004 Mar 09 10:32:46 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:32:54 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 10:34:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 10:37:50 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:37:59 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 10:42:10 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:42:18 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 11:06:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 11:23:33 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:24:04 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:24:44 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:25:18 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:26:28 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:26:34 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:38:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 12:10:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 12:42:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
Log file ends here
==============

Open And Close Access
Sounds simple enough, but I'm not quite sure where to start. I used the tutorial for opening and closing Excel, but it looks like the commands are different and after a lot of searching, I still cannot find a code example of how to open and close Access from VB. If someone could share a code snippet, I'd really appreciate it!

Close Open Folder
I am using a shell command to open a folder. How can I close it afterwards?

If Recordset Open, Close
VBA for Access 2002:

What's the best way to do this? The two examples below produce Object Variable ir Wirh Block not set, or Runtime 91 errors

' if recordset is open, close
If rs.State = 1 Then rs.Close
If rs.State And adStateOpen Then rs.Close

Thanks in advance for the help...

Open And Close With 1 Button :(
hello ppl, i'm new to vb and i have a problem...

i have 2 forms.

the 1st with a button called 'show wage details'

the 2nd form which has no buttons (no buttons needed).

now my problem...

i want to use the 'show wage details' button, so th@ when its pressed, the 2nd form will show, the caption will change from 'show .....' to 'hide ......' and then if th@ button is now pressed after the caption change, it will hide the 2nd form and re-display 'show .....' again.

i can change the caption and show the 2nd form, but i cant get my button 2 function as a hide form or get the caption to change.

plz if ne1 can help me, i'd be very greatful

thanx for the help

Do Not Close App If FORMS Are Open
Is there a way of stopping an application from closing if other forms are still loaded. So before they can close the app they must close the other forms.

I know you can do if form.visible then cancel = true

but is there a general thing where it knows whether other forms are visible or not.

Thanks

Open And Wait To Close
Hi, How I can open a file using the Filename, and wait to be closed, it means, stops the code execution.

Thanks !!

How To Close All Open Files...
I open a file to write to it, but sometimes it will come back and say file already open. How can I make sure that all the files in my application are closed?

Open/Close, Write/Put...
I have a server/client program that I have been working on. The client opens up and ftp's its ip to a secure site. The server starts up and downloads all the ip's from the ftp site.

The purpose of this is to be able to help friends with their pc's AND as a way to kind of set up a server for a game I have been working on for me and a few friends. This would allow for easier connections and help me avoid having to send ip's over email before each session.
It then pings and lists all available ip's. I request a connection and I am accepted. I request a directory listing and receive it.

I need to be able to download files from the other computer. I have been succesful with .txt files but NOT with .jpg and other formats. Here is what I was using.

The client does this:

Dim i As Integer
Dim sTxt As String
i = FreeFile
Open strFileToSend For Binary As #i
Do Until EOF(i)
DoEvents
Line Input #i, sTxt
buff = buff & sTxt & vbCrLf
Loop
Close #i
wsClient.SendData "FILE" & strFileToSend & "," & buff


The server does this:

Open sFile For Binary As #1
Put #1, , strFileData
Close #1


I have never worked with winsock much and admit I don't really understand what opening as binary does.... is there anything obvious to you that I am not seeing.

Basically I need to be able to request and receive files from other pc. Thanks for ANY help you can offer. This is currently the only thing holding my project up. Thanks.

New - Close Open *DELETED*
Post deleted by UseTheMan

Help Me Close Open Programs
In my program i want to "see" the path of all programs and close certain one
s, depending on the users settings. How do i find the paths of OPEN programs
and then terminate them?

How I Close All Form That Open Under Mdi?
i want to close every form that open under MDI how code it

Open/close Cd Error...
i have this code that should open/close the cd-rom when i click on a button but it gives an error wich i dont understand. What is wrong with it?
This is the code i use.


Code:
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Dim lngReturn As Long
Dim strReturn As Long


'This one opens the cd door:
lngReturn = mciSendString("set CDAudio door open", strReturn, 127, 0)

'and this one closes the cd door:
lngReturn = mciSendString("set CDAudio door closed", strReturn, 127, 0)

Open Exe File, On Close Do...
A bit cryptic...

What i want is, to start a exe file (with shell command). If i close this same exe file ,the program (code) witch has started the exe must do something. How can i do this???

Carlito

Open, First, Next, Last , Prev, Close
(new at databases) I'm at the onset of trying to create a simple example of a bringing up one-at-a-time (Access 2000) table databases (topics: one db on colleges, one db on airports, one db on students) and displaying the contents in individual textboxes ... not using the ADO or Data control as the goal is to build this without using a control and manually code all buttons and making the fields show up in specific textboxes.


I have created an interface that has:

- one input textbox to enter the desired database name - user has a choice of three.

- one command button to open the entered database name.

- various command buttons for moving to First, Next, Last, Prev records and possibly adding, deleting, searching records.

- various textboxes for every individual item to display based upon which database was entered ... such as college or airport name, code, address, city, state, zip, phone, website, email address, etc., SSN, student name, student address, etc.


I know the db has to be opened, recordsets defined, txtboxes defined, amongst other events that I'm unsure of ... I'm looking to see if there is an example on something like this? Then I could see the pieces needed and how it's put together. Just something similar, even if it only shows one database, that would give me an idea how to do this.

I can show what I've done so far, no way is it close, just has snippets of code for now, definitely not complete, but it's where I am at ...

Can anyone help? simple examples?

Attached what I have built so far.

Keep Connection Or Close &amp; Re-open?
I have a VB app that allows up to 10 clients to access an Access 97 db (typically about 50 meg in size) on an NT server. Each client opens one connection to the database and the connection remains open as long as the app is running. The app typically needs to create and close many recordsets.

Anyone have an opinion as to whether this is a poor practice? If so, what problems might it cause. Also, what effects might I see if I continually open and close connections as they are needed?

(using DAO now but am currently upgrading to ADO)

How Can I Check And Close Any Open Cn Or Rs
Hello

How can I check is there any Open Connection or Recordset to database from any where taht I need?

And how can I close any open Database any time I need?

VB6 & Access & ADO

Thanks

Open And Close Txt File
hi im trying to align the name and the email address can someone help me out?

Private Sub cmdcontact_Click()
'Save Contact
Open "contact.txt" For Append As #1
Printer.Print "txtname.Text", "txtemail.Text"
MsgBox ("Contact Saved")
End Sub

it ends up coming out like this in the text file

jim mack jmack@gmail.com
Albert Sanchez ASanchez@gmail.com
Chris Jones Cjones@mail.com

Close Files That Are Not Open
I am downloading file from the internet with freefile
FileOne = Freefile
FileTwo = Freefile
FileThree = FreeFile
After each file is downloaded then
Close #FileOne, Close #FileTwo, Close #FileThree
The connection could be interupted at any point or the form closed
Is this wrong?
on error resume next
Close #fileOne
close #filetwo
close #file Three
On error goto error handler
I realize i could write a module boolean for each file and set it to true when they get succeffuly opened and then downloaded and then selectly close them.
Sure be a lot easier to just close them all even if they are not open.
Bad idea?

Close All Open VB Windows.
Is there a way to close all the open code and form windows in VB?

It's just that when I stop the program I have to wait for all the open windows to refresh before I can do anything.

It's getting worse as my program gets bigger.

Copyright © 2005-08 www.BigResource.com, All rights reserved