Need help on Initial Startup Form

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
I just have a quick question.... I have created a database application in visual studio 2008 pro. I am making this for a friend of mine and he asked if I could have a form or 2 to appear only at the initial start up of the application, but not to show again when the user opens it again from there on out. He has a small business and this is going to be a promotional software and would like to say a few words to the user at first, but dosn't think it's necassary after the first time.

Is this possible and if so how?

Does anyone know of any good sites (tutorials) about this subject?

Thanks to all in advanced

daveofgv
 
You could either use a counter or a boolean value that will change to either 1 or true on the first load event of the form. After that they shouldn't show up again.

GLobal

dim counter as integer = 0
dim first as boolean = false

form load
counter plus 1
or
boolean = true
 
Thank you for your reply coach. I will try to see if I can get it. How about a form that loads and a check box that the user can click saying "if you do not want to see this message again check here"?

Would I put the same code (that you supplied) in the check box?

daveofgv
 
Create a setting in project settings, User scope, Boolean type. This will persist and you can set this True/False or bind it to a checkbox checked property.
 
"This will persist and you can set this True/False or bind it to a checkbox checked property."



Would it be possible to elaborate a little more for me. Maybe in a 2nd grade level.....

I have went to project properties and changed the settings as you stated. How would I direct that specific setting to a form (checkbox on the form)?

My friend asked for a huge promo database app and I have completed it all except for little things like this. Compared to the whole solution this is minor things just to make it look nicer....lol

Thank you for your help
daveofgv
 
"Cannot bind to the property or column Setting on the DataSource.
Parameter name: dataMember"


I have tried and get the error message above

daveofgv
 
Ah,

For project Settings (Like the User Scoped Settings variable you are are using there) you don't bind as a "Data Bindings" you bind it under the control's "Application Settings". This tells the interface that the value is bound to a settings variable, where as DataBindings is all based upon the DataSource property.
 
Thanks Jaeden,

When I attempt to bind under the checkbox application settings (Property Binding) I get a list for Bind properties to application settings. (ie... forecolor, imageAlign, Margin etc....)

Am I in the right spot and if so which one do I bind?

I am now not getting the error message, however, when I click the checkbox it still comes up after I start the app again. Am I missing something?

daveofgv
 
Last edited:
Okay, i'll step it through for simplicity so we're on the same page:

Let us say, Form1 is the form you wish to display, but allow the user to select never to display it again.

So you go to Project/Settings (in the Solution Explorer) and Open them. Then add a User Scope Setting: DoNotDisplayForm1Again (Boolean) default value False.

Let us Say Form2 is the form that displays Form1 (Form1.Show()).

Form1 - Design View, Select CheckBox1 (the Do Not Show Again CheckBox), expand the ApplicationSettings TreeNode in the properties, and you should see the Property "Checked". Click the Drop down and you should be able to see all the "Boolean" Application Settings Properties defined for your Project. Select DoNotDisplayForm1Again .

Go Back to Form2 and I will assume this form happens to display Form1 as a warning or splash of some sort, so we will show Form1 through a Private method not directly in your code.

VB.NET:
private Sub ShowSplashForm()
   if Not My.Settings.DoNotDisplayForm1Again then
      Form1.Show
   end if
end sub

Now, In the Solution Explorer, under your project, the first entry should be "My Project", Open that, and go to the Application Tab. Under the Windows application framework properties group, there is a setting:
Save My.Settings on Shutdown
Check that.

Now every time you would want to display the splash form from Form2 (for whatever reason) you would simply call ShowSplashForm(), which checks to see if the user wants to see that form again.

Cheers
 
JaedenRuiner -

thank you for the indepth detail, however, when form1 opens up with the checkbox the button to go back to form2 does not work anymore. Without the checkbox on the form it does work. Also, the checkbox is checked and it still goes to form1.

I decided to take a small break to get my sanity back and go relax, but my two kids started screaming so my relax time away from the computer was even more fruterated....lol

