Display a form only after installation in VB - vb.net

I am developing a Windows form application in VB
I want to display a form only at the first application start up i.e. opening the form for the first time after installation , then it should not display the form . How to do it?

The way this is normally done is by
1) setting a registry key FirstRun (you create this) to a value of False
When you run your app for the first time you check the key if it exists (It won't at this stage) then run the installation form which will set the key. So next time the program runs it checks the key and sees that it has been set and knows not to run the form.
2) This is the way I do it. Check if a folder or file belonging to the app exists if not run installation form and create the file, folder that you will check for. If it does exist then you know not to run the form.
If (!File.Exists("yourFile"))
InstallForm.Show();

Related

How to save an application setting item

Good morning, excuse me
I also looked into similar questions but I can not solve the problem anyway.
On a form, on the add Connect window of window, the system and app administrator has the option to
select the SQL Server available on the system and configure the correct connection string. Once set and validated, it is saved in its app settings set item with the following snippet:
If ValidateStringConnection() Then
My.Settings.MMABooksConnectionString = stNewStringConnection
My.Settings.Save()
txtCurrentConnection.Text = My.Settings.MMABooksConnectionString
End If
However, the save occurs only at the memory level of the running App, so in a subsequent restart it resumes the value set at the project level and stored in the file:
CustomerMaintenanceDB.exe.config
I also use the following snippet:
My.MySettings.Default("MMABooksConnectionString") = stNewStringConnection
My.MySettings.Default.Save()
but nothing is saved in the above file.
Now I ask there is a way for the value of the item to be saved in the above file, so that when the App is subsequently rerun you find the correct connection value without having to intervene again the System Administrator?
Thank you for any helpful advice
Right click on the name of your program in Solution Explorer and select Properties. Click the Settings tab.
Enter MMABooksConnectionString as the Name, select (Connection string) in the Type dropdown and Scope as Appliction. You can scope to application since I don't think this will be changing.

When I am creating record and saving manually record number is generated but record number is not generated using selinium automation

The task is that when I create a record and click save then verify using automation that a record number is generated automatically.
However when I am executing this task manually and saving it record number is generated but when I am creating the same record with same fields using automation then record number is not generated.
Ways I tried:
I have tried pausing selenium after clicking save button but I am not able to figure out the reason.
I have checked that user is the same manually and through automation.
What else I could be the reason
i believe you have to replicate user action while saving the record instead of performing an action on DOM. you can give a try using any of the below options
1) Actions Class
2)Robot Class
3)Sikuli

How to code a self incrementing loop that carries on from the last value stored when the program is run again vb.net?

I am trying to create a self incrementing loop to act as a key field for my project, I have coded a counter, but every time I run the program again, it starts from 1 again, what do I do to ensure that it carries on from the last number written to file? I am a beginner to vb.net. Thank you :)
To achieve this, you can store whatever data you want to store as an application setting.
In visual studio, if you want to add a setting, go to the settings pane of the solution explorer.
Dont forget to call the save function when you are done with updating the value as the values wont get updated unless we call this function.
For more information you can refer to this URL
http://msdn.microsoft.com/en-us/library/bc6ws923.aspx
Alternatively, when the application is exited, you can save the required value to a file and when the program is opened again, you read the file and update the variable to the value stored in the file.

Persist user settings

I need to save the user's data for the first time he opens the app and never show it again.
Let's say I need the user to enter his first name and other data, and save it so the application can use it later. The user enters his first name, and the next time he opens the application, he doesn't get asked to enter his name again. The application just goes to the main screen.
How can I do this?
You can use application settings. Open your project's properties (My Project in the Solution Explorer), go to the Settings tab, and make a setting. I'll assume you called it FirstName. Keep everything else as-is (User Setting, String) and save.
Now you can use this setting just like any other property, except it'll persist between runs. You can find the property in the My.Settings class. To set it the first time:
My.Settings.FirstName = userFirstName
And to use it later, it's just My.Settings.FirstName.

Running VBA before any forms open

