Private Sub CBFRANK_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBFRANK.CheckedChanged
If CBFRANK.Checked = True Then
existsub = subjectBox.Text
rollingsub = existsub + "FR, "
existfull = FullName.Text
rollingfull = existfull + "Franklin Hospital, "
subjectBox.Text = rollingsub
FullName.Text = rollingfull
Else
Replace(FullName.Text, "Franklin Hospital, ", "")
End If
End Sub
Thats what I have, and what it does is basically when you check a box it adds "ZHH, " to one text box and "Zucker Hillside Hospital, " to another.
What I want to be able to do is search those text boxes when the property is unchecked and I want it to just remove those additions regardless of where they are
So imagine I have this in the respective boxes:
XXX, ZHH, XXX
And in the other box
XXX Hospital, Zucker Hillside Hospital, XXX Hospital
I want to be able to remove both ZHH and Zucker Hillside Hospital from their respective boxes regardless of where they are in the string
The event handler would be the unchecked function the other "if"
Just use String.Replace searching for the text to remove and setting an empty string in its place
Private Sub CBZUCK_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBZUCK.CheckedChanged
If CBZUCK.Checked = True Then
subjectBox.Text = subjectBox.Text & "ZHH, "
FullName.Text = FullName.Text & "Zucker Hillside Hospital, "
Else
subjectBox.Text = subjectBox.Text.Replace("ZHH, ", "")
FullName.Text = FullName.Text.Replace("Zucker Hillside Hospital, ", "")
End If
End Sub
You can use the function Replace(), like this
replace(myString,"ZHH","")
so it's replace every instance of ZHH bu nothing.
Beware that it can erase ZHHYTVF and leave YTVF. It might not want that.
If CBZUCK.Checked = True Then
subjectBox.Text = subjectBox.Text & "ZHH, "
FullName.Text = FullName.Text & "Zucker Hillside Hospital, "
Else
subjectBox.Text = subjectBox.Text.Replace("ZHH, ", "")
FullName.Text = FullName.Text.Replace("Zucker Hillside Hospital, ", "")
End If
End Sub
Thank you!
Related
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 4 years ago.
Improve this question
I have this code
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Location1 As String
Dim city As Boolean
Dim sss As Boolean
If Not IsNumeric(TextBox1.Text) Then
MsgBox("Invalid ip address")
Else
city = True
sss = False
geoip()
If Label1.Text = "" Or Label1.Text = " " Then
city = False
Else
city = True
Location1 = Label1.Text
End If
If city = False And Label16.Text = "" Or Label16.Text = " " Then
Location1 = Label17.Text
Else
sss = True
End If
If sss = True Then
Location1 = Label16.Text
End If
End If
TextBox1.Text = ""
If CheckBox2.Checked = True Then
TextBox2.Text = "We look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
If CheckBox1.Checked = True Then
TextBox2.Text = "My name is " + TextBox3.Text + " from " + TextBox4.Text + " and im here for letting you know that we look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
TextBox1.Text = ""
End Sub
And it doesn't work as intended. It displays even when label1 is not "" or " " as label 16, I searched for the error in the code for so much time, but I think all is good
I now understand your question - I'm leaving my old answer since it is correct to bracket conditions and your code would still have broken, but your problem was that you have your If ... elses such that you fall into the else in places you wouldn't want to.
For example - Consider this line in your code:
If city = False And Label16.Text = "" Or Label16.Text = " " Then
Location1 = Label17.Text
Else
sss = True
End If
That else will be hit if city is true or if there's something in in label 16. You'd only want it to get there if city is still false and there's something in label 16....
Rather focus on doing your logic by nesting your conditional logic. This code should work as expected:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Location1 As String
Dim city As Boolean
Dim sss As Boolean
If Not IsNumeric(TextBox1.Text) Then
MsgBox("Invalid ip address")
Else
geoip()
If Label1.Text.Trim() = "" Then
city = False
If Label16.Text.Trim() = "" Then
Location1 = Label17.Text
Else
sss = True
Location1 = Label16.Text
End If
Else
city = True
Location1 = Label1.Text
End If
End If
TextBox1.Text = ""
If CheckBox2.Checked = True Then
TextBox2.Text = "We look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
If CheckBox1.Checked = True Then
TextBox2.Text = "My name is " + TextBox3.Text + " from " + TextBox4.Text + " and im here for letting you know that we look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
TextBox1.Text = ""
End Sub
I'm not understanding your question as stated, but am pretty sure your issue has to do with bracketing your clauses.
Your line If city = False And Label16.Text = "" Or Label16.Text = " " Then reads right to you, but isn't being understood correctly by the compiler... Always bracket complex logic statements to be safe.
Try and change this:
If city = False And Label16.Text = "" Or Label16.Text = " " Then
to this:
If city = False And (Label16.Text = "" Or Label16.Text = " ") Then
Or, please explain the problem a bit better...
I think you used the IsNumeric function won't work for a ip address. Try to split the ip and then check with IsNumeric.
I get an error saying "This date time literal was not understood" with this formula:
Private Sub btnOPrint_Click(sender As Object, e As EventArgs) Handles btnOPrint.Click
If MsgBox("Print Offertory Record?", MsgBoxStyle.OkCancel, "Print Record") = MsgBoxResult.Ok Then
Dim report As New ReportDocument
report.Load("C:\Users\Paolo\Documents\Visual Studio 2015\Projects\NewMonitoringSystem\NewMonitoringSystem\OffertoryReport.rpt")
docprint.CrystalReportViewer1.ReportSource = report
docprint.CrystalReportViewer1.SelectionFormula = "{tblOffertory.Date}=""" & dtpOffertory.Text & """ AND {tblOffertory.Weekly}=#" & txtOffertory.Text & "#"
docprint.CrystalReportViewer1.Refresh()
docprint.Show()
End If
End Sub
If I remove this line...
AND {tblOffertory.Weekly}=#" & txtOffertory.Text & "#"
...and instead use this line...
docprint.CrystalReportViewer1.SelectionFormula = "{tblOffertory.Date}=""" & dtpOffertory.Text & """"
...it shows the report with no data, just the columns. What formula should I use?
I'm trying to switch "M" to "Mr." and "F" to "Ms." when the last name is selected in the listbox. When I clicked on the first name it worked, but when I clicked on anyother name, I got this error message:
--Additional information: Index was outside the bounds of the array.--
The information in the text file is like this:
Ball,Krystal,F,1981
Banks,Robin,F,1988
Burgher,Hamilton,M,1980
Early,Brighton,M,1989
Hedd,MT,M,1960
Hogg,Ima,F,1953
Knapp,Anita,F,1970
Overnout,Roger,M,1968
Psito,Arnie,M,1962
Teak,Anne,F,1939
And my code is as follows:
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim names As IO.StreamReader = IO.File.OpenText("Info.txt")
Dim lName As String = lstNames.Text
Dim line As String
Dim gender As String
Dim foundFlag As Boolean = False
Do Until foundFlag Or names.EndOfStream
line = names.ReadLine
If line.Split(","c)(2) = "M" Then
gender = "Mr. "
ElseIf line.Split(","c)(2) = "F" Then
gender = "Ms. "
End If
If line.Split(","c)(0) = lName Then
txtOutput.Text = gender & line.Split(","c)(1) & " " & line.Split(","c)(0) & " is " & 2012 - line.Split(","c)(3)
foundFlag = True
End If
Loop
End Sub
Can someone please let me know what's wrong. Thanks in advance.
I re-created your application exactly as you have it here and it worked jsut fine.
That leads me to believe one of 2 things is happening:
You have bad characters in your Info.txt file
You haven't populated your lstNames combobox with the identical names to what you have in Info.txt.
PS - You might also want to look into your loop to make it more efficient:
Dim line() As String
Dim gender As String
Dim foundFlag As Boolean = False
Do Until foundFlag Or names.EndOfStream
line = names.ReadLine.Split(","c)
If line(0) = lName Then
If line(2) = "M" Then
gender = "Mr. "
ElseIf line(2) = "F" Then
gender = "Ms. "
End If
txtOutput.Text = gender & line(1) & " " & line(0) & " is " & 2012 - cint(line(3))
foundFlag = True
End If
Loop
I'm trying to switch "M" to "Mr." and "F" to "Ms." when the last name is selected in the listbox. When I clicked on the first name it worked, but when I clicked on anyother name, I got this error message:
--Additional information: Index was outside the bounds of the array.--
The information in the text file is like this:
Ball,Krystal,F,1981
Banks,Robin,F,1988
Burgher,Hamilton,M,1980
Early,Brighton,M,1989
Hedd,MT,M,1960
Hogg,Ima,F,1953
Knapp,Anita,F,1970
Overnout,Roger,M,1968
Psito,Arnie,M,1962
Teak,Anne,F,1939
And my code is as follows:
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim names As IO.StreamReader = IO.File.OpenText("Info.txt")
Dim lName As String = lstNames.Text
Dim line As String
Dim gender As String
Dim foundFlag As Boolean = False
Do Until foundFlag Or names.EndOfStream
line = names.ReadLine
If line.Split(","c)(2) = "M" Then
gender = "Mr. "
ElseIf line.Split(","c)(2) = "F" Then
gender = "Ms. "
End If
If line.Split(","c)(0) = lName Then
txtOutput.Text = gender & line.Split(","c)(1) & " " & line.Split(","c)(0) & " is " & 2012 - line.Split(","c)(3)
foundFlag = True
End If
Loop
End Sub
Can someone please let me know what's wrong. Thanks in advance.
I re-created your application exactly as you have it here and it worked jsut fine.
That leads me to believe one of 2 things is happening:
You have bad characters in your Info.txt file
You haven't populated your lstNames combobox with the identical names to what you have in Info.txt.
PS - You might also want to look into your loop to make it more efficient:
Dim line() As String
Dim gender As String
Dim foundFlag As Boolean = False
Do Until foundFlag Or names.EndOfStream
line = names.ReadLine.Split(","c)
If line(0) = lName Then
If line(2) = "M" Then
gender = "Mr. "
ElseIf line(2) = "F" Then
gender = "Ms. "
End If
txtOutput.Text = gender & line(1) & " " & line(0) & " is " & 2012 - cint(line(3))
foundFlag = True
End If
Loop
I have this code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim num As String
Dim message As String
Dim name As String
message = txtMessage.Text
Dim count As Integer = Me.TblContactsBindingSource.Count
If i < TblContactsDataGridView.Rows.Count - 1 Then 'stay within bounds
i = i + 1 ' for all rows except Row0
TblContactsDataGridView.Rows(i - 1).DefaultCellStyle.BackColor = Color.White ' restore previous highlight
TblContactsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.Bisque 'new highlight
num = Me.TblContactsDataGridView.Rows(i).Cells(1).Value.ToString()
name = Me.TblContactsDataGridView.Rows(i).Cells(0).Value.ToString()
If SerialPort1.IsOpen() Then
SerialPort1.Write("AT" & vbCrLf)
SerialPort1.Write("AT+CMGF=1" & vbCrLf)
SerialPort1.Write("AT+CMGS=" & Chr(34) & num & Chr(34) & vbCrLf)
SerialPort1.Write(message & Chr(26))
MessageBox.Show("Message has been successfully sent to " & vbNewLine & name & " (" & num & ") ", "Message Sent", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else 'next row is off the bottom so
'i = 0 'reset index
'TblSmsDataGridView.Rows(TblSmsDataGridView.Rows.Count - 1).DefaultCellStyle.BackColor = Color.White 'restore bottom row
'TblSmsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.Bisque 'highlight top row
End If
In a command button I have this:
Timer1.Interval = 2000
Timer1.Enabled = True 'no need to enable it and start it; one or t'other
What happen is, the message box appears over and over. How can i trigger message box to automatically close once it is finished? I commented the code in the "else" because the it repeats over and over.
You have to use a custom message box. Normal message box wont do the thing you wanted. It will pop up every 2 second. best choice is to make a new form and show it as a message box. :)
You need to set timer1.enabled = false in the timer1.tick handler.