how disable text box from two give text box? - vb.net

I have 2 text box in one vb form. if txtMaterial was fill i want to disable the txtPackage and vice versa. I use the code below, but it didn't work. could someone fixed it.
Really appreciate it. tq.
Private Sub txtMaterial_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged
txtMaterial.Enabled = True
txtPackage.Enabled = False
End Sub
Private Sub txtPackage_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPackage.TextChanged
txtPackage.Enabled = True
txtMaterial.Enabled = False
End Sub

Make both TextBoxes fire the same handler, then simply set the Enabled() state of each one based on whether the other TextBox has something in it:
Private Sub txtChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged, txtPackage.TextChanged
txtMaterial.Enabled = (txtPackage.TextLength = 0)
txtPackage.Enabled = (txtMaterial.TextLength = 0)
End Sub
*Note the ending of the first line has both controls listed using Handles txtMaterial.TextChanged, txtPackage.TextChanged at the end.

Private Sub txtMaterial_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged
If txtMaterial.Text <> "" Then
txtPackage.Enabled =False
End If
End Sub

based on the comment that you added
Blockquote i want to make it disable as the second one. but in my case if i fill the txtMaterial the txtPackage also can be fill with text at the same time.
the solution to your problem must be this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtPackage.Enabled = False
End Sub
Private Sub txtMaterial_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged
If Not String.IsNullOrEmpty(txtMaterial.Text) Then
txtPackage.Enabled = True
Else
txtPackage.Enabled = False
End If
End Sub

Related

Use a textbox to store a numeric counter in VB.Net

I want to count with a TextBox.
Here is my code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
OrainsProgressBar1.Increment(1)
If OrainsProgressBar1.Value = 100 Then
Timer3.Start()
Timer1.Stop()
End If
End Sub
Private Sub OrainsTheme1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrainsTheme1.Click
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Start()
Timer2.Start()
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
OrainsProgressBar1.Increment(-1)
If OrainsProgressBar1.Value = 0 Then
Timer1.Start()
Timer3.Stop()
End If
End Sub
Private Sub OrainsButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrainsButton1.Click
OrainsTextBox1.Text += 100
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OrainsTextBox1.Text += 1
End Sub
End Class
But I have an error with OrainsTextBox1.Text += 1. VB says:
'Conversion from string "" to type 'Double' is not valid.'
What is the problem?
In the .Net world, the data types of things matter a lot. Strings (like the .Text property) are NOT numbers. You need to convert. Even if someone only enters the digits 0-9 into the textbox, that's still a string of numeric characters, rather than a number. And what should happen if someone enters random text into that textbox that won't convert to a number type at all?
For this code, I suggest building a property, like this:
Private _orainsValue As Double
Public Property OrainsValue As Double
Get
Return _orainsValues
End Get
Set
_orainsValue = Value
OrainsTextBox1.Text = _orainsValue.ToString()
End Set
End Property
That will let you write code like this and have the expected result shown to the user:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OrainsVale += 1
End Sub
Note that it does mean you will want to mark the TextBox disabled,though, because this doesn't account for user data entry.
Instead of doing like this OrainsTextBox1.Text += 1
do like this OrainsTextBox1.Text = Val(OrainsTextBox1.Text) + 1
Because .Text is string. Which will append the 1s as "11111111"

