Results 1 to 27 of 27

Thread: [RESOLVED] form load and unload with timer

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Resolved [RESOLVED] form load and unload with timer

    please need help .. I have form1 and form2 ..

    is there any way that as soon as form1 is launched form 2 will also be launched above the form1 and stay a while and unload itself..

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: form load and unload with timer

    How long do you want form2 to remain open for?

    Edit:

    You could try one of the methods here.
    Last edited by Nightwalker83; Apr 19th, 2012 at 06:27 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by Nightwalker83 View Post
    How long do you want form2 to remain open for?

    Edit:

    You could try one of the methods here.
    i want to put a progressbar like loading items on form2 .. when it reaches 100% then form2 should be closed.

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    try something like this
    Code:
    Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
    With ProgressBar1
        .Min = 0
        .Max = 10
        .Value = 0
        .Visible = True
    End With
    End Sub
    Private Sub Timer1_Timer()
        If ProgressBar1.Value < 10 Then
            ProgressBar1.Value = ProgressBar1.Value + 1
        Else
            ProgressBar1.Value = 0
            ProgressBar1.Visible = False
            Unload Me
            Timer1.Enabled = False
        End If
    End Sub
    Last edited by seenu_1st; Apr 19th, 2012 at 08:37 AM.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    thanks .. I actually solved my problem by this code
    Code:
    Option Explicit
    Dim cnt As Integer
    Private Sub Form_Load()
    Picture2.Height = Picture1.Height
    Picture2.BackColor = vbBlue
    Picture2.Width = 0
    tm.Enabled = True
    tm.Interval = 1
    End Sub
    
    Private Sub tm_Timer()
    Picture2.Refresh
    Picture1.Refresh
    cnt = cnt + 1
    Label1.Caption = (cnt) & "      %  "
    If cnt > 100 Then
    Picture2.Width = Picture1.Width
    cnt = 0
    Unload Me
    
    Picture2.Width = Picture1.Width
    tm.Enabled = False
    Unload Me
    Else
    Picture2.Width = (cnt / 100) * Picture1.Width
    End If
    End Sub
    In this code label1 is used to show the progress count .. how to add label2 which will run different item name .. like loading different items

  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    do u need to add a label at runtime? or u already had label2 in the form?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    do u need to add a label at runtime? or u already had label2 in the form?
    no there is no label2 on the form ... i want to show in label2 like product1, product2 and so on like progress count is changing 1-100

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    if i understand corectly may be this is u need
    Code:
    Private Sub tm_Timer()
    Picture2.Refresh
    Picture1.Refresh
    cnt = cnt + 1
    Label1.Caption = cnt & "      %  "
    Label2.Caption = "Product " & cnt
    If cnt > 100 Then
    Picture2.Width = Picture1.Width
    cnt = 0
    Unload Me
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    if i understand corectly may be this is u need
    Code:
    Private Sub tm_Timer()
    Picture2.Refresh
    Picture1.Refresh
    cnt = cnt + 1
    Label1.Caption = cnt & "      %  "
    Label2.Caption = "Product " & cnt
    If cnt > 100 Then
    Picture2.Width = Picture1.Width
    cnt = 0
    Unload Me
    thanks for your help .. brother I actually do not want to show count with product ,, like you have coded .. I want while running progressbar label2 should display product name one by one .. like bread, water, tea etc...

  10. #10
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    where from u wil get that product names?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    where from u wil get that product names?
    like you put this code of line

    Label2.Caption = "Product " & cnt

    if instead of product name of products will change one by one .. i actually want to show that these products are loading on form1

  12. #12
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    use Array() function to list products, try something like this
    Code:
    PrdAr = Array("Bread", "Cake", "Biscuit") 'add more
    Label2.Caption = PrdAr(cnt)
    remember array starting count is 0, means 0 = Bread, 1 = Cake ....
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: form load and unload with timer

    Don't forget to mark the thread "Resolved".
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    use Array() function to list products, try something like this
    Code:
    PrdAr = Array("Bread", "Cake", "Biscuit") 'add more
    Label2.Caption = PrdAr(cnt)
    remember array starting count is 0, means 0 = Bread, 1 = Cake ....
    thanks brother i did it this way

    Code:
    Dim PrdAr as *******
    PrdAr = Array("Bread", "Cake", "Biscuit") 'add more
    Label2.Caption = PrdAr(cnt)
    but I get compiler error: Expected array on Label2.Caption = PrdAr(cnt)

  15. #15
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    declare it as variant
    Code:
    Dim PrdAr As Variant
    or
    Code:
    Dim PrdAr
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    declare it as variant
    Code:
    Dim PrdAr As Variant
    or
    Code:
    Dim PrdAr
    Run-time error '9':
    Subscript out of range

  17. #17
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    ur cnt value getting more than ur array value, if u set 10 items in array it means 0-9 only, so ur cnt value shuld be with in that limit.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    ur cnt value getting more than ur array value, if u set 10 items in array it means 0-9 only, so ur cnt value shuld be with in that limit.
    can't it be done with another timer Timer2

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    ur cnt value getting more than ur array value, if u set 10 items in array it means 0-9 only, so ur cnt value shuld be with in that limit.
    can't it be done with another timer Timer2

  20. #20
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    post ur complete code, or if posible attach ur project as zip file.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    ok here is a sample .. I have placed Label2 on form which i intend to show products .. [Loading --- bread then water and so on ]
    Attached Files Attached Files

  22. #22
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    try like this
    Code:
    Option Explicit
    Dim cnt As Integer
    Dim PrdAr
    
    Private Sub Form_Load()
    PrdAr = Array("Product1", "Product2", "Product3", "Product4", "Product5", _
                    "Product6", "Product7", "Product8", "Product9", "Product10")
    Picture2.Height = Picture1.Height
    Picture2.BackColor = vbBlue
    Picture2.Width = 0
    tm.Enabled = True
    tm.Interval = 1
    End Sub
    
    Private Sub tm_Timer()
    Picture2.Refresh
    Picture1.Refresh
    cnt = cnt + 1
    
    Label1.Caption = cnt & "      %  "
    
    If cnt Mod 10 = 0 Then
        Label2.Caption = PrdAr(Int(cnt / 10) - 1)
    End If
    
    If cnt > 100 Then
        Picture2.Width = Picture1.Width
        cnt = 0
        Unload Me
    Else
        Picture2.Width = (cnt / 100) * Picture1.Width
    End If
    End Sub
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    try like this
    Code:
    Option Explicit
    Dim cnt As Integer
    Dim PrdAr
    
    Private Sub Form_Load()
    PrdAr = Array("Product1", "Product2", "Product3", "Product4", "Product5", _
                    "Product6", "Product7", "Product8", "Product9", "Product10")
    Picture2.Height = Picture1.Height
    Picture2.BackColor = vbBlue
    Picture2.Width = 0
    tm.Enabled = True
    tm.Interval = 1
    End Sub
    
    Private Sub tm_Timer()
    Picture2.Refresh
    Picture1.Refresh
    cnt = cnt + 1
    
    Label1.Caption = cnt & "      %  "
    
    If cnt Mod 10 = 0 Then
        Label2.Caption = PrdAr(Int(cnt / 10) - 1)
    End If
    
    If cnt > 100 Then
        Picture2.Width = Picture1.Width
        cnt = 0
        Unload Me
    Else
        Picture2.Width = (cnt / 100) * Picture1.Width
    End If
    End Sub
    Thanks brother for your help .. it worked fine .. to save the space of the forum by making another thread please help me bit more so that I will make thread resolve..

    I have another code where instead of message box I want to show form with label1 for programme used count

    code

    Code:
    Private Sub Form_Load()
    On Error Resume Next
    SaveSetting "hh", "StartupForm", "TimesRun", GetSetting("hh", "StartupForm", "TimesRun", 0) + 1
    Timesrun = GetSetting("hh", "StartupForm", "TimesRun")
    MsgBox "You have Used this programme " & Timesrun & " times"
    End Sub
    Last edited by janu; Apr 20th, 2012 at 02:15 AM.

  24. #24
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    it's better start a new thread, so many person wil help u, and i wil too
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  25. #25
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: form load and unload with timer

    Quote Originally Posted by janu View Post
    Thanks brother for your help .. it worked fine .. to save the space of the forum by making another thread please help me bit more so that I will make thread resolve..
    That does not save any space at all... what it does is save you a tiny amount of effort, while making things more confusing and annoying for all of the people who try to help (whether they have replied or not).

    If your original question has been answered, be polite and mark the thread as Resolved (which allows people who help to focus on the things that haven't been answered yet). You may also want to Rate the posts of the people who helped.

    If you have another question that is not a direct extension of the question at the top of the thread, create a new thread for it. There are several reasons why nearly everyone does that and you should too, including many that benefit you (such as more chance of other people reading your question, thus more chance of a good answer).

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: form load and unload with timer

    Quote Originally Posted by seenu_1st View Post
    it's better start a new thread, so many person wil help u, and i wil too
    actually I want to display more than 10 let it be 20 but this code does not allow

    Code:
    If cnt Mod 10 = 0 Then
        Label2.Caption = PrdAr(Int(cnt / 10) - 1)
    End If

  27. #27
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: form load and unload with timer

    change to
    Code:
    If cnt Mod 5 = 0 Then
        Label2.Caption = PrdAr(Int(cnt / 5) - 1)
    End If
    not tested, hope it's corect
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


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