The reason why I am needing this is when a user clicks the close button (end) a small msgbox will appear asking if they remembered to save all. I would like to give the option for the user to stop displaying that message if they would like to.

Does this help at all?

daveofgv
 
thank you for the indepth detail, however, when form1 opens up with the checkbox the button to go back to form2 does not work anymore. Without the checkbox on the form it does work. Also, the checkbox is checked and it still goes to form1.
...
msgbox will appear asking if they remembered to save all. I would like to give the option for the user to stop displaying that message if they would like to.

Okay, so basically you are creating your own "MsgBox()" function because the default one doesn't have the "Do Not Show this Dialog Again"

So that is a form, with:
Label
Button
Button
CheckBox


That should be about it.

So, I would set it up like this:

CheckBox - We already handled in the last post
Button1
  • Text = &Yes
  • DialogResult = Yes
Button2
  • Text = &No
  • DialogResult = No
Label
  • Text = "Did you remember to Save All?"
Form
  • AcceptButton = Button1
  • CancelButton = Button2

then my previous suggested code with some changes:
VB.NET:
private Sub Form2_FormClosing(sender as object, _
                                    e as System.Windows.Forms.FormClosingEventArgs) _
                                    Handles Me.FormClosing
   e.cancel = ShowSplashForm()
end sub

private Function ShowSplashForm() as Boolean
   if My.Settings.DoNotDisplayForm1Again then Return false
   return (Form1.Show[i]Dialog(Me)[/i] = DialogResult.No)
end sub

That should basically handle the basics of what you want. Granted, I used the FormClosing method to prevent the closing of the Main Form (Form2) and though I'm not necessarily sure this is the effect you wanted the boolean usage of the ShowSplashForm() is sound.
 
Ok.....

I have built a nice 8 table database program for a friend that became a client. I am using Access since he does not want SQL. I suppose he knows Access and would like to open the .mdb file to get some info from it and dosn't know SQL.

I have many forms and my design is pretty good. Everything works fine and I have no problems with connections and no deployment issues. I think if I can't get this right again I am going to stop the way I live and go work at Taco Bell....lol

This is really kicking me in the back end and I feel as dumb as can be.....

