I use Fileystemwatcher to watch a certain folder on our network share and wan't to count the lines in a textbox.
I have 2 richtextboxes, the first one will display the line number and the second one displays the change/deleted/renamed file.
I am able to display the total of lines in a label, but also want to show the line numbers in a richtextbox, but the problem is that it adds the number to the current, it needs to add the number on a new line.
Hopefully the image will explain.
Private Sub textFolderActiviteit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textFolderActiviteit.TextChanged
textFolderActiviteit.SelectionStart = textFolderActiviteit.Text.Length
textFolderActiviteit.SelectionLength = 0
textFolderActiviteit.ScrollToCaret()
textFolderActiviteit.Focus()
Dim currentLineIndex As Integer = textFolderActiviteit.GetLineFromCharIndex(textFolderActiviteit.SelectionStart)
Me.Label2.Text = String.Format("{0}", currentLineIndex + 1)
Me.textLineCount.Text = String.Format("{0}", currentLineIndex + 1 & vbCrLf)
End Sub
Private Sub textLineCount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textLineCount.TextChanged
textLineCount.SelectionStart = textLineCount.Text.Length
textLineCount.SelectionLength = 0
textLineCount.ScrollToCaret()
textLineCount.Focus()
End Sub
Maybe I'm misunderstanding the question, but couldn't you just put the VbCrlf before the line number?
Me.textLineCount.Text = String.Format("{0}", vbCrLf & (currentLineIndex + 1).ToString())
Related
Complete noob to vb.net (and programming in general) here, all I really want is every time I click a button, the number in the textbox is added by 1 but the new number shows up on the next line. Tried to google this a hundred times but nothing really helped.
I don't want to use loops as I don't want all numbers to show up at once, only for the added number to show up after clicking a specific button (on a new line).
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim txtoutput As String = ""
Dim a As Integer = 1
txtoutput &= "the value of a =" & a & Environment.NewLine
a = a + 1
TextBox1.Text = txtoutput
End Sub
You are replacing the Text, you want to append a new line, so you need to do:
Private a As Int32 = 0
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
a += 1
Dim newLine = $"the value of a = {a}"
TextBox1.Text = TextBox1.Text & Environment.NewLine & newLine
End Sub
You also have to use a field and not a local variable if you want to retain the old value and increment it. Otherwise it is reset always to it's inital value.
Please try to change dim a to static a
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim txtoutput As String = ""
Static a As Integer = 1
txtoutput &= "the value of a =" & a & Environment.NewLine
a = a + 1
TextBox1.Text = txtoutput
End Sub
For example i got two barcode, so i scan the two barcode at the textbox, it appear AVM12323AVM44454..
But I want it to be displayed in textbox for example like AVM12323, AVM44454. where there is a "," comma between the two code.
Previously i'm only tested for scan one barcode only in the textbox. So now i'm trying to scan more than one barcode in one textbox.
i have been looking the few example but not success.
Private Sub TextBoxMulti_TextChanged(sender As Object, e As EventArgs) Handles TextBoxMulti.TextChanged
Dim selectedMultiArrayScan As String()
Dim selectedMultiScan As String = ""
selectedMultiScan = TextBoxMulti.Text & ","
selectedMultiArrayScan = selectedMultiScan.Split(",")
End Sub
Private Sub MultiScan_Click(sender As Object, e As EventArgs) Handles MultiScan.Click
For Each stateName As String In selectedMultiArrayScan
//some query for each scanned item
Next stateName
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False ' Fire only once
If TextBox1.Text.Trim <> "" Then TextBox1.Text += ", "
End Sub
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
Timer1.Enabled = True
End Sub
Read the textbox with the event TextChanged like this:
If TextBox1.Text.Length >3 Then
Dim txt As String = Label1.Text + ", " + TextBox1.Text
If txt.Length = 6 Then txt = txt.Remove(0, 2)
Label1.Text = txt
'if you want to erase the text in TextBox1
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = Label1.Text.Length
Try
End If
I use this code and it show the Barcodes in a label, you can replace the label to show in the textBox. Also, my Barcodes lenght always have 4 Alphanumeric characters. For you, Replace the If TextBox1.Text.Length >3 Then (3 to 8) to detect where a Barcode is readed.
I trying to make program in visual basic in Text Changed event that when enter value the text box the program will store that value and when delete that value and enter new value it will use the first value and Compares with the new value if the new value > from the first value Decreases the new value from the first value (new value-first value) and if the new value < from the first value it will Decreases the first value from new value (first value - new value) and the The result another text box
Dim f As String
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text > f Then
TextBox18.Text = TextBox2.Text - f
f = (TextBox2.Text)
End If
I make this code it work but when the new value is (10) or Larger its not working
Try the following:
Dim f As String
Private Sub TextBox2_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Leave
If not string.isnullOrEmpty(TextBox2.Text) Then
If CDbl(TextBox2.Text) > CDbl(f) Then
TextBox18.Text = CStr(CDbl(TextBox2.Text) - CDbl(f))
f = TextBox2.Text
End If
End If
End Sub
I was wondering if you could help me? My question is that, is there a way of changing the value in my.Settings in a form if you enter a number/decimal in a textbox and click a button and then update in the settings to be then changed in another from which is linked to my.Settings in a variable?!
Form 1:
Public Class frmConverter
Dim input As String
Dim result As Decimal
Dim EUR_Rate As Decimal = My.Settings.EUR_Rates
Dim USD_Rate As Decimal = 1.6
Dim JYP_Rate As Decimal = 179.65
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
input = txtInput.Text
Try
If ComboBox1.Text = "£" Then
Pounds()
ElseIf ComboBox1.Text = "€" Then
Euros()
ElseIf ComboBox1.Text = "$" Then
Dollars()
ElseIf ComboBox1.Text = "¥" Then
Yen()
End If
Catch es As Exception
MsgBox("Error!")
End Try
End Sub
Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
Me.Hide()
frmExchange.Show()
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtInput.Text = ""
lblResult.Text = ""
End Sub
Function Pounds()
If ComboBox1.Text = "£" And ComboBox2.Text = "€" Then
result = (input * EUR_Rate)
lblResult.Text = FormatNumber(result, 2) & " " & ComboBox2.Text
ElseIf ComboBox1.Text = "£" And ComboBox2.Text = "$" Then
result = (input * USD_Rate)
lblResult.Text = FormatNumber(result, 2) & " " & ComboBox2.Text
ElseIf ComboBox1.Text = "£" And ComboBox2.Text = "¥" Then
result = (input * JYP_Rate)
lblResult.Text = FormatNumber(result, 2) & " " & ComboBox2.Text
End If
Return 0
End Function
Form 2:
Public Class frmExchange
Private Sub frmExchange_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Settings.EUR_Rates = (txtinput.Text)
My.Settings.Save()
My.Settings.Reload()
End Sub
Public Sub SetNewRate(ByVal rate As Decimal)
txtinput.Text = rate.ToString
End Sub
Private Sub btnchange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnchange.Click
If ComboBox1.Text = "€" Then
My.Settings.USD_Rates = (txtinput.Text)
frmConverter.SetNewRate(txtinput.Text)
End If
End Sub
End class
It sounds like you are trying to use My.Settings as some sort of set of global reference variables. Thats not what they are for, not how they work and not what they are.
First, turn on Option Strict as it looks like it may be Off. This will store the decimal value of a textbox to a Settings variable which is defined as a Decimal:
My.Settings.USD_Rates = CDec(SomeTextBox.Text)
Thats all it will do. It wont save the value and it wont pass it around or share it with other forms and variables.
My.Settings.Save 'saves current settings to disk for next time
My.Settings.Reload 'Load settings from last time
This is all covered on MSDN. There is no linkage anywhere. If you have code in another form like this:
txtRate.Text = My.Settings.USD_Rates.ToString
txtRate will not automatically update when you post a new value to Settings. There are just values not Objects (see Value Types and Reference Types). To pass the new value to another form:
' in other form:
Public Sub SetNewRate(rate As Decimal)
' use the new value:
soemTextBox.Text = rate.ToString
End Sub
in form which gets the change:
Private Sub btnchangeRate(....
' save to settings which has nothing to do with passing the data
My.Settings.USD_Rates = CDec(RateTextBox.Text)
otherForm.SetNewRate(CDec(RateTextBox.Text))
End Sub
You may run into problems if you are using the default form instance, but that is a different problem.
You botched the instructions. The 2 procedures are supposed to go in 2 different forms - one to SEND the new value, one to RECEIVE the new value. With the edit and more complete picture, there is an easier way.
Private Sub btnSettings_Click(...) Handles btnSettings.Click
' rather than EMULATE a dialog, lets DO a dialog:
'Me.Hide()
'frmExchange.Show()
Using frm As New frmExchange ' the proper way to use a form
frm.ShowDialog
' Im guessing 'result' is the xchg rate var
result = CDec(frm.txtInput.Text)
End Using ' dispose of form, release resources
End Sub
In the other form
Private Sub btnchange_Click(....)
' do the normal stuff with Settings, if needed then:
Me.Hide
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FirstNumber = TextBox1.Text
SecondNumber = TextBox2.Text
Message = "The results are as follows:" & vbNewLine
Message = Message & "Addition:" & FirstNumber + SecondNumber
Label3.Text = Message
End Sub
I am using the code above in a program where I have declared Message As String. But why is it that on the second line the text "The results are as follows" doesn't appear even though I have included Message as part of the line?
Maybe because your label isn't high enough to show two lines of text. Increase Label3.Height and it will be fixed.
Label3.Height = 30 ' 30 is an example of course