So I have an Access database with a front and a back end. I will be distributing it to users soon, but I have no control over where exactly they will put the files on their computers. However, I think I can count on them putting front and back ends in the same folder.
As such, when the front end opens, I want it to check that the linked tables are correctly connected to the back-end database. I have working code for this; however I don't know where to put it. When the front end opens, a menu form is automatically opened (configured through the start-up dialogue box). I have put the code in the OnOpen event, which I thought occurred before any data is loaded, but when I test this out, I get a message telling me that the back-end cannot be found (it's looking in its old location).
Basically, is there an event I can use that runs before any forms have opened?
Create a Macro and name it "autoexec".
For the macro action, select "RunCode" and then set the function name to the name of the function you use to check your linked tables.
As Matt said, create a macro, call it "autoexec", and select "RunCode" as the macro action. The Function Name argument should be the name of the function you wish to run (and not a sub), and if the function has no arguments, you should still put () at the end, or it won't work.
I generally prefer to create a small form that runs a number of checks, such as finding the back-end and so forth, and set various options. The code for the open event of this form might be:
Me.Visible = False
'Determines if the database window is displayed
SetProp "StartupShowDBWindow", False, dbBoolean
'Hide hidden and system objects
SetOption "Show Hidden Objects", False
SetOption "Show System Objects", False
'Find back end
CheckLinkPath
I keep a table of tables to be linked in the front-end and if any are missing, this form can be used to report the error, or any other error for that matter.
Set RS = CurrentDb.OpenRecordset("Select TableName From sysTables " _
& "WHERE TableType = 'LINK'")
RS.MoveFirst
strConnect = db.TableDefs(RS!TableName).Connect
If Not FileExists(Mid(strConnect, InStr(strConnect, "DATABASE=") + 9)) Then
'All is not well
blnConnectError = True
Else
Do Until RS.EOF()
If db.TableDefs(RS!TableName).Connect <> strConnect Then
blnConnectError = True
Exit Do
End If
RS.MoveNext
Loop
End If
If everything is ok, the small form calls the main menu or form and the user never sees the checking form. I would also use this form to open a password prompt, if required.
Before putting your front end and back end in the same folder, think about it. Isn't it worth having 2 folders? What about multiple users on the same computer accessing the same back-end database? What about multiple users accessing the same databse through a network? What is the necessity of having a front end-back end typology if your app is basically a single-user app?
Why don't you add a dialog box to your app, in case your connectivity is lost? You could create a fileDialog object in your code, allowing the user to browse for a *mdb file anywhere on his computer/network. It is then possible to control that the selected mdb file contains all requested tables and open the corresponding links (I guess you are using the transferDatabase command).
And what about additional tools/references you'll need for your app to run when you'll distribute it to your final users? By default, MS Access records the 3 basic ones:
Visual Basic For Application
Microsoft Access Library
Microsoft DAO Library
If your app needs anything else, such as ADO or Office objects (ADODB.recordset or Office commandbars for example), you will have to add the references manually for each installation, as the final user won't be able to open the VBA window and access the tools/references menu.
So, if you need to deploy your app on multiple computers, I strongly advise you to use a deployment tool such as this free one. You'll need a few hours to be able to use it properly, but the result is worth it. You'll be able to give your clients a real installer module. It will create folders, add requested shortcuts, and manage references in the computer's registry. This will make your deployment definitely painless!
EDIT: the autoexec macro is definitely the right solution for calling code before any event.
EDIT: don't forget that your final users can make profit of the runtime version of Access, which is free!
As others have suggested, I'd use the AutoExec macro in this case. If your code that checks the linked tables is currently a sub, change it to a function that returns TRUE if it succeeds. You can then use the "conditions" column in the AutoExec macro to exit the application with a user-friendly error dialog if the link table code fails. Your AutoExec macro could be something like:
Call your LinkTables() function, set condition to terminate startup if it fails.
Call your "Main" startup menu form.
You could send them a *.BAT file that copies the databases to c:\temp (or whatever folder you choose. Setup the linked to this folder before creating the BAT file. Zip it up and email it to them. then you won't have to worry with the extra needed code.