Results 1 to 5 of 5

Thread: Prevent Form from loading [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Question Prevent Form from loading [Resolved]

    I have a proplexing problem.....

    [code]

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim Check As Integer, filepath As String
    filepath = "C:\Help.txt"
    Check = Len(Dir$(filepath))
    If Check = 0 Then
    Dim Frm As New Form2()
    Frm.ShowDialog()
    End If

    End Sub

    This code does it's job of throwing the From2 up if the file don't exist but on Form2 using a button is it possible to stop Form1 from loading?

    I can get the Form2 to close with Me.Close() but it still loads Form1 after Form2 closes.
    Last edited by teamdad; Jul 2nd, 2004 at 10:39 PM.

  2. #2
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    You can do two things here:


    1. Do your file check from a module and set that as the startup form, that way no form will be visible until after the check has ben done.

    2.Use Me.ActiveForm.Hide in the "Form1.Load" event, and then show it or keep it hiden after the file check.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    It doesn't like Me.ActiveForm.Hide() for some reason. Durring debug it gives.

    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication15.exe

    Additional information: Object reference not set to an instance of an object.

    If I use Me.Hide() it don't give errors but it don't hide it either.

  4. #4
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Sorry,

    The first one you can't put in the load event, put it in the paint event.

    Or Try the second one:


    In a module:

    Code:
    Public Sub Main()
    'Do you file check here
    'Then show whatever form you'd like
    End Sub
    Also make sure to set the startup object to "Sub Main()"

    This works for sure


    Let me know if you have any probs.
    Last edited by Hole-In-One; Jul 2nd, 2004 at 10:05 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Thanks Hole-In-One,

    I was trying to avoid using a module for some reason but I guess they can be a good friend every now and then

    When I tried the paint method to use the Me.ActiveForm.Hide() it gave the form about a second's worth of flash so I opted to go with the module.

    You guys rule

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