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 8 years ago.
Improve this question
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reader As StreamReader = My.Computer.FileSystem.OpenTextFileReader(TextBox1.Text)
Dim a As String
a = reader.ReadLine
RichTextBox1.Text = RichTextBox1.Text + a
Label5.Text = RichTextBox1.Text.Substring(5, a.Substring(5, a.Length))
reader.Close()
End Sub
Hello. I am trying to read a text file and put the numbers in different variables. The textfile is like this
IMAGE
Every time i run the code it comes out with an error. What should i do?
What is it that you're trying to do with this line?
Label5.Text = RichTextBox1.Text.Substring(5, a.Substring(5, a.Length))
This part: a.Substring(5, a.Length) returns a string, but the second argument of Substring expects an integer, so it is causing an error.
Substring looks like this: Substring(startIndex As Integer, length As Integer). You are trying to pass a string into the second argument.
Simply dropping the second argument from that line seems that it would do what you want it to:
Label5.Text = RichTextBox1.Text.Substring(5)
If these types of problems are frequently affecting you, I highly suggest you turn Option Strict on in Visual Studio. Here are some instructions on how to do so.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
i have a button when clicked, a document will open...
Private Sub btnPrintDTR_Click(sender As Object, e As EventArgs) Handles btnPrintDTR.Click
'function/sub to call
End Sub
in the "function to call", i want this Sub DefineTables(ByVal document As Document)
to be called.
i was able to call Function SearchRecord() As DataTable on button click using this code
DataGridView1.DataSource = SearchRecord()
i wanted a similar call but i could not figure out how to.
anyone have any idea on this?
I was interested to learn that you are system developer. One of the first things my husband would do when interviewing was to ask about items on the applicants resume.
I have no idea what type of Document your code refers to.
Private Sub btnPrintDTR_Click(sender As Object, e As EventArgs) Handles btnPrintDTR.Click
Dim doc As New Document
DefineTables(doc)
End Sub
oh now i get it...
by observing lots of functions...
Private Sub btnPrintDTR_Click(sender As Object, e As EventArgs) Handles btnPrintDTR.Click
DefineTables(document)
End Sub
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
[so i put the string like "hello world" and want to change "l" to "a" then i need to count the no. of changed letters how do i count the change letters only? help pls[1]: https://i.stack.imgur.com/Wu1PF.jpg
a possible solution would be computing the length difference between the input string and the same one with find string substituted with "":
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
newStringTB.Text = inputTB.Text.Replace(findTB.Text, replaceTB.Text)
noOfReplacedTB.Text = Len(inputTB.Text) - Len(Replace(inputTB.Text, findTB.Text, ""))
End Sub
just change:
"Button1" to your actual command button name
"newStringTB", "findTB", "replaceTB" and "noOfReplacedTB" to your actual textboxes names
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 8 years ago.
Improve this question
I have a listbox with a list of items and I want to give them actions when clicked, unfortunately when I try to double click the listbox, the action is applied to the whole listbox and I'm not being able to find tips anywhere on how to give an action to each item on a listbox.
In this case I want a click on an item on the listbox to display a youtube video on webbroswer1
So I've been asked to be less vague...I want to get each ITEM on a Listbox to navigate to a different webbrowser page. I have no more code than the one posted below...
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim curItem As String = ListBox1.SelectedItem.ToString()
WebBrowser1.Navigate("http://www.youtube.com/embed/ECIupNr8U-o")
Someone able to help?
Regards
If each item is a valid address then:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If Not Listbox1.SelectedIndex = -1 Then
WebBrowser1.Navigate(ListBox1.SelectedItem.ToString())
End If
End Sub
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 8 years ago.
Improve this question
when i click the "browse" button I need to browse for a txt/xml file and place the data of that file in the text box.So for this I tried with a code but I was not successful.So can you help me with the vb.net code for this
If think that the problem is in your if statement. Here is an example of what you can do:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists("Your Path") = True Then
TextBox1.Text = My.Computer.FileSystem.ReadAllText("Your Path")
Else
MsgBox("ERROR - File Not Found")
End If
End Sub
End Class
Notice the change I did in the If Statement. Hoped it helped.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a TextBox and Button.
I want it when the user types in TextBox, for example, "stackoverflow", a MessageBox will show saying:
Please complete the URL - and if the user type's "stackoverflow.com"
The program then continues and takes them onto that website. However, if the URL does not contain an extension such as (.co.uk, .com, .org etc), the program does not continue onto the website.
Whenever you can, use something already available in .NET
Dim address As String = "StackOverflow"
Dim uri As System.Uri
If System.Uri.TryCreate(address, UriKind.RelativeOrAbsolute, uri) Then
' if you get here, it's a real url
Else
' if you get here, it's not
End If
This should be able to validate all website urls and prompt the user to enter a website url in the correct format.
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
ValidatewebsiteAddress(Me.TextBox1.Text)
End Sub
Private Sub ValidatewebsiteAddress(ByVal _websiteAddress As String)
If Not Regex.IsMatch(_websiteAddress, _
"^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+#)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?") Then
MessageBox.Show("Please complete url")
Else
MessageBox.Show("Thanks a lot")
End If
End Sub