Delete Button Codes

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Material_Status_DBDataSet.Material_Status_Table' table. You can move, or remove it, as needed.
Me.Material_Status_TableTableAdapter.Fill(Me.Material_Status_DBDataSet.Material_Status_Table)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'add
PL_NOTextBox.Enabled = True
NAME_OF_THE_JOBTextBox.Enabled = True
QUANTITYTextBox.Enabled = True
ITEMTextBox.Enabled = True
UNITTextBox.Enabled = True
REMARKSTextBox.Enabled = True
ACTION_TAKENTextBox.Enabled = True
Me.Material_Status_TableBindingSource.AddNew()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'delete
Me.Material_Status_TableBindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'edit
PL_NOTextBox.Enabled = True
NAME_OF_THE_JOBTextBox.Enabled = True
QUANTITYTextBox.Enabled = True
ITEMTextBox.Enabled = True
UNITTextBox.Enabled = True
REMARKSTextBox.Enabled = True
ACTION_TAKENTextBox.Enabled = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'update
Me.Validate()
Me.Material_Status_TableBindingSource.EndEdit()
Me.Material_Status_TableTableAdapter.Update(Me.Material_Status_DBDataSet)
TableAdapterManager.UpdateAll(Me.Material_Status_DBDataSet)
PL_NOTextBox.Enabled = False
NAME_OF_THE_JOBTextBox.Enabled = False
QUANTITYTextBox.Enabled = False
ITEMTextBox.Enabled = False
UNITTextBox.Enabled = False
REMARKSTextBox.Enabled = False
ACTION_TAKENTextBox.Enabled = False
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'search Me.Material_Status_TableTableAdapter.SearchPLNO(Me.Material_Status_DBDataSet.Material_Status_Table, TextBox1.Text)
End Sub
End Class
Hello, I am new to vb. My project has an add, delete & update search buttons that connect with a database called material status. When I run this project it don't permanently delete data record in database enter image description here , when delete button pressed. What is wrong here?
Could you please send me codes for display searching combo box instead of textbox1.

How to add items from a MenuStrip event to a ListBox using a For Next Loop

That might have sounded weird so let me explain.
I have a school assignment that has me pulling my hair out. I have to get a collection of 5 facts and have them display to a ListBox using a For Next Loop. The user would use an InputBox to input the facts.
I dont know what to put in the For Next to fetch the string from the InputBox. I'm at my wits end and am falling behind.
Here is what I have so far
Public Class frmWWIIFacts
Private Property RemoveAt As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub AddFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFactToolStripMenuItem.Click
Dim intFact As Integer
Dim strInputFact As String
strInputFact = InputBox("Do you want to add a fact?", "Add a fact")
For
Next
strInputFact = InputBox("Do you want to add a fact?", "Add a fact")
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ClearListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearListToolStripMenuItem.Click
lstFacts.Items.Clear()
End Sub
Private Sub RemoveFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveFactToolStripMenuItem.Click
End Sub
I've submitted a reddit post requesting some assistance but its gotten me nowhere. https://www.reddit.com/r/learnprogramming/comments/3t614u/vb2015_using_menustrip_to_addremove_items_in_a/
I would love some help on this. Please ask questions if your confused on my method or if you need to know more.
Sounds like you're trying to do this:
Private Sub AddFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFactToolStripMenuItem.Click
Dim intFact As Integer
Dim strInputFact As String
lstFacts.Items.Clear()
For intFact = 1 To 5
strInputFact = InputBox("Please enter a fact:", "Add a fact")
If Not strInputFact = "" Then
lstFacts.Items.Add(strInputFact)
End If
Next
End Sub

Get Own control values in visual basic 10

I'm looking for a way to get the data of control (in this case a Trackbar) inside the trackbar itself.
I got this:
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Label1.Text = TrackBar1.Value
End Sub
But I want to replace that "trackBar1." with something like
Label1.Text = THIS_CONTROL.Value
Is this possible in Vb10 ?
Thanks
Use the sender argument:
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Dim THIS_CONTROL As TrackBar = DirectCast(sender, TrackBar)
Label1.Text = THIS_CONTROL.Value
End Sub

VB.net Form unexpectingly terminating

Hi I have the following form but cant figureout why its upbrubtly terminiating when difrent buttons are clicked?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Dim TEST1 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST1 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
Private Sub button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WebBrowser1.Navigate("file://C:\test\test")
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.WebBrowser1.Navigate("file://C:\test")
Button2.Enabled = False
Button1.Enabled = True
End Sub
Private Sub button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
Dim TEST2 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST2 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
The terms face book and hotmail are just random to keep company site private :)
I suspect the Mouse_Enter event and the Mouse_Leave events are not giving time to the webbrowser to fully load the document and maybe it is internally crashing.
Try checking if the webbrowser has finished working before navigating again and tell us:
Use
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Me.WebBrowser1.Navigate("http://www.google.com")
End if