CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jun 2001
    Posts
    69

    About quit the program

    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.

  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: About quit the program

    try


    unload me




    HTH

    cksiow
    http://vblib.virtualave.net - share our code


  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: About quit the program

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    Jun 2001
    Posts
    69

    Re: About quit the program

    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.

  5. #5
    Join Date
    Jun 2001
    Posts
    69

    Re: About quit the program

    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.

  6. #6
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: About quit the program

    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.


  7. #7
    Join Date
    Jun 2001
    Posts
    69

    How to make it then?

    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.

  8. #8
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: How to make it then?

    Right click on the form and select the context menu Remove Form1

    Then select the menu Project-&gt;Add Module and put the Sub Main() in that.

    Finally, select the menu Project-&gt;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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  9. #9
    Join Date
    Jun 2001
    Posts
    69

    It still in 'Process'

    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.

  10. #10
    Join Date
    Apr 2000
    Posts
    737

    Re: About quit the program

    okay, try this two API

    GetCurrentProcess
    TerminateProcess

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes


  11. #11
    Join Date
    May 2001
    Posts
    6

    Re: About quit the program

    Try this:

    Unload me
    Set frmName = nothing

    ASLU


  12. #12
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: About quit the program

    '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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  13. #13
    Join Date
    Jun 2001
    Posts
    69

    Here is my code:

    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

    ' Get database fields to message queue structure
    S01 = IIf(IsNull(Rs!comp_code), "", Rs!comp_code)
    S02 = IIf(IsNull(Rs!company_name_1), "", Rs!company_name_1)
    S03 = IIf(IsNull(Rs!company_name_2), "", Rs!company_name_2)
    S04 = IIf(IsNull(Rs!comp_phone), "", Rs!comp_phone)
    S05 = IIf(IsNull(Rs!head_code), "", Rs!head_code)
    S06 = IIf(IsNull(Rs!nh_comp_status), "", Rs!nh_comp_status)
    S07 = IIf(IsNull(Rs!nh_mkt_segment), "", Rs!nh_mkt_segment)
    S08 = IIf(IsNull(Rs!nh_customer_numb), "", Rs!nh_customer_numb)
    S09 = IIf(IsNull(Rs!nh_sales_terr), "", Rs!nh_sales_terr)
    ' S10 = IIf(IsNull(Rs!nh_customer_since), "", Rs!nh_customer_since)
    S10 = "2000-01-01"
    S11 = IIf(IsNull(Rs!nh_cust_class), "", Rs!nh_cust_class)
    S12 = IIf(IsNull(Rs!nh_price_class), "", Rs!nh_price_class)
    S13 = IIf(IsNull(Rs!nh_master_terms), "", Rs!nh_master_terms)
    S14 = IIf(IsNull(Rs!nh_tax_code), "", Rs!nh_tax_code)
    S15 = "000"
    S16 = IIf(IsNull(Rs!nh_resale_numb), "", Rs!nh_resale_numb)
    S17 = IIf(IsNull(Rs!nh_national_acct), "", Rs!nh_national_acct)
    S18 = IIf(IsNull(Rs!nh_leasing_co), "", Rs!nh_leasing_co)
    S19 = IIf(IsNull(Rs!nh_allow_multi_ship), "", Rs!nh_allow_multi_ship)
    S20 = IIf(IsNull(Rs!nh_billing_addr1), "", Rs!nh_billing_addr1)
    S21 = IIf(IsNull(Rs!nh_billing_addr2), "", Rs!nh_billing_addr2)
    S22 = IIf(IsNull(Rs!nh_billing_city), "", Rs!nh_billing_city)
    S23 = IIf(IsNull(Rs!nh_billing_state), "", Rs!nh_billing_state)
    S24 = IIf(IsNull(Rs!nh_billing_zip), "", Rs!nh_billing_zip)
    S25 = IIf(IsNull(Rs!nh_cert_filed), "", Rs!nh_cert_filed)
    S26 = IIf(IsNull(Rs!nh_credit_fname), "", Rs!nh_credit_fname)
    S27 = IIf(IsNull(Rs!nh_credit_lname), "", Rs!nh_credit_lname)
    S28 = IIf(IsNull(Rs!nh_credit_salutation), "", Rs!nh_credit_salutation)

    End If

    '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

    'get database fields to message queue structure
    S29 = "0"
    S30 = IIf(IsNull(Rs!comp_code), "", Rs!comp_code)
    S31 = IIf(IsNull(Rs!address1), "", Rs!address1)
    S32 = IIf(IsNull(Rs!address2), "", Rs!address2)
    S33 = IIf(IsNull(Rs!city), "", Rs!city)
    S34 = IIf(IsNull(Rs!State), "", Rs!State)
    S35 = IIf(IsNull(Rs!zip), "", Rs!zip)
    S36 = IIf(IsNull(Rs!country), "", Rs!country)
    S37 = IIf(IsNull(Rs!dest_flag), "", Rs!dest_flag)
    S38 = IIf(IsNull(Rs!nh_ship_instr), "", Rs!nh_ship_instr)
    End If

    'close database connection
    Rs.Close
    Qd.Close
    Db.Close
    Ws.Close
    Set Rs = Nothing
    Set Qd = Nothing
    Set Db = Nothing
    Set Ws = Nothing

    'make message string buffer
    Ms = S01 & S02 & S03 & S04 & S05 & S06 & S07 & S08 & S09 & S10 & S11 & S12 & S13
    Ms = Ms & S14 & S15 & S16 & S17 & S18 & S19 & S20 & S21 & S22 & S23 & S24 & S25
    Ms = Ms & S26 & S27 & S28 & S29 & S30 & S31 & S32 & S33 & S34 & S35 & S36 & S37
    Ms = Ms & S38 & " " & "END"

    Ml = Len(Ms)
    MsgBox Str(Ml)
    MsgBox Ms

    'set DataQueue API to translate mode for ASCII to EBCDIC
    setMode_result = EHNDQ_SetMode(EHN_hwnd, EHN_Location, EHN_Xlate)
    If setMode_result &lt;&gt; 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 &lt;&gt; 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

    filename = CurDir$ & "\" & "PAL_DQ.ini"
    fnum = FreeFile()

    Open filename For Input As #fnum

    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.

  14. #14
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Here is my code:

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  15. #15
    Join Date
    Jun 2001
    Posts
    69

    That's some 3rd party APIs

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured