I'm looking to extract only the line that starts "A SUNOT..." from this website. https://pilotweb.nas.faa.gov/common/nat.html
I then want to paste that line into a text box in VB2008.
I tried using:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TrackA As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://pilotweb.nas.faa.gov/common/nat.html")
Dim gather As System.Net.HttpWebResponse = TrackA.GetResponse
Dim write As System.IO.StreamReader = New System.IO.StreamReader(gather.GetResponseStream)
RawData.Text = write.ReadLine(?)
End Sub
End Class
I got it to write the entire page but I wanted just that line.
The '?' is to show if that ReadLine command is the right thing to be using there.
Thanks, James
Try the following code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TrackA As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://pilotweb.nas.faa.gov/common/nat.html")
Dim gather As System.Net.HttpWebResponse = TrackA.GetResponse
Dim write As System.IO.StreamReader = New System.IO.StreamReader(gather.GetResponseStream)
Dim ContentStr As String = write.ReadToEnd
Dim StartIndex As Integer = ContentStr.IndexOf("A SUNOT")
Dim StrLength As Integer = ContentStr.IndexOf(vbLf, StartIndex) - StartIndex
RawData.Text = ContentStr.Substring(StartIndex, StrLength)
End Sub
Related
I am trying to pass the selected nodes from a treeview to another form that is displayed in the text boxes.
this is my code in TreeView1_NodeMouseDoubleClick event
the code works fine when the data from the selected treeview is shown in the same form, but the problem is when I want to pass it to the other form 4 nothing is shown and the debug shows me that if it receives the values but they are not reflected, maybe my code to refer to the other form is wrong I would like a support with this case.
Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
Dim nodeKey As String = TryCast(e.Node.Tag, String)
Dim form4 As New Form4
' Dim nodetext As String = TryCast(e.Node.Tag, String)
'Dim nodeKey As String = DirectCast(e.Node.Tag, String)
If nodeKey IsNot Nothing AndAlso nodeKey.StartsWith("DIST") Then
'You have double clicked a district node
Dim IDDISTRITO As Integer = Integer.Parse(nodeKey.Substring(4))
form4.lblco.Text = IDDISTRITO
'Do something with the district id here
'...
form4.txtdis.Text = e.Node.Text
form4.txtpro.Text = e.Node.Parent.Text
form4.txtdepa.Text = e.Node.Parent.Parent.Text
End If
End Sub
so I call form 3 where is the treeview
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim for3 As New Form3
for3.Show()
End Sub
As you assumed, yes you are referencing the forms incorrectly. Please follow this technique. In form3 class, declare a public variable Public Dim form4 As New Form4.
Then modify the form3 calling procedure like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim for3 As New Form3
for3.form4 = Me
for3.Show()
End Sub
Now modify your existing code to this :
Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
Dim nodeKey As String = TryCast(e.Node.Tag, String)
' Dim nodetext As String = TryCast(e.Node.Tag, String)
'Dim nodeKey As String = DirectCast(e.Node.Tag, String)
If nodeKey IsNot Nothing AndAlso nodeKey.StartsWith("DIST") Then
'You have double clicked a district node
Dim IDDISTRITO As Integer = Integer.Parse(nodeKey.Substring(4))
form4.lblco.Text = IDDISTRITO
'Do something with the district id here
'...
form4.txtdis.Text = e.Node.Text
form4.txtpro.Text = e.Node.Parent.Text
form4.txtdepa.Text = e.Node.Parent.Parent.Text
End If
End Sub
I have not tested the above code, but I believe you have got the idea.
Well I managed to solve it, the simplest thing was complicated, I publish the solution.
form 4 by calling 3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim for3 As New Form3
AddOwnedForm(for3)
for3.ShowDialog()
End Sub
just add this code and voila
Dim form4 As Form4 = CType(Owner, Form4)
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 6 years ago.
Improve this question
This is my code so far. My professor said I can not hard code. Can you please help me with the loop under the button click event. Right the flash form will load and pull up the first term and definition in the text files but when you click the next button it shows the path of the file that has been read in.
Public Class frmFlash
Private _intSizeOfArray As Integer = 3
Private _strLocationOfTerms(_intSizeOfArray) As String
Private _strLocationOfDefinitions(_intSizeOfArray) As String
Private _objReader As IO.StreamReader
Private _strTerms As String
Private Sub frmFlash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objReader As IO.StreamReader
Dim strLocationOfTerms As String = "C:\Users\boone\Desktop\Terms.txt"
Dim strLocationOfDefinitions As String = "C:\Users\boone\Desktop\Definitions.txt"
Dim intTermArray(4) As Integer
Dim intCount As Integer
lblDefinition.Visible = False
If IO.File.Exists(strLocationOfTerms) Then
objReader = IO.File.OpenText(strLocationOfTerms)
_strTerms = objReader.ReadLine()
lblTerm.Text = _strTerms
End If
If IO.File.Exists(strLocationOfDefinitions) Then
objReader = IO.File.OpenText(strLocationOfDefinitions)
strLocationOfDefinitions = objReader.ReadLine()
objReader.Close()
lblDefinition.Text = strLocationOfDefinitions
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim objReader(_intSizeOfArray) As IO.StreamReader
Dim intCount As Integer = 0
Dim strTermArray As String
Dim strLocationOfTerms As String = "C:\Users\boone\Desktop\Terms.txt"
Dim strLocationOfDefinitions As String = "C:\Users\boone\Desktop\Definitions.txt"
Do While intCount <= _intSizeOfArray
lblTerm.Text = strLocationOfTerms(_strTerms)
lblDefinition.Text = strLocationOfDefinitions
intCount += 1
Loop
End Sub
Private Sub btnDefinition_Click(sender As Object, e As EventArgs) Handles btnDefinition.Click
lblDefinition.Visible = True
End Sub
End Class
Since you are working with arrays, the easiest way to do this is to skip the processing in the button handler entirely. Load up your arrays in the Load event and just grab an IEnumerator for them.
'In Class level declarations
Private _termsEnumerator As IEnumerator(Of String)
Private _defsEnumerator As IEnumerator(Of String)
Private Sub frmFlash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Your other initialization code...
'...
'Load your _strLocationOfTerms and _strLocationOfTerms here.
_termsEnumerator = _strLocationOfTerms.GetEnumerator()
_defsEnumerator = _strLocationOfDefinitions.GetEnumerator()
End Sub
Then it's just as simple as grabbing the next item from the arrays (they implement IEnumerable):
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If _termsEnumerator.MoveNext() And _defsEnumerator.MoveNext() Then
lblTerm.Text = _termsEnumerator.Current
lblDefinition.Text = _defsEnumerator.Current
End If
End Sub
My code should be showing 32 characters but it's only showing 7. This is the code I currently have:
Imports System.IO
Public Class Form1
Private Property sr As Object
Private Sub BrowseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseBtn.Click
OpenFileDialog.ShowDialog()
FilePathLabel.Text = OpenFileDialog.FileName
End Sub
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
Dim sr As StreamReader = New StreamReader(OpenFileDialog.FileName)
Dim data = sr.ReadToEnd()
Dim pos = data.IndexOfAny("LASTSAVE")
If pos >= 0 Then
End If
CatiaVersionLabel.Text = data.Substring(pos, 32)
End Sub
End Class
Not too sure why it's doing this as the text that needs to be found is there when I open it independently.
I was trying to display data from file in a list saved on the hard drive by clicking on a button, however I'm not sure on haw to do it properly:
Private Sub btnListRecipes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListRecipes.Click
Dim TextLine As String
If System.IO.File.Exists(Filename) = True Then
Dim RecipeReader As New System.IO.StreamReader(Filename)
Do While RecipeReader.Peek() <> -1
TextLine = TextLine & RecipeReader.ReadLine() & vbNewLine
Loop
lstRecipes.Text = TextLine.Text
Else
MsgBox("File Does Not Exist")
End If
End Sub
I would be really grateful for assistance :D
Private Sub btnListRecipes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListRecipes.Click
Try
lstRecipes.AddRange(File.ReadAllLines(FileName))
Catch
MsgBox("Unable to read file")
End Try
End Sub
Use:
lstRecipes.Items.Add(TextLine.Text)
More specifically before it jumps to the next item in the list, so this would go right after your assignment of TextLine.
you can do this:
Imports System
Imports System.IO
Public Class Form1
Public Shared listTXT, listOfTxt, listOfTxtFile As New List(Of String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\myDirectory\"
Dim parentinfo As New DirectoryInfo(path)
' Store Text file name in a list
For Each txtFile As FileSystemInfo In parentinfo.GetFileSystemInfos()
listTXT.Add(txtFile.Name)
Next
' Store Path of Text file in a list
For noOfTxtFile = 0 To listTXT.Count - 1
Dim pathOfFile As String = path & listTXT(noOfTxtFile)
listOfTxtFile.Add(pathOfFile)
Dim obj As System.IO.StreamReader
obj = System.IO.File.OpenText(pathOfFile)
While Not obj.EndOfStream
listOfTxt.Add(obj.ReadLine)
End While
Next
Dim lineOfTxt As Integer
Dim txt As String
For lineOfTxt = 0 To listOfTxt.Count - 1
txt = listOfTxt(lineOfTxt)
ListBox1.Items.Add(txt)
Next
End Sub
End Class
It works perfectly in debug mode but it gives me 'The process cannot access the file because it is being used by another process' unhandled exception error when I run the built one and press the Save button(It loads but not saves after that).
Any advice, please.
Imports System.IO
Public Class DL1
Function DirExists(ByVal DirName As String) As Boolean
On Error GoTo ErrorHandler
DirExists = GetAttr(DirName) And vbDirectory
ErrorHandler:
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub LoadGlink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadGlink.Click
GlinkList.Items.Clear()
Dim fileReader As System.IO.StreamReader
fileReader = _
My.Computer.FileSystem.OpenTextFileReader("c:\Source\DL1\Glink.txt")
Dim mystring() As String = fileReader.ReadToEnd.Split(vbNewLine)
GlinkList.Items.AddRange(mystring)
fileReader.Close()
Me.Controls("Glinklist").Focus()
End Sub
Private Sub linktochrome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles linktochrome.Click
If GlinkList.SelectedItem IsNot Nothing Then
' selected item is sglink
Dim sglink = GlinkList.SelectedItem.ToString
Process.Start("C:\Users\1\AppData\Local\Google\Chrome\Application\chrome.exe", sglink)
End If
Me.Controls("Glinklist").Focus()
End Sub
Private Sub movetofol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movetofol.Click
Dim strDir As String
strDir = "C:\Users\1\Downloads\Glink\" & "\" & SFoltext.Text
If DirExists(Trim(strDir)) = False Then
MkDir(Trim(strDir))
End If
For Each f As String In Sresult1.Items
Dim f_name As String = Path.GetFileName(f)
My.Computer.FileSystem.MoveFile(f, strDir & "\" & f_name)
Next
Sresult1.Items.Clear()
GlinkList.Items.Remove(GlinkList.SelectedItem)
End Sub
Private Sub ChecKDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChecKDL.Click
Sresult1.Items.Clear()
Dim fileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
fileList = My.Computer.FileSystem.GetFiles("C:\Users\1\Downloads\")
For Each foundFile As String In fileList
Sresult1.Items.Add(foundFile)
Next
End Sub
Private Sub Bsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsave.Click
Dim i As Integer
'Saves Glinklist
Dim path As String = System.IO.Path.Combine("c:\Source\DL1\", "Glink.txt")
Using fs As New System.IO.FileStream(path, IO.FileMode.Create)
Using w As IO.StreamWriter = New IO.StreamWriter(fs)
For i = 0 To GlinkList.Items.Count - 1
w.WriteLine(GlinkList.Items.Item(i))
Next
w.Close()
End Using
End Using
End Sub
Private Sub RMselec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RMselec.Click
GlinkList.Items.Remove(GlinkList.SelectedItem)
Me.Controls("Glinklist").Focus()
End Sub
End Class
Not sure it this could be the answer, but I will post here because I can better format the code.
Let me know if this changes anything
Change your reading function to
Using fileReader = _
My.Computer.FileSystem.OpenTextFileReader("c:\Source\DL1\Glink.txt")
Dim mystring() = fileReader.ReadToEnd.Split(vbNewLine)
GlinkList.Items.AddRange(mystring)
End Using
Or simply
Dim mystring() = File.ReadAllLines()
GlinkList.Items.AddRange(mystring)
Usually this means a permission issue. Try running Visual Studio as admin to eliminate that possibility.