CheckBox Saved with IsolatedStorage (vb) - silverlight

I have a problem loading the saved setting of a CheckBox (Checked True or False). On calling up the saved setting it always comes back as True from IsolatedStorage weather the CheckBox has been checked or not? Please see the code attached and I would appreciate it if someone could show me the error of my ways.
Kind regards
Will
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
'Rem Save Settings'
If CheckBox1.IsChecked = True Then
IsolatedStorageSettings.ApplicationSettings("MyCheckBox") = CheckBox1.IsChecked = True
ElseIf CheckBox1.IsChecked = False Then
IsolatedStorageSettings.ApplicationSettings("MyCheckBox") = CheckBox1.IsChecked = False
End If
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button3.Click
' Rem Call Up Saved Settings'
MessageBox.Show("Choose Tank Procedure First")
CheckBox1.IsChecked = (IsolatedStorageSettings.ApplicationSettings("MyCheckBox"))
End Sub

This Answer was kindly given to me by Karmjit Singh from the Microsoft Silverlight Forunm
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
If IsolatedStorageSettings.ApplicationSettings.Contains("MyCheckSettings") Then
IsolatedStorageSettings.ApplicationSettings("MyCheckSettings") = CheckBox1.IsChecked
Else
IsolatedStorageSettings.ApplicationSettings.Add("MyCheckSettings", CheckBox1.IsChecked)
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
Dim x As Boolean?
IsolatedStorageSettings.ApplicationSettings.TryGetValue(Of Boolean?)("MyCheckSettings", x)
CheckBox2.IsChecked = x
End Sub

Related

How to get the Subroutine Sender name

When I click the Button1 the MsgBox shows me "1" which is good.
Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
MsgBox(CType(sender, Button).Name.Replace("Button", ""))
End Sub
I want the MsgBox shows me "30" when I click the Button2.
Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) Handles Button2.Click
Hello30()
End Sub
Sub Hello30()
'The following line is need to be repaired.
MsgBox(CType(sender, ????).Name.Replace("Hello", ""))
End Sub
Not really sure what you're trying to do, but this is an example that'll get you close:
Imports System.Reflection
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Hello30()
End Sub
Sub Hello30()
Dim method As String = MethodBase.GetCurrentMethod.Name
MsgBox(method.Replace("Hello", ""))
End Sub

Visual Basic 2010: How can I put the two values in the same row in my database?

Visual Basic 2010: How can I put the two values in the same row in my database?
Button 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rst As ADODB.Recordset
rst = opentable("Select * from timesheet", ADODB.CursorLocationEnum.adUseServer)
With rst
.AddNew()
.Fields("time1").Value = Date.Now
.Update()
MsgBox("Time in")
End With
End Sub
Button 2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rst As ADODB.Recordset
rst = opentable("Select * from timesheet", ADODB.CursorLocationEnum.adUseServer)
With rst
.AddNew()
.Fields("time2").Value = Date.Now
.Update()
MsgBox("Time Out")
End With
End Sub

Issue with Array - NullReferenceException was unhandled - VB.NET

I am basically trying to create an array to export checked items onto a word document. But I am getting an error saying
"Object reference not set to an instance of object."
and
"Referenced 'SelectedMutualFunds' has a value of 'Nothing'
Below is my code:
Public Class ExportFunds
Public SelectedMutualFunds() As String
Private Sub ExportFundOkButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportFundOkButton.Click
Dim i As Integer
Dim array_Counter As Integer
array_Counter = 0
For i = 0 To ExportFundCheckedListBox.Items.Count() - 1
If ExportFundCheckedListBox.GetItemCheckState(i) = CheckState.Checked Then
SelectedMutualFunds(array_Counter) = ExportFundCheckedListBox.Items(i).ToString
array_Counter += 1
End If
Next
Me.Close()
End Sub
Can someone please help me solve this issue?
You need to provide length to your string array
Public SelectedMutualFunds() As String
to the following within ExportFundOkButton_Click before you use, preferably just before the for loop.
Redim SelectedMutualFunds(ExportFundCheckedListBox.Items.Count() - 1)
You can get this down to a one-liner and fix the NullReference exception at the same time:
Private Sub ExportFundOkButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportFundOkButton.Click
SelectedMutualFunds = ExportFundCheckedListBox.Items.Where(Function(i) i.CheckState = CheckState.Checked).Select(Function(i) i.ToString()).ToArray()
Me.Close()
End Sub
Or, slightly longer but easier to read:
Private Sub ExportFundOkButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportFundOkButton.Click
SelectedMutualFunds = ExportFundCheckedListBox.Items.
Where(Function(i) i.CheckState = CheckState.Checked).
Select(Function(i) i.ToString()).
ToArray()
Me.Close()
End Sub

Access level on VB.NET

