Displaying file properties - vb.net

Is possible to display file properties with full path and date. I would like to add file size and/or hash value of the file to the output (if possible) the data will be written to a text file not done yet I want to get the basic operation working first. This will be used as a file monitor for USB drives when all is said and done.
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents objWatcher As New clsFSW()
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents cmdStart As System.Windows.Forms.Button
Friend WithEvents cmdStop As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtFolder As System.Windows.Forms.TextBox
Friend WithEvents chkSubFolders As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.cmdStart = New System.Windows.Forms.Button()
Me.cmdStop = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.txtFolder = New System.Windows.Forms.TextBox()
Me.chkSubFolders = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(32, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox1.Size = New System.Drawing.Size(392, 240)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'cmdStart
'
Me.cmdStart.Location = New System.Drawing.Point(120, 336)
Me.cmdStart.Name = "cmdStart"
Me.cmdStart.TabIndex = 1
Me.cmdStart.Text = "Start Watch"
'
'cmdStop
'
Me.cmdStop.Location = New System.Drawing.Point(216, 336)
Me.cmdStop.Name = "cmdStop"
Me.cmdStop.TabIndex = 2
Me.cmdStop.Text = "Stop Watch"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(6, 272)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(93, 13)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Folder to Monitor:"
'
'txtFolder
'
Me.txtFolder.Location = New System.Drawing.Point(110, 272)
Me.txtFolder.Name = "txtFolder"
Me.txtFolder.Size = New System.Drawing.Size(184, 20)
Me.txtFolder.TabIndex = 4
Me.txtFolder.Text = ""
'
'chkSubFolders
'
Me.chkSubFolders.Location = New System.Drawing.Point(312, 272)
Me.chkSubFolders.Name = "chkSubFolders"
Me.chkSubFolders.Size = New System.Drawing.Size(128, 24)
Me.chkSubFolders.TabIndex = 6
Me.chkSubFolders.Text = "Include Subfolders"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(464, 373)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkSubFolders, Me.txtFolder, Me.Label1, Me.cmdStop, Me.cmdStart, Me.TextBox1})
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "File System Watcher Class Demo"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmdStop.Enabled = False
With objWatcher
End With
End Sub
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
Dim sDir As String
sDir = txtFolder.Text
If IO.Directory.Exists(sDir) Then
objWatcher.FolderToMonitor = sDir
objWatcher.StartWatch()
cmdStop.Enabled = True
cmdStart.Enabled = True
chkSubFolders.Enabled = True
Else
MessageBox.Show("Folder does not exist!")
End If
End Sub
Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
objWatcher.StopWatch()
cmdStop.Enabled = True
cmdStart.Enabled = True
chkSubFolders.Enabled = True
End Sub
Private Sub chkSubFolders_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSubFolders.CheckedChanged
objWatcher.IncludeSubfolders = (chkSubFolders.Checked = True)
End Sub
Private Sub objWatcher_FileCreated(ByVal FullPath As String) Handles objWatcher.FileCreated
TextBox1.Text &= "File Created: " & FullPath & ", " & DateString & vbCrLf
End Sub
Private Sub objWatcher_FileChanged(ByVal FullPath As String) Handles objWatcher.FileChanged
TextBox1.Text &= "File Changed: " & FullPath & ", " & DateString & vbCrLf
End Sub
Private Sub objWatcher_FileDeleted(ByVal FullPath As String) Handles objWatcher.FileDeleted
TextBox1.Text &= "File Deleted: " & FullPath & ", " & DateString & vbCrLf
End Sub
Private Sub objWatcher_FileRenamed(ByVal OldFileName As String, ByVal newFileName As String) Handles objWatcher.FileRenamed
TextBox1.Text &= "File Rename: " & OldFileName & " to " & newFileName & ", " & DateString & vbCrLf
End Sub
Private Sub objWatcher_FileWatchError(ByVal ErrMsg As String) Handles objWatcher.FileWatchError
TextBox1.Text &= "The following error occurred: " & ErrMsg & vbCrLf
End Sub
End Class

Related

call sub to change USERname color

I want to change USERname color inside RitchTextBox, I am using this code below to call the SUB but all the text now in red?
UPDATE
Sub AddMessage(txtUsername As String, txtSend As String)
box.SelectionColor = Color.Red
box.AppendText(vbCrLf & txtUsername & "$ ")
box.SelectionColor = Color.Black
box.AppendText(txtSend)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSend.Click
' Shell("net send " & txtcomputer.Text & " " & txtmessage.Text)
Try
If txtPCIPadd.Text = "" Or txtUsername.Text = "" Or txtSend.Text = "" Then
MsgBox("wright a message!", "MsgBox")
Else
client = New TcpClient(txtPCIPadd.Text, 44444)
Dim writer As New StreamWriter(client.GetStream())
txttempmsg.Text = (txtSend.Text)
writer.Write(txtUsername.Text + " # " + txtSend.Text)
AddMessage(txtUsername.Text, txttempmsg.Text + vbCrLf)
'txtmsg.Text="You:" + txtmessage.Text)
writer.Flush()
txtSend.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
When you have a problem trying to get something to work in your program. It is easier to create a test example that you can then use to figure out what is happening without dealing with a lot of other variables in your larger program. In your case I created a VB Winforms app, added a RichTextBox, two TextBox's and a Button. By doing so I am able to show that the function is working.
Public Class Form1
Sub AddMessage(txtUsername As String, txtSend As String)
box.SelectionColor = Color.Red
box.AppendText(vbCrLf & txtUsername & " :") 'Note added colon
box.SelectionColor = Color.Black
box.AppendText(txtSend) 'Note changed variable name to parameter name
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AddMessage(txtUsername.Text, txttempmsg.Text)
End Sub
End Class
Example:

Dual Monitor screen saver fail

I am attempting to make a dual screen screen saver. It was working at the beginning but now it isn't working. Here is the start up function:
Sub Main()
Dim x = 0
For Each screen As Screen In screen.AllScreens
Dim screensaver As ScrSav = New ScrSav(screen.Bounds)
screensaver.Location = screen.Bounds.Location
screensaver.Show()
x += 1
Debug.Print(screen.Bounds.Left & " " & screen.Bounds.Top & " " & screen.Bounds.Width & " " & screen.Bounds.Height & " " & "")
Next
Application.Run()
End Sub
and here is the form code
Public Class ScrSav
Public Sub New()
InitializeComponent()
End Sub
Public Sub New(xBounds As Rectangle)
InitializeComponent()
Me.Bounds = xBounds
Debug.Print(Me.Bounds.Left & " " & Me.Bounds.Top & " " & Me.Bounds.Width & " " & Me.Bounds.Height & " " & "")
Cards.Location = New Point((Me.Width - Cards.Width) / 2, (Me.Height - Cards.Height) / 2)
Header.Location = New Point((Me.Width - Header.Width) / 2, 0)
Cards.Navigate("http://pah.guycothal.com/screensaver.aspx")
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End
End Sub
Private Sub ScrSav_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
End
End Sub
End Class
What am i doing wrong???
I am initializing the 2 screen the way others are. in fact, i have a few places where I have put debugging in place to see what is going on in each of the subs. here is what is it outputting
0 0 1280 800 <--main
0 0 1280 800 <--new
1280 -224 1280 1024 <-main
1280 -224 1280 1024 <-new
I have labeled which sub each is from to make it easier to understand. Also, here is what is on the form itself
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ScrSav
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ScrSav))
Me.Cards = New System.Windows.Forms.WebBrowser()
Me.Header = New System.Windows.Forms.PictureBox()
CType(Me.Header, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Cards
'
Me.Cards.AllowNavigation = False
Me.Cards.AllowWebBrowserDrop = False
Me.Cards.IsWebBrowserContextMenuEnabled = False
Me.Cards.Location = New System.Drawing.Point(128, 137)
Me.Cards.MaximumSize = New System.Drawing.Size(640, 200)
Me.Cards.MinimumSize = New System.Drawing.Size(640, 200)
Me.Cards.Name = "Cards"
Me.Cards.ScriptErrorsSuppressed = True
Me.Cards.ScrollBarsEnabled = False
Me.Cards.Size = New System.Drawing.Size(640, 200)
Me.Cards.TabIndex = 0
Me.Cards.TabStop = False
Me.Cards.Url = New System.Uri("http://pah.guycothal.com/screensaver.aspx", System.UriKind.Absolute)
Me.Cards.WebBrowserShortcutsEnabled = False
'
'Header
'
Me.Header.Image = CType(resources.GetObject("Header.Image"), System.Drawing.Image)
Me.Header.InitialImage = CType(resources.GetObject("Header.InitialImage"), System.Drawing.Image)
Me.Header.Location = New System.Drawing.Point(0, 0)
Me.Header.MaximumSize = New System.Drawing.Size(2000, 60)
Me.Header.MinimumSize = New System.Drawing.Size(2000, 60)
Me.Header.Name = "Header"
Me.Header.Size = New System.Drawing.Size(2000, 60)
Me.Header.TabIndex = 1
Me.Header.TabStop = False
'
'ScrSav
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.Black
Me.ClientSize = New System.Drawing.Size(991, 453)
Me.Controls.Add(Me.Header)
Me.Controls.Add(Me.Cards)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "ScrSav"
Me.ShowInTaskbar = False
Me.Text = "ScrSav"
Me.TopMost = True
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
CType(Me.Header, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents Cards As System.Windows.Forms.WebBrowser
Friend WithEvents Header As System.Windows.Forms.PictureBox
End Class

Why is my form disappearing when I press ENTER?

Good-day,
I'm experiencing a very strange event that just started happening. Whenever I press the ENTER button on my keyboard, I expect the KeyDown event of my textbox to be raised and the corresponding code run. Instead, the form disappears (as if the .Hide() method has been called). When I debug, I see that the code that's supposed to run after the KeyDown event is raised is executing accordingly - but the form just disappears.
I've never encountered this before, so I don't know what to do. Any help would be appreciated. Thanks.
HERE'S THE CODE OF MY FORM:
Imports System.Net
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class FormAdd
#Region "VARIABLE DECLARATIONS CODE"
'FOR MySQL DATABASE USE
Public dbConn As MySqlConnection
'FOR CARD NUMBER FORMATTING
Private CF As New CardFormatter
'FOR CARD ENCRYPTION
Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider
Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encryptedCard As String
#End Region
#Region "SUB-ROUTINES AND FUNCTIONS"
Private Sub GetDBdata()
Try
If TextBoxAccount.Text = "" Then
MessageBox.Show("Sorry, you must enter an ACCOUNT# before proceeding!")
TextBoxAccount.Focus()
Else
dbConn = New MySqlConnection
dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("SELECT * FROM customer WHERE accountNumber = " & TextBoxAccount.Text, dbConn)
Dim dbTable As New DataTable
dbAdapter.Fill(dbTable)
If dbTable.Rows.Count > 0 Then
'MessageBox.Show("Customer Account Found!")
Call recordFound()
TextBoxLastName.Text = dbTable.Rows(0).Item("nameLAST")
TextBoxFirstName.Text = dbTable.Rows(0).Item("nameFIRST")
TextBoxSalutation.Text = dbTable.Rows(0).Item("nameSALUTATION")
TextBoxCompanyName.Text = dbTable.Rows(0).Item("nameCOMPANY")
Else
'MessageBox.Show("No Customer Records Found! Please try again!")
Call recordNotFound()
ButtonReset.PerformClick()
End If
dbConn.Close()
End If
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
Dispose()
End Sub
Private Sub SetDBData()
Try
dbConn = New MySqlConnection
dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
Dim noCard As Boolean = True
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbQuery As String = "SELECT * FROM cc_master WHERE ccNumber = '" & TextBoxCard.Text & "';"
Dim dbData As MySqlDataReader
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
dbCmd.CommandText = dbQuery
dbCmd.Connection = dbConn
dbAdapter.SelectCommand = dbCmd
dbData = dbCmd.ExecuteReader
While dbData.Read()
If dbData.HasRows() = True Then
MessageBox.Show("This Credit/Debit Card Already Exists! Try Another!")
noCard = False
Else
noCard = True
End If
End While
dbData.Close()
If noCard = True Then
'PERFORM CARD ENCRYPTION
'PERFORM DATABASE SUBMISSION
Dim dbQuery2 As String = "INSERT INTO cc_master (ccType, ccNumber, ccExpireMonth, ccExpireYear, ccZipcode, ccCode, ccAuthorizedUseStart, ccAuthorizedUseEnd, customer_accountNumber)" & _
"VALUES('" & ComboBoxCardType.SelectedItem & "','" & TextBoxCard.Text & "','" & TextBoxExpireMonth.Text & "','" & TextBoxExpireYear.Text & _
"','" & TextBoxZipCode.Text & "','" & TextBoxCVV2.Text & "','" & Format(DateTimePickerStartDate.Value, "yyyy-MM-dd HH:MM:ss") & "','" & Format(DateTimePickerEndDate.Value, "yyyy-MM-dd HH:MM:ss") & "','" & TextBoxAccount.Text & "');"
Dim dbData2 As MySqlDataReader
Dim dbAdapter2 As New MySqlDataAdapter
Dim dbCmd2 As New MySqlCommand
dbCmd2.CommandText = dbQuery2
dbCmd2.Connection = dbConn
dbAdapter2.SelectCommand = dbCmd2
dbData2 = dbCmd2.ExecuteReader
MessageBox.Show("Credit/Debit Card Information Saved SUCCESSFULLY!")
ButtonReset.PerformClick()
End If
dbConn.Close()
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
Dispose()
End Sub
Private Sub ResetForm()
TextBoxAccount.Clear()
TextBoxLastName.Clear()
TextBoxFirstName.Clear()
TextBoxSalutation.Clear()
TextBoxCard.Clear()
ComboBoxCardType.SelectedItem = ""
TextBoxCompanyName.Clear()
TextBoxCVV2.Clear()
TextBoxExpireMonth.Clear()
TextBoxExpireYear.Clear()
TextBoxZipCode.Clear()
CheckBoxConfirm.Checked = False
TextBoxAccount.SelectionStart = 0
TextBoxAccount.SelectionLength = Len(TextBoxAccount.Text)
TextBoxAccount.Focus()
GroupBoxInputError.Hide()
LabelInstruction.Show()
GroupBox1.Height = 75
End Sub
Private Sub recordFound()
GroupBoxInputError.Text = ""
LabelError.BackColor = Color.Green
LabelError.ForeColor = Color.White
LabelError.Text = "RECORD FOUND!"
GroupBoxInputError.Visible = True
GroupBox1.Height = 345
ButtonReset.Show()
LabelInstruction.Hide()
ComboBoxCardType.Focus()
End Sub
Private Sub recordNotFound()
GroupBoxInputError.Text = ""
LabelError.BackColor = Color.Red
LabelError.ForeColor = Color.White
LabelError.Text = "NO RECORD FOUND!"
GroupBoxInputError.Visible = True
End Sub
'Public Sub encryptCard()
' Try
' DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(My.Settings.Key))
' DES.Mode = System.Security.Cryptography.CipherMode.ECB
' Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor
' Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(TextBoxCard.Text)
' TextBoxCard.Text = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
' Catch ex As Exception
' MessageBox.Show("The following error(s) have occurred: " & ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
' End Try
'End Sub
#End Region
#Region "TOOLSTRIP MENU CONTROL CODE"
Private Sub ExitAltF4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitAltF4ToolStripMenuItem.Click
End
End Sub
#End Region
#Region "BUTTON CONTROLS CODE"
Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
FormMain.Show()
Me.Close()
End Sub
Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
Call ResetForm()
End Sub
Private Sub ButtonSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click
Call SetDBData()
Call ResetForm()
End Sub
Private Sub ButtonEncrypt_Click(sender As System.Object, e As System.EventArgs) Handles ButtonEncrypt.Click
End Sub
#End Region
#Region "FORM CONTROLS CODE"
Private Sub FormAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
TextBoxAccount.Focus()
Me.KeyPreview = True
Timer1.Enabled = True
Timer1.Interval = 1
GroupBoxInputError.Hide()
ButtonSubmit.Hide()
ButtonReset.Hide()
GroupBox1.Height = 75
'LabelFooter.Text = "Welcome " & FormLogin.TextBoxUsername.Text() & " | Timestamp: " & Date.Now.ToString
Try
LabelIP.Text = "IP: " & Dns.GetHostEntry(Dns.GetHostName).AddressList(0).ToString
Catch ex As Exception
End Try
'Populate the Card Type combobox with the list of card types from the CardFormatter class
ComboBoxCardType.Items.AddRange(CF.GetCardNames.ToArray)
End Sub
#End Region
#Region "TEXTBOX CONTROLS CODE"
Private Sub TextBoxCard_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBoxCard.GotFocus
TextBoxCard.SelectionStart = 0
TextBoxCard.SelectionLength = Len(TextBoxCard.Text)
Me.Refresh()
End Sub
Private Sub TextBoxCard_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBoxCard.LostFocus
'//CARD VALIDATION//
' This code will check whether the card is a valid number or not. It doesn't check to see if the card is active.
' The code calls on the creditcard function stored in MyModules.vb
Try
If creditcard(TextBoxCard.Text) Then
'MsgBox("Card is Valid")
TextBoxCard.BackColor = Color.GreenYellow
TextBoxCard.ForeColor = Color.Black
GroupBoxInputError.Visible = False
TextBoxCard.Text = CF.GetFormattedString(ComboBoxCardType.Text, TextBoxCard.Text)
Me.Refresh()
Else
BWErrorNotice.RunWorkerAsync()
'MsgBox("Invalid Card")
GroupBoxInputError.Visible = True
TextBoxCard.Focus()
TextBoxCard.Text = TextBoxCard.Text.Replace("-", "")
Me.Refresh()
End If
Catch ex As Exception
End Try
End Sub
Private Sub TextBoxAccount_GotFocus(sender As Object, e As System.EventArgs) Handles TextBoxAccount.GotFocus
TextBoxAccount.SelectAll()
End Sub
Private Sub TextBoxAccount_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBoxAccount.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
If TextBoxAccount.Text <> "" Then
Call GetDBdata()
Else
MsgBox("You must enter an account number!", MsgBoxStyle.Exclamation, "ATTENTION PLEASE!")
TextBoxAccount.Focus()
End If
End If
'If e.KeyCode = Keys.Enter Then
' e.Handled = True
' SendKeys.Send("{Tab}")
'End If
End Sub
Private Sub TextBoxCard_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBoxCard.MouseClick
TextBoxCard.SelectionStart = 0
TextBoxCard.SelectionLength = Len(TextBoxCard.Text)
TextBoxCard.Text = TextBoxCard.Text.Replace("-", "")
Me.Refresh()
End Sub
#End Region
#Region "OTHER/MISCELLANEOUS CONTROLS CODE"
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
LabelDateTime.Text = DateTime.Now
End Sub
Private Sub BWErrorNotice_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWErrorNotice.DoWork
Do While Not creditcard(TextBoxCard.Text)
LabelError.BackColor = Color.Black
System.Threading.Thread.Sleep(500)
LabelError.BackColor = Color.Red
System.Threading.Thread.Sleep(500)
Loop
BWErrorNotice.CancelAsync()
End Sub
Private Sub CheckBoxConfirm_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBoxConfirm.CheckedChanged
If CheckBoxConfirm.Checked = True Then
ButtonSubmit.Show()
Else
ButtonSubmit.Hide()
End If
End Sub
#End Region
End Class
Although what follows will not likely solve the form disappearance problem, it will resolve a downstream issue:
In GetDBData(), you are assigning accountNumber to the value of TextBoxAcount.Text, which must be enclosed with quotes unless you employ a parameter which I strongly recommend you get in the habit of doing.
Dim dbAdapter As New MySqlDataAdapter("SELECT * FROM customer WHERE accountNumber = " & TextBoxAccount.Text, dbConn)
Parameters offer a number of benefits including implicit type conversions, injection attack prevention, and will sometimes even cure unexpected behaviors.
I figured out the problem. I was calling Dispose() at the end of my GetDBData() function - so the form was getting disposed before execution returned back to the TextBox. I deleted it and all is well again.

Save TreeView As TXT or XML

Is there a way to save all the treeview items in visual basic as an TXT file (I Prefer TXT) or XML?
I also want to save it to my.settings.
Use a recursive function e.g.
Public Class Form1
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
TreeView1.Nodes.Add("Animal")
TreeView1.Nodes(0).Nodes.Add("Reptile")
TreeView1.Nodes(0).Nodes(0).Nodes.Add("Dragon")
TreeView1.Nodes(0).Nodes(0).Nodes.Add("Lizard")
TreeView1.Nodes(0).Nodes.Add("Mammal")
TreeView1.Nodes(0).Nodes(1).Nodes.Add("Cat")
TreeView1.Nodes(0).Nodes(1).Nodes.Add("Dog")
TreeView1.Nodes.Add("Vegetable")
TreeView1.Nodes(1).Nodes.Add("Fruit")
TreeView1.Nodes(1).Nodes(0).Nodes.Add("Apple")
TreeView1.Nodes(1).Nodes(0).Nodes.Add("Orange")
TreeView1.Nodes(1).Nodes(0).Nodes.Add("Pear")
TreeView1.Nodes(1).Nodes.Add("Aubergine")
TreeView1.Nodes(1).Nodes.Add("Carrot")
TreeView1.Nodes(1).Nodes.Add("Cucumber")
TreeView1.Nodes(1).Nodes.Add("Zucchini")
TreeView1.Nodes.Add("Mineral")
TreeView1.Nodes(2).Nodes.Add("Granite")
TreeView1.Nodes(2).Nodes.Add("Quartz")
TreeView1.Nodes(2).Nodes.Add("Topaz")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Multiline = True
TextBox1.Height = 200
TextBox1.Width = 200
TextBox1.Text = WriteTreeView("", TreeView1.Nodes)
End Sub
Private Function WriteTreeView(ByVal parent As String, ByVal tnc As TreeNodeCollection) As String
Dim strOutput As String = ""
If tnc.Count = 0 Then
strOutput = parent & vbCrLf 'leaf
Else
For i As Integer = 0 To tnc.Count - 1
Dim strCurrent As String = ""
If parent > "" Then strCurrent = parent & "."
strCurrent &= tnc(i).Text
strOutput &= WriteTreeView(strCurrent, tnc(i).Nodes)
Next i
End If
Return strOutput
End Function
End Class

Clearing text boxes

I compiled the following little application only I want all the textpoxes cleard when the tabs areswitched by the user how can this be achieved?
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FILE_NAME As String = "C:\test.pgp"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
objWriter.WriteLine((TextBox2.Text) + "," + " " + "*" + (TextBox1.Text))
objWriter.Close()
MsgBox("The acad.pgp file was successfully appended…")
Else
MsgBox("File missing reinstall or contact vendor…")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim FILE_NAME As String = "C:\test.pgp"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
objWriter.WriteLine((TextBox3.Text) + "," + " " + "START " + (TextBox4.Text) + ", 1,,")
objWriter.Close()
MsgBox("The acad.pgp file was successfully appended…")
Else
MsgBox("File missing reinstall or contact vendor…")
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim FILE_NAME As String = "C:\test.pgp"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
objWriter.WriteLine((TextBox5.Text) + "," + " " + "START " + (TextBox6.Text) + ", 1,,")
objWriter.Close()
MsgBox("The acad.pgp file was successfully appended…")
Else
MsgBox("File missing reinstall or contact vendor…")
End If
End Class
Public Sub ClearTextBoxes(frmClearMe As Form)
Dim txt As Control
For Each txt In frmClearMe
If TypeOf txt Is TextBox Then txt.Text = ""
Next
End Sub