VB.NET:
 Private Sub Form2_FormClosing(ByVal sender As Object, _
                                    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                                    Handles Me.FormClosing
        e.cancel = ShowSplashForm()
    End Sub

    Private Function ShowSplashForm() As Boolean
        If My.Settings.donotshowagain Then Return False
        Return (Form1.ShowDialog(Me) = DialogResult.No)
    End Function


If both of my forms are called:
Main.vb - current form that opens my message box
NeedInternet.vb - form that opens with "Do not show again checkbox"
donotshowagain - My.Settings.donotshowagain

Would I change the code that you supplied (which I am so greatful for) to show form1 to Main and form2 as NeedInternet??????

VB.NET:
Public Class NeedInternet
    Private Sub Main_FormClosing(ByVal sender As Object, _
                                    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                                    Handles Me.FormClosing
        e.Cancel = ShowSplashForm()
    End Sub

    Private Function ShowSplashForm() As Boolean
        If My.Settings.donotshowagain Then Return False
        Return (Me.ShowDialog(Me) = DialogResult.No)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ActiveAlerts.Show()
        Me.Close()
    End Sub

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

    End Sub
End Class

And I am placing the snippet at the top in the Class section correct????

Also, I do put it on NeedInternet form (messagebox) correct?
daveofgv
 
Last edited:
VB.NET:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If My.Settings.donotshowagainlaw = False Then
            NeedInternetLaw.Show()
        Else
            If My.Settings.donotshowagainlaw = True Then
                Law.Show()
            End If
        End If
    End Sub

It appears that this works well.....

I tried to do an If....Else statement
 
Well,

First:
daveofgv said:
VB.NET:
public Class NeedInternet
    Private Sub Main_FormClosing(ByVal sender As Object, _
                                    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                                    Handles Me.FormClosing
        e.Cancel = ShowSplashForm()
    End Sub
And I am placing the snippet at the top in the Class section correct????
The Main_FormClosing Event should be in the Main.vb file attached to the Main Class. and teh NeedInternet_Load should be in the NeedInternet.vb in the NeedInternet Class, and second the snippet doesn't care "where" it is placed, at least within the Class. yes the code I offered is a Class Method for the Forms you were working with.

Secondly:
daveofgv said:
VB.NET:
 If My.Settings.donotshowagainlaw = False Then
            NeedInternetLaw.Show()
        Else
            If My.Settings.donotshowagainlaw = True Then
This code here will definitely work, but some of that is thanks to VB. Now, this is most definitely a personal preference, but it flows into all aspects of programming in my mind, which is why I feel it necessary to comment.
The Boolean type (in most every language) is basically a Bit, but for binary alignment it is expanded into a byte, must often an unsigned 8 bit integer, though you will see here that VB does not follow that pattern. For VB they do something idiotic by making "True" equate to the numerical value -1, and False = 0. If you understand how bits/bytes work within a computer you can see the fallacy behind this.
Take a simple 16 bit Short (Short Integer, or Word) as aligned within a computer. An Unsigned Short is 0-65535, a Signed Short is -32768-32767. But the question of how it is written in bits is complicated (and I don't quite remember it all for it has been years). But 0 to 65535 is simple, because it is 00000000-00000001 = 1 but for the Signed Short:
11111111-11111111 = -1, and that's where the confusion can set in. Within the Boolean Logic as well as Bitwise logic of the computer it is helpful to recognize this when working with VB as opposed to other languages, however, it should be noted that all languages interpret 0 as false and (Not-0) as true, thus going back to Boolean Logic 101:
VB.NET:
If (Not False) = (True)
If (Not True) = (False)
thus, my personal preference is to always reference boolean's as a boolean and not as a "Equation", as some languages cannot compare False to False, and even further to remember that a database can never compare NULL to NULL,
VB.NET:
DB: If NULL = NULL  : is False  because Null(0) is False
SO I tend to recommend that boolean should be treated the same:
VB.NET:
If ([U]Not My.Settings.DoNotShowAgain[/U]) then

elseif [U]My.Settings.DoNotShowAgain[/U] then

end if
Which leads me to the depiction of the obvious. If the type is Boolean, it can only contain two values, True or False, thus the double statement is quite unnecessary. With Modern optimizers they may catch it, and eliminate the double statement, but I never trust a computer to do my job (*chuckle*).
looking at the statement above, that does two identical comparisons that the compiler may catch. However your statement:
VB.NET:
1: if Not X then
    else
2:     If X then
        end if
    end if
uses an "compound" statement within the "false" execution of the primary If block. when the "If Not X" is evaluated, if it fails, the "else" section is executed, and the first statement of that block is another "If X", but since you are using the same variable for both blocks you are in turn forcing the compiler to evaluate the same variable twice and the optimizer most likely won't catch it, so when the program runs it must execute two different comparison evaluations to achieve its end.
VB.NET:
If My.Settings.DoNotShowAgain then
  DoTrueCode()
else
  DoFalseCode()
end if
the Above achieves the exact same result as yours, but with only one Boolean evaluation. At the moment, this is not a vast importance or necessity within the grand scheme of your application, since with modern processors you'd never notice the difference. However, recognizing the good coding practice, you could extrapolate a 10,000,000 line program, with say 500,000 Boolean evaluations, if every Boolean Evaluation was done twice, that would be 1,000,000 calculations to resolve what only needed 500,000 and the slow down might then become apparent.

As much as I hated them, and personally find them useless, I'd recommend looking into some logic flow charts again, and researching some of the basics of programming. I personally find VB to not be the best teacher of programming, since it allows too many oversights on the part of the programmer, trying to fix what we are supposed to know and do by right.

All that being said, the final product of your design should work, given that the Main Form's Events are all handled in the Main.Vb file and the NeetInternet Form's Events are all handled in the NeetInternet.vb file.
Hope this helps.
 
Back
Top