I have created a system and im new to vb.net. It is working fine. The problem is, I need to restrict the main page from 1.) Users and 2.) Admin.
For example, After logging in, Admin will proceed to the main page
And if users logs in, they will be directed to a different page
I'm still new to vb.net (like 6 weeks ago) and i am using microsoft access as my database. A lot of code I find online is very complex and technical. I just need simple vb.net code
Any help will be appreciated, thank you!!
i have posted my code for my login form, so you guys can further understand my coding:
Public Class Form1
Dim loginerror As String
Public Function login()
Dim DBconn As New ADODB.Connection
Dim user As New ADODB.Recordset
Dim Username As String
Dim userDB As String
Dim passDB As String
Dim UserFound As Boolean
DBconn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = '" & Application.StartupPath & "\LoginDB.mdb'")
user.Open("UserTable", DBconn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
UserFound = False
login = False
Username = "Username = '" & txtuser.Text & "'" '
Do
user.Find(Username)
If user.BOF = False And user.EOF = False Then
userDB = user.Fields("Username").Value.ToString
passDB = user.Fields("Password").Value.ToString
If userDB <> txtuser.Text Then
user.MoveNext()
Else
UserFound = True
If passDB = txtpass.Text Then
user.Close()
DBconn.Close()
Return True
Else
loginerror = "Invalid Password"
user.Close()
DBconn.Close()
Return False
End If
End If
Else
loginerror = "Invalid Username"
user.Close()
DBconn.Close()
Return False
End If
Loop Until UserFound = True
user.Close()
DBconn.Close()
Return False
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If login() = True Then
Welcome.Show()
Me.Close()
Else
MessageBox.Show(loginerror, "Login Message")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AcceptButton = Button1
Me.Show()
Application.DoEvents()
txtuser.Focus()
End Sub
Private Sub txtpass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpass.TextChanged
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub txtuser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtuser.TextChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
End Class
Just in case here is my coding for my main form:
Public Class Mainform
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select MessageBox.Show("Are you sure you want to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case Windows.Forms.DialogResult.Yes
Case Windows.Forms.DialogResult.No
e.Cancel = True
End Select
End Sub
Private Sub Mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WorkTableAdapter.Fill(Me.LoginDBDataSet.Work)
Me.AssetTableAdapter.Fill(Me.LoginDBDataSet.Asset)
Me.HistoryTableAdapter.Fill(Me.LoginDBDataSet.History)
Me.InventoryTableAdapter.Fill(Me.LoginDBDataSet.Inventory)
Me.Equipment1TableAdapter.Fill(Me.LoginDBDataSet.Equipment1)
End Sub
Private Sub mainform_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub Equipment1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Equipment1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Equipment1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.LoginDBDataSet)
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Mainform_Load(Me, New System.EventArgs)
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
Form1.Show()
Me.Dispose()
Me.Close()
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
End Sub
Private Sub IDLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TabPage5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage5.Click
End Sub
Private Sub Equipment_NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub HistoryDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub InventoryDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
End Sub
Private Sub Machine_IDTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub _WO_CompletedLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub _WO_CompletedCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub _WO_CompletedCheckBox_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Machine_IDTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Machine_IDTextBox1.TextChanged
End Sub
Private Sub _WO_CompletedCheckBox_CheckedChanged_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _WO_CompletedCheckBox.CheckedChanged
End Sub
End Class
you need to determine if the user is administrator or not (usually your user table should have a role attached to the user e.g. administration, employee, etc.)
something like this when you try to log in
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If login() = True and UserRole='Administrator' Then
Welcome.Show()
Me.Close()
elseif login() = True then
WelcomeUser.Show()
Me.Close()
Else
MessageBox.Show(loginerror, "Login Message")
End If
End Sub

VSTUDIO2012 How to make a "borderstyle = none" form MOVEABLE

I'm learnning vstudio 2012, I'm trying to make moveable a form with "borderstyle = none" but i can't.
All the info that i found in Google talks about vb4 5 & 6 about this problem, versions too earlier for me and i cannot use they (I don't know how to).
my declaraments is very simple, i only need to make the window moveable by clicking on the app (anywhere on the form):
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label2.Text = "X: " & MousePosition.X
Label3.Text = "Y: " & MousePosition.Y
End Sub
Sub Form1_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar >= ChrW(3) Then
Clipboard.SetDataObject(Label2.Text & " " & Label3.Text)
End If
End Sub
End Class
Any help please? thankyou for read
I've resolved this, thanks.
Private ArrastrarForm As Boolean
Private PosicionMouseHeader As Point
Private tmpPoint As Point
Private Sub Form1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
ArrastrarForm = True
PosicionMouseHeader = e.Location
End If
End Sub
Private Sub Form1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If ArrastrarForm Then
tmpPoint = Me.Location + e.Location - PosicionMouseHeader
Me.Location = tmpPoint
End If
End Sub
Private Sub Form1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
ArrastrarForm = False
End If
End Sub
bye!

Resources