visual basic 2008 generate text box on click - vb.net

I have created the text box, and the generate button.
when I click on the generate button, I want it to display a text box with numbers. How do I do so using the event handler?. Sorry, basic question.

If all that you are trying to do is to set the value of a text box when a button is clicked, then you can do it like in the following example. You'll have to replace the names of the controls with whatever you have called them:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Static count As Integer = 0
count += 1
Select Case count
Case 1
TextBox1.Text = "123"
Case 2
TextBox1.Text = "345"
End Select
End Sub

First, drag a TextBox from your tool box, then double-click on your button and edit your Button1_Click method, like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "12234234234"
End Sub

Related

variable object name error

I have the following:
a listbox called ListBox1 with a couple of random values in it
a couple of rich textboxs called Rit11 up to Rit 154
a button
When I click a rich textbox, I want to set the a variable to the number that the box is called. After this I select a value from the listbox, and when I press the button, I want this value to move to the selected textbox, and be removed from the listview. I made the following code, but it gives an error.
Private Sub Rit12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rit12.Click
SelBox = "12"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim BoxName
BoxName = ("Rit" & SelBox)
Me.Controls(BoxName).Text = ListBox1.SelectedItem
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
It worked fine, till I tried using the variable name. This rule seems to give the problem:
Me.Controls(BoxName).Text = ListBox1.SelectedItem

add selected item from listbox to textbox but do not remove text after from textbox after i add from listbox

Example what i want so if i type some keywords to textbox i do not it remove text from textbox
when click on listbox and add that selected item to textbox but only after keywords and do not remove them both just leave as it is ?
How can you do that ?
this is code i have for so far.
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
TextBox1.Text = ListBox2.SelectedItem
End Sub
Thanks.
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
TextBox1.Text += ListBox2.SelectedItem
End Sub
Add the plus sign before equals to the += sign is an Add AND assignment operator, It adds right value to the left value and assigns the result to left value

Select case with VB GUI (For School)

Greetings and salutations. I really need help for school.
This is what I'm dealing with:
Cannot make selection until one option is picked.
The "You have selected a hostel location" text shouldn't show up until "Select Location" is pressed.
My assignment is a hostel selection, allowing the user to select one or the other. Once the selection is made via btnselect, lblselected is supposed to show up, then the window is supposed to close.
Please help me. I have no idea what I'm doing. I'm a web designer trying to expand my knowledge.
Option Explicit On
Public Class frmhostelselection
Private Sub btnlondon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlondon.Click
End Sub
Private Sub btndublin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndublin.Click
End Sub
Private Sub btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnselect.Click
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
End Sub
Private Sub lblselected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblselected.Click
End Sub
Private Sub lblmsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblmsg.Click
End Sub
End Class
Ok, i get you a logic
First on you loadsub
you must add
londonlistbox.enabled = false
dublinlistbox.enabled = false
then, add to you london button
dublinlistbox.enabled = false
london.enabled = false
and add the opposite to the dublin button
then, select location
select case londonlistbox and dublinlistbox
case londonlistbox.enabled = true
label1.text = londonlistbox.selecteditems
case dublinlistbox.enabled = true
label1.text = dublinlistbox.selecteditems
that's all
You want to hide the label. In visual studio, you want to select the label, and set its visible value to false. Or you can set it to be invisible for the formload event.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblselected.visible = false
end sub
You then need it to show for the button click event.
lblselected.visible = true
From your picture i am unsure what the buttons are to do. You seem to have 2 actual locations to choose (as buttons) and another button which seems to act as a select button.
You also have requested a select case command in your question.
So perhaps you want t select case to load when you click the select location button, and that a value will be set if you click either of the other buttons?
As above said, you have made no attempt to try this yourself, so i won't write the code, but it sounds like you want this...
The 2nd label should be invisible until the select button is clicked.
You want to string or something that will identify what has been pressed. This string should be a global variable that is declared beneath the public path.
When either londen button or... other button is pressed, the global string should change to either London or...Dublin.
When you press the select button, it should load a select case method which will check for either london or dublin.
Select case globalstring
case "London"
' make label visible, maybe change lblselected text to reflect that London was pressed.
case "Dublin"
' Make label visible, maybe change lblselected text to reflect that Dublin was pressed.
case default
' Produce an error message saying that nothing was pressed.
end Select
I'm guessing you also want images to show in those pictureboxs. Use initial image to get that one.
And the exit button will just be me.close()

Extract text from clicked submenu item of Menustrip

I've been dealing and looking for a way of extracting the text of any given subitem when clicked and write the text in textbox1.
this is the code that I have so far, but it does not seem to work.
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
Dim result As String
If AccionAToolStripMenuItem.Checked = True Then
result = AccionAToolStripMenuItem.Text
TextBox1.Text = result
End If
End Sub
You are using the wrong event. The ItemClicked event works for the items on the menu. You need to add a event for each of the subitems:
Sub SomeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SomeTSMenuItem.Click
TextBox1.Text = Ctype(sender, ToolStripMenuItem).Text
End Sub
You can make a function for each subitem or handle every event on the same function:
Handles item1.Click, item2.Click, item3.CLick
Try reading e.ClickedItem.Text.

How can i search using a Text box and Listbox in vb.Net?

give me code, in which i can enter a word in a textbox and a listbox appear with a item that has same string in which i enter in a textbox.
Please Help me...
I found the following via Google, which sound like the type of things you want to do:
Autosearch ListBox in VB.NET
(WinForms)
Search Listboxes as You Type
(WinForms or is this VB6?)
Searching for items in a ListBox
(WPF)
Using # 1, here is some code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
List1.Items.Add("Computer")
List1.Items.Add("Screen")
List1.Items.Add("Modem")
List1.Items.Add("Printer")
List1.Items.Add("Scanner")
List1.Items.Add("Sound Blaster")
End Sub
Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged
Dim i As Integer = List1.FindString(Text1.Text)
List1.SelectedIndex = i
If Text1.Text = "" Then
List1.SelectedIndex = -1
End If
End Sub
Think pseudocode, you can do this.
Grab the text from the textbox.
Set a pointer / counter to the listbox and loop through each item until the end of the list. If the textbox value has the same value as the listboxitem.text then you've found a match exit the for loop.
Add this code to texboxchange
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox1.SelectedIndex = ListBox1.FindString(TextBox1.Text.Trim)
End Sub