Ravencraft

I'm trying to get splashscreen2 to be displayed for a length of time (5 seconds) then to display form6.

I've figured out to display form6 with:

Dim e as New Form6

e.Show()

But I can't get it to work, as I am having some problems getting the timer to inilize and, well, everything in general. Tried the help files, But can't quite figure it out...




Re: Visual Basic Express Edition Troubles with timer

Seith

I could do with a little more information about when the timer will be started, but assuming it starts at run time (thus making your splashscreen2 the first form that's shown) this would be the rough code:

For Timer on the Splash Screen

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Hide()
Form2.Show()

timer1.Enabled = false

End Sub


Use these settings for the timer and put it on the splash screen:
http://i4.tinypic.com/62p71h0.png


What is this doing
When your splash screen loads, the timer will count up to 5000 (5 seconds) then hide itself and show form2 (for you will be form6)


It also disables the timer so that it doesn't keep doing it every 5 seconds, as your splash screen will still be there, just hidden.





Re: Visual Basic Express Edition Troubles with timer

cobradeth1

why not do a syste.threading.thread.sleep(5000)

i made a screen capture program that hides the program, waits, print screens, waits, then brings the screen back. Works great just put it in your load.





Re: Visual Basic Express Edition Troubles with timer

SJWhiteley

Don't abuse your main GUI thread by using sleep like that.

What you want to do is to enable the splash screen in your application and set the minimum delay time. To quote from another thread:

Cathal Connolly wrote:
If you want to change the default splash screen display time, then in the project property's Application page, click on "View Application Events". This will create a new file ApplicationEvents.vb. Open the Partial Friend Class MyApplication in that file, add this code:

Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean

'Set the splash screen timeout.

Me.MinimumSplashScreenDisplayTime = 5000
Return MyBase
.OnInitialize(commandLineArgs)

End Function

Cathal

(why does everyone want to display their splash screen for 5 seconds Strange, I say...).






Re: Visual Basic Express Edition Troubles with timer

JohnWein

SJWhiteley: Why not use the Startup event It seems equivalent and it saves typing.

Code Snippet

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

MinimumSplashScreenDisplayTime = 5001

End Sub





Re: Visual Basic Express Edition Troubles with timer

SJWhiteley

JohnWein wrote:

SJWhiteley: Why not use the Startup event It seems equivalent and it saves typing.

Code Snippet

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

MinimumSplashScreenDisplayTime = 5001

End Sub

That would be great, except that it doesn't work Smile

(and don't think you can squeak by with having a non-5 second splash screen by adding 1 millisecond Wink)

Actually, all you need to do is type in overrides wihin the MyApplication class. Intellisense will drop down your options, one of which is OnInitialize. Select it and press Tab - all the rubbish needed gets filled in for you, and all you need to type is the MinimumSplash...etc. (or even just type me. and select the item you need).

(Edit: personally, I create my own splash screen on a separate thread - since some of the form events in the splash screen don't appear to fire when expected).






Re: Visual Basic Express Edition Troubles with timer

JohnWein

I don't understand. It works fine on my computer. I always (almost) check my code before posting.



Re: Visual Basic Express Edition Troubles with timer

js06

Ravencraft,

This is what i did and it has worked well for me.

Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Me.Timer1.Start()

Me.Timer1.Interval = 2000

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Me.Timer1.Stop()

Form6.Show()

Me.Close()

End Sub

Add a timer to the splash screen

Set the interval time to whatever you need which i guess would be 5000 (this way you may only need 2000) try it

set the startup form to -- splash screen

set the splash screen to -- (none)

set shutdown mode to -- when last form closes

For some reason i had trouble with the splash screen displaying how i wanted it to when it was set as the splash screen in the application properties.

I used this on 4 different apps and it works like a charm






Re: Visual Basic Express Edition Troubles with timer

spotty

To add a splash screen to you application

1. Add a splash screen form to the project

2. In My Project, On Application tab

  • Ensure Enable Application Framework is checked
  • set the startup form to whatever you main form is
  • set the splash screen to your splashscreen form

3. Click View application events and a code window will appear

4. Within the Partial Friend Class MyApplication, paste the following code.


Code Snippet
Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
'Set the splash screen timeout.
Me.MinimumSplashScreenDisplayTime = 5000
Return MyBase.OnInitialize(commandLineArgs)
End Function

Adjust the MinimumSplashScreenDisplayTime property here to however many milliseconds you want the splashscreen to stay up (5000 = 5 seconds)


5. Run the application.

Its really rather simple, in the paste you had to set up timers, ensure form was top most and there were many different alternative to doing this. With 2005 adding a splash screen is as simple as adding the form, setting a couple of project properties, and in your case adding a couple of lines of code to adjust the delay time from its default of 3 seconds.






Re: Visual Basic Express Edition Troubles with timer

Ravencraft

Thanks for the help with that. I have another question about timers. Lets say that I want to create a simple application that counts down from 5 to 1 before displaying a msgbox of some sorts. For sake's end, I have a label (called label 1). With this label, I would like to display a countdown (from 5 to 1).

While I'm not making this project, I figure this would be great for someone to show me how to do this, so I can get an understanding of how to do something simular (my game will have many time dependant things such as quests and the like). That would be a major help and point me in the right direction.






Re: Visual Basic Express Edition Troubles with timer

JohnWein

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) _

Handles Button1.Click, Button2.Click

Timer1.Interval = 1000

Label1.Text = "5"

Timer1.Tag = Label1.Text

Timer1.Start()

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

Dim Cnt As Integer

Cnt = CInt(Timer1.Tag) - 1

If Cnt = 0 Then

Timer1.Stop()

Return

End If

Timer1.Tag = Cnt

Label1.Text = Cnt.ToString

End Sub





Re: Visual Basic Express Edition Troubles with timer

SJWhiteley

Good grief, does no-one have any idea what a splash screen is for

Okay, the whole point of a splash screen is not to say 'look how great I am', but means 'hold on, this is going to take some time, so here's a pretty picture to look at'.

If you load your splash screen first, then load your form, you do absolutely nothing except delay the start of your application. This is poor design.

Spotty has summarized what should be done, below.






Re: Visual Basic Express Edition Troubles with timer

js06

Spotty,

Now that i see your explanation, if i would have known that in the beginning i may have gone with that.

I was just wondering, are there any reasons other than having to change settings that this is a better way

The reason I decided to do what i did was that when i would display my splash screen and my parent form was loading, it didn't want to display right all the time. I wasn't hung up on wanting to show off my fancy splash, i just wanted important info to be read like my copyright and since i have 3 different versions of the same app, i wanted them to see that they were indeed opening the corrrect one.

Sometimes I feel like the more experienced programmers are bothered that those of us that are new think outside of the standard. Many of us don't know what the standard is and I can't speak for others but I like to create something a little bit different sometimes.

It reminds me of when I was in the basic training and we had to be re-molded into something we were not.

Either way, I appreciate all that your knowledge brings to us stubborn learners.






Re: Visual Basic Express Edition Troubles with timer

spotty

Adding a splash screen is common action, therefore MS added it to make it easy to add a splash screen to a project, also in prior version people had all sorts of weird logic to handle displaying stuff, so they added this option by default that enables an application framework for adding splashscreens by simply setting a few properties in the project properties and identifying the form.

So they made things simple for what the vast majority of people would be happy with, however when people want to start changing things they have to understand a bit more about the underlying code. The same is true for many other features (data being a great example where the wizards generate underlying VB code and to start changing stuff outside of what is possible in the wizards you need to understand what it has generated).

Experienced developers generally have spent a lot of time learning the language, using it and understand limitations and finding solutions to there problems. The splash screen problem is a classic example where a simple search of the forums would reveal numerous answer to the problem. Is it a commonly asked question, Yes. Could it be done better, Probably.

I think you will find that VB has a tough act, it caters to a huge range of developers from complete novice to experienced developers. The way to become more productive is to use the product and attempt to become more self sufficient, when you run into problems attempt to search for an answer first and then ask in the forums. This way you wont become completely reliant on others to give you answers and also in the process of searching you often find other gems of information which may not help you this time but knowing about them may help you later.

As we are talking about a language here, it enables you to create something different. There are always numerous ways to achieve the same result. The only thing I can say about doing things differently is that it can sometimes cause you to create more work for yourself than needed, result in code which runs most of the time ut not all the time and may become a bit of a maintanence nightmare when you have to come back and do ssome changes 2 years after you wrote it. Things to consider when doing things differently.





Re: Visual Basic Express Edition Troubles with timer

SJWhiteley

Spotty is a bit more diplomatic than I am, but I'll point out that (spash screen usage) isn't a standard, and yes you can program your application any way you like. However, programmers tend to be blind to the needs of the person who will be using the program, particularly newer programmers - although more experienced programmers to be refocused more often than they should.

Programmers have a strange habit of separating their own user experience from the programming experience. Consider this; are you happy to sit in front of your computer or 5 seconds, staring at a blob, before the program you clicked on will start to load For example, notepad If it's not OK for you, then it definately isn't OK for your users (even if that user is you). Here's another question - when you run/debug the program, do you sit there for 5 seconds waiting for the splash screen to go away

This is really a design issue rather than a programming issue; but you can't separate the two. Yes, there are standard ways of doing things, but you have to think more about objectives than 'following the standard'. I've used applications which use the 'standard' and just absolute dross (too many to name), but other applications where a standard 'windows gray' doesn't exist, and are a joy to use (few and far between, but they exist - video editing software, music applications). Thinking outside the box is finding better ways to achieve the objective.

But you still have to know the rules before you can break the rules...