Hello, First thank you for your time with helping me. I am trying to learn VB programming using Visual Basic 2005. My problem is this: I am trying to download a ASCII.txt file from a web site and populate a data base (Weather.mdb). I think I have a good connection to the webpage for extracting the file but I can not get the data to populate the database. What am I doing wrong or not doing?and How can I correct it? below is my code. Again Thank you for your time and assistance.
CODE
Dim x As Integer
Dim intcount As Integer
'Dim URL As String
Dim strURL As String = "http://weather.noaa.gov/data/nsd_cccc.txt"
'Dim MessageBox As String
Dim wr As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create("http://weather.noaa.gov/data/nsd_cccc.txt"), Net.HttpWebRequest)
Dim ws As Net.HttpWebResponse = CType(wr.GetResponse(), Net.HttpWebResponse)
Dim str As IO.Stream = ws.GetResponseStream()
Dim inBuf(540000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
GoTo Here
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While
Dim fstr As New IO.FileStream("C:\Data\Weather2.csv", IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
fstr.Write(inBuf, 0, bytesRead)
str.Close()
fstr.Close()
Here:
strURL = "nsd_cccc.txt"
Me.Refresh()
' set up variables as needed for Stream Reader
Dim objReader As IO.StreamReader
Dim myRecord As String
Dim myArray() As String
Dim _strFilePath As String
Dim db As New DBUpdt()
Dim dbaddRecord As DBUpdt()
Dim strSQL As String
_strFilePath = ("C:\Data\Weather2.csv")
If IO.File.Exists(_strFilePath) Then
' Open db connection
db.openDBConnection("C:\Data\Weather.MDB")
' clear the list box
lstLocations.Items.Clear()
objReader = IO.File.OpenText(_strFilePath)
Do While objReader.Peek <> -1
' Read the data fields
myRecord = objReader.ReadLine()
' Split it into an array
myArray = Split(myRecord, ";")
If myArray(5).ToString = "Greenland" Then
'Update database
'MessageBox.Show("Found One")
'strSQL = "SELECT * FROM Stations WHERE [" & strKeyName & "]=;" & strKeyContents & ";"
'query(strSQL)
'dbaddRecord()
End If
Loop
db.query(strSQL)
Do While db.moreRecords
Debug.WriteLine(db.getField("stationid"))
Loop
'' Separate array members into individual fields
'StationID.Text = Replace(myArray(0), Chr(34), "")
'StationName.Text = Replace(myArray(1), Chr(34), "")
'txtCity.Text = Replace(myArray(2), Chr(34), "")
'txtState.Text = Replace(myArray(3), Chr(34), "")
' Close the text file
objReader.Close()
End If
End Sub
Never mind I figured the down Load part out.
This post has been edited by pfales: 10 May, 2008 - 09:25 PM