Results 1 to 14 of 14

Thread: Making my program error proof.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Nottingham, England
    Posts
    197
    This is kind of a repeat of a previous question, but this is from a different angle. Sorry!

    I am writing a database application at the moment. I am really paraniod about error trapping (along with loads of other things!) and all that kind of stuff. My program has loads of error trapping code, but there's one eventually I can't account for. My program checks that the database (a Microsoft Access Database) exists when it loads up, and gives error messages if someone has deleted or moved it. However, what if the program loads, and then someone uses alt+tab or something to leave the program and delete/move the database. When they return, they may be able to avoid the error traps and cause the program to crash/mess up. How can I stop people from leaving my application unless they have used the exit button built into it? I figure I will need to disable alt+tab and de-active the start bar. I asked about hiding the start bar before, but the code didn't work!

    Any suggestions?

    (Maybe I don't need to do anything! If every form that uses the database has an On Error Goto DatabaseErrorHandler command in it's Form_Activate event, and the error handler is also in the activate event, would that not catch every thing? However, I would still like to hide the start bar, 'cos it obscures some of my larger forms slightly!)

    Thanks very much,

    Steve.

    P.S. - no comments about the correctness (or otherwise) of my handle this time please!
    Sent by: Steve Barker
    E-mail: [email protected]

    P.S. I KNOW 1 is not a prime!
    See this thread: http://forums.vb-world.net/showthread.php?threadid=26485

  2. #2
    Guest
    hide the "start bar"

    Code:
    Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Const SW_HIDE = 0
    Private Const SW_SHOW = 5
    Dim thwnd As Long
    
    Private Sub cmdHideT_Click()
        ShowWindow thwnd, SW_HIDE
    End Sub
    
    
    Private Sub cmdShowT_Click()
        ShowWindow thwnd, WS_SHOW
    End Sub
    
    Private Sub Form_Load()
        thwnd = FindWindow("Shell_TrayWnd", vbNullString)
    End Sub
    disable ctrl-alt-del and alt-tab

    Code:
    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
    
    Private Sub Form_Load()
        SystemParametersInfo 97, bDisabled, CStr(1), 0
    End Sub
    PS: the above code(systemparametersinfo) was from one of kedamans post's and I dont know if it works or not.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Nottingham, England
    Posts
    197

    Smile Thanks!

    Denniswrenn,

    Thanks very much for the help!
    The start bar thing works perfectly. The alt+tab thing needed an extra line:

    Private Const bDisabled = 1

    It works properly if you add this in.

    The program isn't quite water tight yet - users can still access the start button menu by pressing the windows key on the keyboard. Do you know how to disable this please? I imagine it is similar to the alt+tab thing, but I don't really understand the code and so could not adapt it! Can you also think of any other way the user could try to leave my program while it's still running?

    Thanks very much,

    Steve.
    Sent by: Steve Barker
    E-mail: [email protected]

    P.S. I KNOW 1 is not a prime!
    See this thread: http://forums.vb-world.net/showthread.php?threadid=26485

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    To make it water tight, you can make your program run fullscreen and set it always on top.

  5. #5
    Guest
    you could possible use the SetKeyBoardState API


    Code:
    Private Declare Function SetKeyboardState Lib "user32" Alias "SetKeyboardState" (lppbKeyState As Byte) As Long
    I recomend you get a "pro" to help you with that one, I had a little accident with it everywhere I clicked(in the VB IDE) if there was text it was highlited....
    and I am lucky I didnt do more....

  6. #6
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    Just checked... I made a connection (using ADO) to an Access database, and after I opened the connection I couldn't delete the database (running NT 4 server).
    So uhmm that should be enough....
    If you're afraid they delete a table while you're working, add error handler around the open function (you did put that at one place didn't you.... ;-), figure out the error number you'll get when you open a non-existing table and you're done.
    Hope this helps

    Crazy D

  7. #7
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    As for making your program error proof:
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idoits. So far, the Universe is winning."
    -Rich Cook
    "People who think they know everything are a great annoyance to those of us who do."

  8. #8
    Guest
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idoits. So far, the Universe is winning."
    -Rich Cook
    LOL its so true,
    people seem to get dumber every year!
    no offense to anybody on that comment, but its true.....
    as things get easier, people get dumber....

  9. #9
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    be glad ppl get dumber and dumber... that makes a huge part of my living (if the customers aren't that stupid, we don't have to write validation and error handling, and then the program would have been finished already, and I wouldn't have a job anymore....)
    Hope this helps

    Crazy D

  10. #10
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    I think you'll find your program won't be very popular if the user is forced to keep it focused - what happens if they want to write a Word doc while the program's running for example? Windows is a 'multi-tasking' operating system - that's the point. If you start writing full-screen unswitchable programs you're heading back to the 1960's -mainframe days. Why not go the whole hog and force the users to fill in the dialog boxes in the right order!

    I haven't tested it but surely it would be impossible to delete or move a database file while the program is accessing it - don't you get a 'file in use' error message?
    Even if you don't, why not write a little function that checks the existance of the database file before you access it - returning TRUE if it's OK or FALSE if it isn't?

    As for "I would still like to hide the start bar, 'cos it obscures some of my larger forms slightly!" - if your forms are that large what happens if someone has a lower res monitor? It wasn't long ago that most users only had 640x480 displays. Why not use the tabbed dialog control to split the information onto various tabs, therefore taking up a lot less space?

    Sorry about the moan - it's just that my predecessor at here seemed to have the same mindset. Each of her programs fills up the entire screen and gets grumpy with you if you try and have a life outside of the program. Her excuse was she was brought up with COBOL and mainframes - what's yours?

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Nottingham, England
    Posts
    197

    My excuse!

    Thanks for the suggestions, especially Buzby.

    I've learn't from bitter experience about form sizing and resolution.I did a thread when I started VB that might make you laugh! (S#*t - it was only 11 days ago - feels like forever!)

    http://forums.vb-world.net/showthrea...threadid=26098

    I now code in 800x600 - and include a routine that looks for resolution depth. The forms and controls are then rescaled for higher resolutions. It does spoil the pictures on my buttons though. They stay the same size (in terms of pixels). Is it possible to rescale these too? I don't cater for 640x480 displays. This approach seems to work well. I'll look into TABed forms though - thanks for the suggestion!

    I'll probably also go with your suggestion on checking for the database too, Buzby. Thanks!

    As for my excuse?
    1) I started on Spectrums(!?) (Who didn't?)
    2) I like to take away peoples ability to mess things up. I guess I'll be happy with letting them use the WINDOWS key! I think that with the application I'm doing, the user won't want to open anything else anyway.

    Thanks very much for the help,

    Steve.
    Sent by: Steve Barker
    E-mail: [email protected]

    P.S. I KNOW 1 is not a prime!
    See this thread: http://forums.vb-world.net/showthread.php?threadid=26485

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Nottingham, England
    Posts
    197

    Couple of other things:

    oetje: How do I make my program "run fullscreen and set it always on top."?

    Crazy D: Thanks for checking the connection thing. I haven't used an open function - I have just defined a database name and recordsource. The empty database is included in the package. (I think this may be a bad idea though - it's quite big!) It seems to work! Am I showing my naiveity here? I think I need to learn more advanced database stuff before my next project!

    Thanks,

    Steve.

    Sent by: Steve Barker
    E-mail: [email protected]

    P.S. I KNOW 1 is not a prime!
    See this thread: http://forums.vb-world.net/showthread.php?threadid=26485

  13. #13
    Guest
    This is the Always OnTop Code


    Code:
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Private Enum SWP
    NOSIZEMOVE = &H3
    TOPMOST = -1
    NOTOPMOST = -2
    End Enum
    
    Private Sub OnTop(frm As Form, blnOnTop As Boolean)
        Dim otPos As Long
        Select Case blnOnTop
            Case True
                otPos = SWP.TOPMOST
            Case False
                otPos = SWP.NOTOPMOST
        End Select
        Call SetWindowPos(frm.hwnd, otPos, 0, 0, 0, 0, SWP.NOSIZEMOVE)
    End Sub
    
    Private Sub Form_Load()
        OnTop Me, True
    End Sub

  14. #14
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Unhappy

    Locking the user to your program doesn't strike me as the
    best way to avoid errors either, you get some users saying
    things like "But how do I look at the clock on the task
    bar?" etc. Can't you create an error checking function and
    call it once before your DB select/update code each time?

    Code:
    Public Function CheckMDB() as Boolean
       ' check code
    End Function
    
    ' Then the program can be
    
    If CheckMDB = True then
    
        ' Normal DB access Code
    Else
        Call MsgBox("MORON", "Ya lost ya MDB file ya twit", VBCritical)
    End If
    OR, wrap your DB code in a class and when you pass the
    select statement or whatever have it call your private
    check function so that it's built in and you don't have
    to worry about it in your main prog code.

    Can't wait for the next version of VB's "Try, Catch, Final"
    system for error code!!
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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