Results 1 to 8 of 8

Thread: If my file isn't there load other form???

  1. #1

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Arrow If my file isn't there load other form???

    Sorry, couln't come up with a better title...........
    I need a code that when your form loads if a file isn't in a location(its a dll)
    It goes to another form.(dllnot.frm)
    Is there a way of doing this?????

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: If my file isn't there load other form???

    Do you mean something like this...
    VB Code:
    1. If Len(Dir("path and name of your file")) = 0 Then    ' File is missing
    2.         ' load form1
    3.     Else
    4.         ' load form2
    5.     End If
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: If my file isn't there load other form???

    Hehe, just happened to code this the other day:

    VB Code:
    1. ' in a module
    2. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    3. Private Declare Function GetModuleHandle Lib "kernel32" (ByVal lpModuleName As String) As Long
    4. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    5. Private Declare Function LoadLibrary Lib "kernel32" (ByVal lpLibFileName As String) As Long
    6.  
    7. Public Function IsFunctionSupported(ByRef FunctionName As String, ByRef ModuleName As String) As Boolean
    8.     Dim lngModule As Long, blnUnload As Boolean
    9.     ' get handle to module
    10.     lngModule = GetModuleHandle(ModuleName)
    11.     ' if getting the handle failed...
    12.     If lngModule = 0 Then
    13.         ' try loading the module
    14.         lngModule = LoadLibrary(ModuleName)
    15.         ' we have to unload it too if that succeeded
    16.         blnUnload = (lngModule <> 0)
    17.     End If
    18.     ' now if we have a handle to module...
    19.     If lngModule <> 0 Then
    20.         ' see if the queried function is supported; return True if so, False if not
    21.         IsFunctionSupported = (GetProcAddress(lngModule, FunctionName) <> 0)
    22.         ' see if we have to unload the module
    23.         If blnUnload Then FreeLibrary lngModule
    24.     End If
    25. End Function

    Usage example: we try to see if DrawTextW is supported or not so we know if we need to fallback to ANSI.

    VB Code:
    1. If IsFunctionSupported("DrawTextW", "user32.dll") Then
    2.         ' use DrawTextW
    3.     Else
    4.         ' use DrawTextA
    5.     End If

    Note that you can declare the APIs like normally (in this case both DrawTextA and DrawTextW would be declared), this just lets you check if you can use a function so you don't need to make a complex error checking workaround. This also works for checking if a DLL is in place, of course.

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: If my file isn't there load other form???

    Hey Merri, that could be very useful code... well done
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: If my file isn't there load other form???

    merrit, your code is very useful but not what i'm after, I tried your pnish and it works great but I dont know how to apply it. When I used a form with border, when you pressed exit it went to form1 anyways and when I make it with no border it doesn't show up in the task bar?????????

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: If my file isn't there load other form???

    Quote Originally Posted by LawnNinja
    merrit, your code is very useful but not what i'm after, I tried your pnish and it works great but I dont know how to apply it. When I used a form with border, when you pressed exit it went to form1 anyways and when I make it with no border it doesn't show up in the task bar?????????
    Put it in the sub main, before loading any other module.

  7. #7

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: If my file isn't there load other form???

    Ok,sorry figured it out....
    was me

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: If my file isn't there load other form???

    Why I suggested my longer code is that it also allows you to check that the DLL file is a real loadable DLL file, not an empty, incorrect or corrupted file (it may feel like an overkill, but often too much error prevention is far better than not enough of it).

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