This question has been answered.
Do not want to leave it exposed.
Private Sub btnTTL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles findzipButton.Click
Dim zipCode As String
'forgot
If (ListBox1.FindString(findzipButton.Text) >= 0) Then
ttlTextBox.Text = "$15"
ElseIf (ListBox2.FindString(findzipButton.Text) >= 0) Then
ttlTextBox.Text = "$20"
Else
MessageBox.Show("The zipcode was not found!")
End If
End Sub
End Class
So what I think your trying to do is match the input a user puts into a text box with a selection in the either ListBoxA or ListBoxB. I just tried this in VS 2012, and it seems to work in the way the problem above describes, but I'm only trying to find and display the shipping cost:
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub ListBox1_Load(sender As Object, e As EventArgs) Handles Me.Load
ListBox1.Items.Add("60611")
ListBox1.Items.Add("60234")
ListBox1.Items.Add("56789")
ListBox1.Items.Add("23467")
ListBox1.Items.Add("60543")
ListBox1.Items.Add("60561")
ListBox1.Items.Add("55905")
ListBox1.Items.Add("89567")
ListBox2.Items.Add("50978")
ListBox2.Items.Add("78432")
ListBox2.Items.Add("98432")
ListBox2.Items.Add("97654")
ListBox2.Items.Add("20245")
End Sub
Private Sub btnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFind.Click
Dim zipCode As String = txtZipCode.Text
If (ListBox1.FindString(zipCode) >= 0) Then
txtShipping.Text = "$15"
ElseIf (ListBox2.FindString(zipCode) >= 0) Then
txtShipping.Text = "$20"
Else
MessageBox.Show("The zipcode was not found!")
End If
End Sub
You were on the right track. What you needed to do was compare what the user actually input to the textbox to what was available in the Listbox. The FindItem() method will then result a Long. If it did find your search string it will build the shipping text box.
Related
I have a program I created in VisualBasic that is very similar to a slideshow image viewer. On the left side the user is able to select an image from a location and display it. On the right side I would like them to be able to use the combo box to select a category which would only display images in that category.
I am currently able to get an image list loaded in the right side and the user can cycle through that list, but I am having trouble figuring out how to connect the combobox and imagelist. Maybe there is another route I should try?
Public Class Form1
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
btnPrev.Enabled = True
Static i As Integer
Dim incp As String
incp = +1
i += 1
PictureBox2.Image = ImageList1.Images(i)
If i = ImageList1.Images.Count - 1 Then
i = -1
End If
End Sub
Private Sub Btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
Static i As Integer
Dim incp As String
incp = +1
i += 1
PictureBox2.Image = ImageList1.Images(i)
If i = ImageList1.Images.Count - 1 Then
i = -incp
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
End Class
So you're saying that you have multiple ImageList objects and you want the user to select one using the ComboBox? If so then you do it like you would for selecting from any other list of objects using a ComboBox, e.g.
category1ImageList.Tag = "Category 1"
category2ImageList.Tag = "Category 2"
categoriesComboBox.DisplayMember = "Tag"
categoriesComboBox.DataSource = {category1ImageList, category2ImageList}
The user selects from the Tag values and then the SelectedItem of the ComboBox is the selected ImageList.
Below I have an array and in my design I have a check list box with 10 options. For example, if boxes 1 and 2 were checked, I would only want to print Indexes 0 and 1 ONLY. I have a button that prints all of the array members (included below) and that is what I want to make print only selected items. I have tried using a switch but that file had gotten corrupted and I am lost. Thank you. (Language is VB)
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btn1.Click
Dim strDecimal(9) As String
strDecimal(0) = FormatPercent(0.0146175)
strDecimal(1) = FormatPercent(0.0345324585)
strDecimal(2) = FormatPercent(0.09324543575)
strDecimal(3) = FormatPercent(0.07346475)
strDecimal(4) = FormatPercent(0.0772346615)
strDecimal(5) = FormatPercent(0.42234234654)
strDecimal(6) = FormatPercent(0.6246264664)
strDecimal(7) = FormatPercent(0.4524642234)
strDecimal(8) = FormatPercent(0.6876543534)
strDecimal(9) = FormatPercent(0.6876543534)
For num As Integer = 0 To strDecimal.Length - 1
listArrays.Items.Add(strDecimal(num))
Next
End Sub
Private Sub clearList()
listArrays.Items.Clear()
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
clearList()
End Sub
Assuming you're using a CheckedListBox and want to know which items are Checked:
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
For Each itm As String In listArrays.CheckedItems
Debug.Print(itm)
Next
End Sub
I'm writing a program for an internship and need some advice. I've done my research but have mostly returned fruitless... I need to loop the "buttonOneClick for one second iterations. The program will send a "P" character, wait one second, send a p, wait one second, etc... Also I need to write the information it receives to an excel spreadsheet. Any help/critiquing of existing code would be greatly appreciated.
Here's what I have:
Public Class Form2
Dim buttonOnePush As Boolean = False
Dim buttonTwoPush As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Send strings to a serial port.
Using com5 As IO.Ports.SerialPort =
My.Computer.Ports.OpenSerialPort("COM5")
com5.WriteLine("P")
End Using
End Sub
Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""
Dim com5 As IO.Ports.SerialPort = Nothing
Try
com5 = My.Computer.Ports.OpenSerialPort("COM5")
com5.ReadTimeout = 10000
Do
Dim Incoming As String = com5.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Loop
Catch ex As TimeoutException
returnStr = "Error: Serial Port read timed out."
Finally
If com5 IsNot Nothing Then com5.Close()
End Try
Return returnStr
End Function
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If IsNumeric(TextBox1.Text) AndAlso IsNumeric(TextBox2.Text) Then
TextBox1.Text = CDec(TextBox2.Text)
End If
End Sub
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
If IsNumeric(TextBox6.Text) AndAlso IsNumeric(TextBox3.Text) Then
TextBox6.Text = CDec(TextBox3.Text)
End If
End Sub
Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
If IsNumeric(TextBox7.Text) AndAlso IsNumeric(TextBox4.Text) Then
TextBox7.Text = CDec(TextBox4.Text)
End If
End Sub
Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
If IsNumeric(TextBox8.Text) AndAlso IsNumeric(TextBox5.Text) Then
TextBox8.Text = CDec(TextBox5.Text)
End If
End Sub
Private Sub TextBox15_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox15.TextChanged
If IsNumeric(TextBox15.Text) AndAlso IsNumeric(TextBox16.Text) Then
TextBox15.Text = Hex(TextBox16.Text)
End If
End Sub
Private Sub TextBox14_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox14.TextChanged
If IsNumeric(TextBox14.Text) AndAlso IsNumeric(TextBox11.Text) Then
TextBox14.Text = Hex(TextBox11.Text)
End If
End Sub
Private Sub TextBox13_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox13.TextChanged
If IsNumeric(TextBox13.Text) AndAlso IsNumeric(TextBox10.Text) Then
TextBox13.Text = Hex(TextBox10.Text)
End If
End Sub
Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged
If IsNumeric(TextBox12.Text) AndAlso IsNumeric(TextBox9.Text) Then
TextBox12.Text = Hex(TextBox9.Text)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
buttonTwoPush = True
buttonOnePush = False
Me.Close()
Form1.Close()
End Sub
End Class
Use a Timer to issue that command at one second intervals. Drag a Timer over to your form from the toolbox, and double click on it to get a _Tick method.
Set the .Interval member of the timer in your form's constructor, and use the .Start and .Stop methods to control it.
For the Excel piece, you'll need to add a reference to the project for the Microsoft Excel 12.0 (or 14.0 if you have Excel 2010) Object Library. Find this under the COM tab of the Add Reference dialog which you get by right clicking on the project in the Solution Explorer. See this page for an exhaustive reference (scroll down to the bottom of the page for a quick example in VB.NET).
So I have a code atm that has 2 combo boxes, one to select the make, then it will enable the model, I have 3 model choices, here's code:
Public Class Form2
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmb_make.Items.Add("Toyota")
cmb_make.Items.Add("Nissan")
cmb_make.Items.Add("Hyundai")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_finish.Click
If cmb_make.Text = "" Then
MsgBox("Please select your make")
End If
If cmb_model.Text = "" Then
MsgBox("Please select your model")
End If
If cmb_model.Text = ("Supra") Then
Form3.Show()
Me.Close()
End If
If cmb_model.Text = ("MR2") Then
Form4.Show()
Me.Close()
End If
If cmb_model.Text = ("Hilux") Then
Form5.Show()
Me.Close()
End If
If cmb_model.Text = ("R34") Then
Form6.Show()
Me.Close()
End If
If cmb_model.Text = ("R33") Then
Form7.Show()
Me.Close()
End If
If cmb_model.Text = ("R32") Then
Form8.Show()
Me.Close()
End If
If cmb_model.Text = ("Genesis Coupe") Then
Form9.Show()
Me.Close()
End If
If cmb_model.Text = ("RD1 Coupe") Then
Form10.Show()
Me.Close()
End If
If cmb_model.Text = ("Excel") Then
Form11.Show()
Me.Close()
End If
End Sub
Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_make.SelectedIndexChanged
Dim Strchoice As String
Strchoice = cmb_make.SelectedItem
If Strchoice = "Toyota" Then
End If
cmb_model.Items.Clear()
cmb_model.Items.Add("Supra")
cmb_model.Items.Add("MR2")
cmb_model.Items.Add("Hilux")
If Strchoice = "Nissan" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("R34")
cmb_model.Items.Add("R32")
cmb_model.Items.Add("R33")
ElseIf Strchoice = "Hyundai" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("RD1 Coupe")
cmb_model.Items.Add("Genesis Coupe")
cmb_model.Items.Add("Excel")
Once I have selected my model of the car, it takes me to that specific form with a picture of that model, I then want to display individual parts, with individual prices that will add up in a text box above, can someone help me and tell me how? Please this is due tomorrow I'm freaking out!!
You can put the parts into picture boxes on the model's form and have either check boxes or radio buttons (depending on what functionality you are required to do) underneath that have the prices as labels and then use an if structure to assign a value to them that can be totaled in the text box.
Dim total as double
If chk_part1.checked = true then
total += partPrice
If chk_part2.checked = true then
total += partPrice
txtTotal.text = total
Not saying that this code is perfect but you could implement something along those lines to get the results you're looking for.
You can also do a For Each Statement. Such as:
Dim Form As New Form3.ControlCollection(Me)
For Each CheckBox As CheckBox In Form
If CheckBox.Checked = True Then
total += partPrice
End If
Next
So, In essense, it should cycle through all of the check boxes and, if they are checked, it adds the part price to the total.
i have 1 text box and 1 listbox in my VB form.
i want to check duplicate item,compare with textbox.text1 and listbox.list item.
and if textbox.text1 value is '3333' and listbox.list multiple value is '1111' '2222' '3333' '4444'
so how to implement such like duplicate check routine?
so if duplicate detect compare with current text1 value and compare with one of listbox's
value is if detect,want to popup messagebox
thanks in advance
Assuming you are inserting strings into your ListBox you can do this:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim x As String
For Each x In ListBox1.Items
If (x = TextBox1.Text) Then
MessageBox.Show("Error")
Return
End If
Next
ListBox1.Items.Add(TextBox1.Text)
End Sub
If it's another type of object that has a property called Value then you need a small change:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim x As Foo
For Each x In ListBox1.Items
If (x.Value = TextBox1.Text) Then
MessageBox.Show("Error")
Return
End If
Next
ListBox1.Items.Add(TextBox1.Text)
End Sub
Assuming that the ListBox contains strings, you can use the Contains method of the Items collection to check for matches. Example (make a form with a ListBox called '_theListBox', a TextBox called '_theTextBox' and a Label called '_theLabel'):
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_theListBox.Items.AddRange(New String() {"aaaa", "bbbb", "cccc", "dddd"})
End Sub
Private Sub _theTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _theTextBox.TextChanged
If ListBoxContainsItem(_theListBox, _theTextBox.Text) Then
_theLabel.Text = "It's a match"
Else
_theLabel.Text = ""
End If
End Sub
Private Function ListBoxContainsItem(ByVal lb As ListBox, ByVal text As String) As Boolean
' check if the string is present in the list '
Return lb.Items.Contains(text)
End Function