I have a text file that need to be read to database. now i can read the text file to database. But my problem is the text file will be in the specific folder. so i must get the folder first then read the text file. it is a automatic process when i run the program it will read the text file to database. this is my code so far:
Code:
Dim blnConnect As Boolean
Const BIF_RETURNONLYFSDIRS = &H1 'Only file system directories
Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "KERNEL32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
'Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Dim FN As Long
Private name1 As String
Private MyPath As String
Dim strFileName As String
Dim strLogPath As String
Dim strField() As String
Dim intFileNum As Double
Dim f_year As String
Dim f_day As String
Dim f_day_month As String
Dim new_date As String
Private Sub cmdImport_Click()
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim Data(11) As String
Dim Fields As Integer
Dim InFile As Integer
Dim InLine As String
InFile = FreeFile
Open App.Path & "\X65_Rectifier_UK_100110_Cav1.txt" For Input As #InFile
If Not EOF(InFile) Then
Line Input #InFile, InLine
End If
While Not EOF(InFile)
Line Input #InFile, InLine
Data(0) = Mid(InLine, 1, 10)
Data(1) = Mid(InLine, 26, 9)
Data(2) = Mid(InLine, 51, 10)
Data(3) = Mid(InLine, 76, 8)
Data(4) = Mid(InLine, 101, 12)
Data(5) = Mid(InLine, 126, 17)
Data(6) = Mid(InLine, 151, 23)
Data(7) = Mid(InLine, 176, 20)
Data(8) = Mid(InLine, 201, 21)
Data(9) = Mid(InLine, 226, 23)
Data(10) = Mid(InLine, 251, 20)
Data(11) = Mid(InLine, 276, 6)
Fields = UBound(Data())
strSQL = "Insert into tb_X65 (date_test,time_test,test_time,varient,serial_no,pre_power_up,input_current_rms,output_voltage,load_off_current,discharge_voltage,discharge_time,status) " & _
"VALUES ('" & Format(Data(0), "m/d/yyyy") & "', " & _
"'" & Format(Data(1), "hh:mm") & "', " & _
"'" & Data(2) & "', " & _
"'" & Data(3) & "', " & _
"'" & Data(4) & "', " & _
"'" & Data(5) & "', " & _
"'" & Data(6) & "', " & _
"'" & Data(7) & "', " & _
"'" & Data(8) & "', " & _
"'" & Data(9) & "', " & _
"'" & Data(10) & "', " & _
"' " & Data(11) & "')"
my_db1.Execute strSQL
Wend
Close #InFile
end sub
Private Sub Form_Load()
Call DatabaseConn2
today_date = Format(Now, "ddMMyyyy")
Call Timer1_Timer
end sub
Private Sub Timer1_Timer()
cmdImport_Click
End Sub
Module1
Public my_db1 As New ADODB.Connection
Public Sub DatabaseConn2()
Set my_db1 = New ADODB.Connection
my_db1.ConnectionString = "driver={SQL Server};" & _
"server=MISXPP16;uid=;pwd=;database=master"
my_db1.CursorLocation = adUseClient
my_db1.ConnectionTimeout = 0
my_db1.CommandTimeout = 0
my_db1.Open
End Sub
I keep the folder path in config.ini file. Now i want to call the path in form loading. something like this
InFile = FreeFile
'Open App.Path & "\config.ini" For Input As InFile
'If Not EOF(InFile) Then
' Line Input #InFile, InLine
' End If
but im not sure about this can any one help me? i attach my text file
In side config.ini file will be like this:C:\X65_Rectifier_Test_Software
Last edited by HanneSThEGreaT; February 19th, 2010 at 01:35 AM.
Reason: Code Tags!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.