Add a checkbox to allow the labels to be updated whenever the input text changes [closed] - vb.net

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am very new to programming language and am in my first Programming class at my university. For a project we are creating a VERY simple project where the user enters words and the program puts them together. It's day one stuff I know but I'm trying to go for the extra credit and "Add a check box to allow the labels to be updated whenever the input text changes".
I have a program that when you type in two separate words in separate text boxes it displays each word individually and then also the two words combined at the bottom. Our professor wants my to add an check box option at the bottom that when clicked with make it so when the users types the two words they display automatically without clicking the display button.
I know this is easy stuff, but any help would be much appreciated.
Thank you for your help.
Public Class form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblLeft.Click
End Sub
Private Sub lbl2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRight.Click
End Sub
Private Sub txtBoxLeft_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBoxLeft.TextChanged
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim strTxtBoxLeft As String
strTxtBoxLeft = txtBoxLeft.Text
Dim strTxtBoxRight As String
strTxtBoxRight = txtBoxRight.Text
lblLeft.Text = strTxtBoxLeft
lblRight.Text = strTxtBoxRight
lblCombo.Text = strTxtBoxLeft & " " & strTxtBoxRight
End Sub
Private Sub chkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbox.CheckedChanged
If chkbox.CheckState = False Then
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class

Try this:
Public Class Form1
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
combineText()
End Sub
Private Sub chkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbox.CheckedChanged
If chkbox.CheckState = False Then
lblCombo.Text = ""
End If
End Sub
Private Sub txtBox_TextChanged(sender As Object, e As EventArgs) Handles txtBoxRight.TextChanged, txtBoxLeft.TextChanged
If chkbox.CheckState Then
combineText()
End If
End Sub
Private Sub combineText()
lblCombo.Text = txtBoxLeft.Text & " " & txtBoxRight.Text
End Sub
End Class
Note: I have consolidated your logic down to just grab the text from the text boxes themselves. There is also one handler that handles text changing in either of the text boxes. Finally, there is a single method that handles combining the values of the two text boxes together, either via the text changed event if the check box is checked or if the user clicks the update button. Also, if the user unchecks the check box, then it will clear the results. Then when the user clicks update it will display the combined text again.

Related

Drag and drop Text Box to List Box

I'm working on a VB.net(2015) code that would allow me to drag and drop from a text box to a list box.
I've set up the code below, and set the allow drop in the list box to true.
I’m able to drag the text to the list box, but it doesn’t appear in the list box.
Looking at the code below I’m not sure what piece I’ve left out, are there any recommendations or suggestions on what can be done?
Public Class PotluckParty
Private Sub enterFoodTextBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles enterFoodTextBox.MouseDown
enterFoodTextBox.DoDragDrop(enterFoodTextBox.Text, DragDropEffects.Move)
End Sub
Private Sub SaladListBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SaladListBox.DragDrop
SaladListBox.Text &= e.Data.GetData(DataFormats.Text).ToString
enterFoodTextBox.Text = ""
End Sub
Private Sub SaladListBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SaladListBox.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
End If
End Sub

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

Passing variable from one form to another in vb.net

I've looked this question up 10 times but each answer is too specific to the question.
I have two public classes, one per form.
The first form has a textbox and two buttons:
Public Class frmAdd
Public addvar As String
Public Sub UltraButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNote.Click
If txtAdd.Text = String.Empty Then
MsgBox("Please complete the notes textbox!")
Else
addvar = txtAdd.Text
MsgBox(addvar)
Close()
End If
End Sub
Public Sub UltraButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
In the second form I want to take that addvar variable and say
Public Sub saveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
frmAdd.show()
me.textbox1.text = addvar
How do I get this to work in vb.net?
You need to read the field out of the frmAdd value
Me.textbox1.Text = frmAdd.addvar
Note that this value won't be available until the form has completed, and is closed (Me.close). Hence you want to use ShowDialog (doesn't return until form is closed) vs. Show (which returns immediately after displaying the form).
frmAdd.ShowDialog()
Me.textbox1.Text = frmAdd.addvar

vb2010 pass data from one form to another

I am trying to pass a value of a textbox on frmMain to a textbox on frmDepartment. I have tried the following code which I thought would work but it dosen't. I ma a new user to VB and come from a php background where it would have been a simple task of setting a seesion. Can anyone help with this? If you need to see more code, please ask. many thanks
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
In frmMain, I am getting value like this:
Dim value As Object = UserDataGridView.Rows(e.RowIndex).Cells(0).Value
txtCustomerActive.Text = CType(value, String)
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.Show()
End Sub
Which is showing in frmMain ok.
In frmDepartment I have this code
Private Sub txtDeptCustomer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDeptCustomer.TextChanged
'Dim customer As String
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
instead of putting the code within the txtDeptCustomer.TextChanged sub, try putting it within the frmDepartment_load:
Private Sub frmDepartment_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
or you could set the frmDepartment text box text on the frmMain button click:
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.txtDeptCustomer.Text = txtCustomerActive.Text
frmDepartment.Show()
End Sub

populating combo box on run time

I got two combo box on the system a Category and Sub Category
my concept must be when i choose COM OR PRT on cmbCategory,
cmbSubCategory will automatically display the corresponding subcategory for the category chosen
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items = "SU, MON"
End If
End Sub
my code returns error
Property Items is Read Only
Items is a collection so to put things into it you need to add them to the collection rather than direct assignment.
If SU and MON are meant to appear as separate items in the combo box then you could do something similar to:
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items.Clear()
cmbSubCategory.Items.Add("SU")
cmbSubCategory.Items.Add("MON")
End If
End Sub
If SU, MON is meant to appear as a single item then you could do:
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items.Clear()
cmbSubCategory.Items.Add("SU, MON")
End If
End Sub
Note that we use Clear to remove items from the combo box/ensure it is empty before populating it with the right options.
PS. I noticed that one of the tags for this question is "SQL", but from what I've read I don't think that this question has a SQL component to it...