I'm a newer and I was asked to made a VB program to using some 3rd party APIs.
Those API do not need any windows, so I made the program by VB, put all functions in formload(). But how can I close the windows?
I'm using 'End' before 'End Sub', it looks that the window was gone, but when I going to the task manager, it still show in the 'processes'.
I can I close it at all?
If you love it, you get it.
If you don't love it, you never get to it.
It is a misconception that a Visual basic program must have a window.
If you have a .BAS module with a Sub Main you can set this to be the startup procedure and it will run and exiot when it gets to the end e.g.:
public Sub Main()
If Command$() = "" then
MsgBox "Application run with no parameters"
else
MsgBox "Application ran with parameters - " & Command$()
End If
End Sub
After pressing OK on the message box the program will unload completely.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
chairyuan
June 13th, 2001, 11:04 AM
Because this program is basically a background program in server, I really do not want any screen comes up.
I've tried to set form visiable to false, and 'End' or 'Unload Me' in the end of my process. In that way, the form will not appear, and program will end in application.
But when I look at the NT task manager, in the 'Processes' view, it still shows there. Each time I call the program, it will have one more in the 'Processes' view.
I don't know if that's Ok or not, but I think for more than 1000 calls a day, it will be a pain.
If you love it, you get it.
If you don't love it, you never get to it.
chairyuan
June 13th, 2001, 11:11 AM
I've tried 'Unload Me' same as 'End' in the end of my process. In that way, the form will not appear, and program will end in application.
But when I look at the NT task manager, in the 'Processes' view, it still shows there. Each time I call the program, it will have one more in the 'Processes' view.
I don't know if that's Ok or not, but I think for more than 1000 calls a day, it will be a pain.
Here's part of my code:
private Sub Form_Load()
Dim setMode_result as Integer
Dim send_result as Integer
Dim Ms as string
Dim Ml as Long
' Ms = "0000000103Testing Company 1st name Test comp last name (770)623-0331 (1605) ACTIVESALES 000103SE42000-01-01 END"
' Ml = len(Ms)
' MsgBox Str(Ml) + " ---- " + Ms
'Some API calls
Unload me
' or End
End Sub
If you love it, you get it.
If you don't love it, you never get to it.
TH1
June 13th, 2001, 11:11 AM
As Clearcode says just use a sub main and then you have no need for a form. If your program is not exiting correctly don't use the end statement as this does not close the program correctly and references may be left in memory leading to memory leaks. In fact I would NEVER use the end statement for this reason.
If you use any set statements in your program ten make sure the you use the set to nothing statement as well to insure that memory is released. Close and set to nothing any recordsets,connections you may have to a database as not doing this may cause the program to remain in memory as well leading to the problem you describe.
chairyuan
June 13th, 2001, 11:50 AM
Sorry I'm a newer in VB.
While I open VB, it always ask me for project. But seems all projects has a start up form?
How can I made a program only have Sub Main()?
If you love it, you get it.
If you don't love it, you never get to it.
Clearcode
June 13th, 2001, 12:12 PM
Right click on the form and select the context menu Remove Form1
Then select the menu Project->Add Module and put the Sub Main() in that.
Finally, select the menu Project->Properties and set the dropdown list marked Startup Object to Sub Main.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
chairyuan
June 13th, 2001, 12:18 PM
Thanks for help
I made that. But after I call it in Dos command line, it still stay in 'Processes' in task manager.
I did open workspace, database, querydef... But I closed all those things before sub end.
I also use a 3rd party APIs which using a DataLink to send a message to AS/400 (which is another machine). That should not effect my program - it just a send, not commit, not confirm ...
If you love it, you get it.
If you don't love it, you never get to it.
'Some API calls
'Your matter seems related to those "Sime API calls": one of them may be still running in background; Ie: if you create a timer via Api, you should kill it before quitting. You may build an application which does not end even with "normal" code, for example building a loop and inside having a DoEvents statement: if quitting before ending loop, App will not close. You should post more code if you want people here to look for a solution.
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
chairyuan
June 15th, 2001, 09:15 AM
Private Declare Function EHNDQ_SetMode Lib "EHNDQW32.DLL" (ByVal shwnd As Integer, ByVal slploc As String, ByVal smode As Long) As Integer
Private Declare Function EHNDQ_Put Lib "EHNDQW32.DLL" (ByVal mhwnd As Integer, ByVal mlpname As String, ByVal mlploc As String, ByVal mlpbuffer As String, ByVal mdl As Long) As Integer
Private Declare Function EHNDQ_Send Lib "EHNDQW32.DLL" (ByVal mhwnd As Integer, ByVal mlpname As String, ByVal mlploc As String, ByVal mlpbuffer As String, ByVal mdl As Long) As Integer
Private Const EHN_OK As Integer = 0
Private Const EHN_Xlate As Long = 9
Private Const EHN_hwnd As Integer = 0
Private EHN_Name As String
Private EHN_Location As String
Private DataSource As String
Private Sub Form_Load()
Dim setMode_result As Integer
Dim send_result As Integer
Dim CompCode As String * 10
Dim ComLine As String
Dim Ss As String
Dim Ws As Workspace
Dim Db As Connection
Dim Qd As QueryDef
Dim Rs As Recordset
Dim Ms As String
Dim Ml As Long
Dim S01 As String * 10
Dim S02 As String * 40
Dim S03 As String * 40
Dim S04 As String * 20
Dim S05 As String * 10
Dim S06 As String * 6
Dim S07 As String * 6
Dim S08 As String * 6
Dim S09 As String * 3
Dim S10 As String * 10
Dim S11 As String * 3
Dim S12 As String * 3
Dim S13 As String * 3
Dim S14 As String * 3
Dim S15 As String * 3
Dim S16 As String * 15
Dim S17 As String * 10
Dim S18 As String * 1
Dim S19 As String * 1
Dim S20 As String * 30
Dim S21 As String * 30
Dim S22 As String * 28
Dim S23 As String * 2
Dim S24 As String * 15
Dim S25 As String * 1
Dim S26 As String * 20
Dim S27 As String * 26
Dim S28 As String * 10
Dim S29 As String * 1
Dim S30 As String * 10
Dim S31 As String * 30
Dim S32 As String * 30
Dim S33 As String * 28
Dim S34 As String * 2
Dim S35 As String * 15
Dim S36 As String * 10
Dim S37 As String * 3
Dim S38 As String * 200
Dim S39 As String * 3
Dim S40 As String * 3
' Read INI file to load variables
Read_PAL_DQ_INI
' Get arguments from Command line (CompCode)
ComLine = Command()
If Len(ComLine) = 0 Then
ComLine = "0000000107"
' Ms = "0000000103Testing Company 1st name Test comp last name (770)623-0331 (1605) ACTIVESALES 000103SE42000-01-01300 000 00000000103100 A trangel Norstreet Norcross GA30092 USA ABC"
' Else
End If
CompCode = ComLine
MsgBox (CompCode)
' Set database connection
Set Ws = DBEngine.CreateWorkspace("TESTWS", "", "", dbUseODBC)
On Error GoTo ERR_WS
Set Db = Ws.OpenConnection(DataSource, False, True, "odbc; uid=Administrator;pwd=240zx;")
On Error GoTo ERR_DB
' Build select statement to get information from Gmcmpany
Ss = "SELECT comp_code, company_name_1, company_name_2, comp_phone, head_code"
Ss = Ss & ", nh_comp_status, nh_mkt_segment, nh_customer_numb, nh_sales_terr"
Ss = Ss & ", nh_cust_class, nh_price_class, nh_master_terms"
Ss = Ss & ", nh_tax_code, nh_max_credit_line, nh_resale_numb, nh_national_acct"
Ss = Ss & ", nh_leasing_co, nh_allow_multi_ship, nh_billing_addr1, nh_billing_addr2"
Ss = Ss & ", nh_billing_city, nh_billing_state, nh_billing_zip, nh_cert_filed"
Ss = Ss & ", nh_credit_fname, nh_credit_lname, nh_credit_salutation"
Ss = Ss & " FROM gmcmpany "
Ss = Ss & "Where comp_code ='" & CompCode & "'"
' Build the query definition
Set Qd = Db.CreateQueryDef("GetRecords", Ss)
' Execute the query and assign to recordset object
Set Rs = Qd.OpenRecordset(dbOpenSnapshot)
On Error GoTo ERR_RS
' Test if there are any records, reset pointer to first position
If Rs.EOF = False Then
Rs.MoveLast
Rs.MoveFirst
'Build select statement to get information from Gmcm_addr
Ss = "SELECT numb_, comp_code, address1, address2, city, State, zip, country, dest_flag, nh_ship_instr "
Ss = Ss & "FROM Gmcm_addr "
Ss = Ss & "Where comp_code ='" & CompCode & "'"
'build the query definition
Set Qd = Db.CreateQueryDef("GetRecords", Ss)
'execute the query and assign to recordset object
Set Rs = Qd.OpenRecordset(dbOpenSnapshot)
On Error GoTo ERR_RS
'test if there are any records
If Rs.EOF = False Then
'reset pointer to first position
Rs.MoveLast
Rs.MoveFirst
'set DataQueue API to translate mode for ASCII to EBCDIC
setMode_result = EHNDQ_SetMode(EHN_hwnd, EHN_Location, EHN_Xlate)
If setMode_result <> EHN_OK Then
MsgBox "Error in EHNDQ_SetMode"
MsgBox Err
MsgBox Error$
Else
MsgBox "EHNDQ_SetMode successed"
End If
'send message to DataQueue in AS/400
send_result = EHNDQ_Send(EHN_hwnd, EHN_Name, EHN_Location, Ms, Ml)
If send_result <> EHN_OK Then
MsgBox "Error in EHNDQ_Send"
MsgBox Err
MsgBox Error$
Else
MsgBox Ms
End If
END_ALL:
Unload Me
' End
Exit Sub
ERR_WS:
Debug.Print "Error:"; Err, Error$
MsgBox "WorkSpace not created -- ERROR WS"
Resume END_ALL
ERR_DB:
Debug.Print "Error:"; Err, Error$
MsgBox "Connection To Database Could Not Be Established -- ERROR DB"
Ws.Close
Set Ws = Nothing
Resume END_ALL
ERR_RS:
Debug.Print "Error:"; Err, Error$
MsgBox "Get ResaultSet error, may not have records -- ERROR RS"
Rs.Close
Set Rs = Nothing
Ws.Close
Set Ws = Nothing
Resume END_ALL
End Sub
Private Sub Read_PAL_DQ_INI()
Dim filename As String
Dim fnum As Integer
Dim i As Integer
Dim TempString As String
i = 0
Do Until i = 3
Line Input #fnum, TempString
If Left$(TempString, InStr(TempString, "=")) = "DQ_NAME=" Then
EHN_Name = Right$(TempString, Len(TempString) - InStr(TempString, "="))
End If
If Left$(TempString, InStr(TempString, "=")) = "DQ_LOCATION=" Then
EHN_Location = Right$(TempString, Len(TempString) - InStr(TempString, "="))
End If
If Left$(TempString, InStr(TempString, "=")) = "DQ_LOCALSOURCE=" Then
DataSource = Right$(TempString, Len(TempString) - InStr(TempString, "="))
End If
i = i + 1
Loop
Close #fnum
End Sub
If you love it, you'll get it.
If you don't love it, you never get to it.
Cimperiali
June 15th, 2001, 10:53 AM
Sorry: know nothing about "EHNDQ_SetMode"...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
chairyuan
June 15th, 2001, 09:57 PM
EHNDQ_setMode is to set a data transfer mode (from ASCII to EBCDIC, which is used in AS/400, which is one of the IBM mini machine);
EHNDQ_send is to send a message the the created data queue (like a message queue in the remote machine).
This program suppose to get information from SQL Server tables, join it to a string, then send to remote machine.
I've closed the DB things, and the remote data queue will start and stay there without the program runs.
When the program finished, It not in the applications any more, but still can be found in 'process' some how.
If you love it, you'll get it.
If you don't love it, you never get to it.
Cimperiali
June 18th, 2001, 02:29 AM
I do not know if this is the case, but once I had to read from as400. The query was simple, and was supposed to open a "file" to retrieve some of its data with a "where" clause. What happened was: Vb showed data correctly in brief time, but on As400 there still was a job running: even if query seemed completed on PC, on as400 it was still reading data (it went to end of file before closing). The result was: it was impossible to close application until all data been read on As400. The only partial workaround we found out was to send query using "Top" to retrive only some data...
Hope this may give a clue on matter.
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.