hello guys... im having trouble to open up the 2 files , i tried so many times , but i can't think what's the right directory should i put at the '??????' .... the purpose is to pass the value of directory so it can read and open up 2 of the file that i want to open .... i do hope you could understand me and hopefully you can help me.... pls .....

Option Explicit

Private Sub CmdChkFile_Click()

Dim FileName As String
Dim a As String, b As String
Dim fs As FileSystemObject
Dim ts As TextStream, ts1 As TextStream
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile("???????", ForReading)
Set ts1 = fs.OpenTextFile("??????", ForReading)
txtdata(0).Text = rtndirectory(Trim(CommonDialog1.FileName))
txtdata(1).Text = rtndirectory(Trim(CommonDialog1.FileName))

If txtdata(0).Text = "" Then Exit Sub
If txtdata(1).Text = "" Then Exit Sub


Do While Not ts.AtEndOfStream
a = ts.ReadLine
b = ts1.ReadLine
Loop

Debug.Print


End Sub

Private Sub cmdFileFmt_Click()

On Error GoTo err

CommonDialog1.Filter = ".hdr"
CommonDialog1.InitDir = App.Path & "\BatchFile"
CommonDialog1.FileName = "Header"
CommonDialog1.ShowOpen

If Trim(CommonDialog1.FileName) = "" Then Exit Sub

txtdata(1).Text = rtndirectory(Trim(CommonDialog1.FileName))

Exit Sub
err:
MsgBox err.Description, vbCritical, "Error lines " + err.Number


End Sub


Private Sub Cmdsource_Click()
On Error GoTo err

CommonDialog1.Filter = ".Dat"
CommonDialog1.InitDir = App.Path & "\BatchFile"
CommonDialog1.FileName = "DAT"
CommonDialog1.ShowOpen

If Trim(CommonDialog1.FileName) = "" Then Exit Sub

txtdata(0).Text = rtndirectory(Trim(CommonDialog1.FileName))

Exit Sub
err:
MsgBox err.Description, vbCritical, "Error lines " + err.Number

End Sub

Public Function rtndirectory(vdirectory As String) As String
Dim vtxt As Integer
vtxt = InStr(vdirectory, "\\")
Do While Not vtxt = 0
vdirectory = Mid(vdirectory, 1, vtxt) & Right(vdirectory, Len(vdirectory) - (vtxt + 1))
vtxt = InStr(vdirectory, "\\")
Loop
rtndirectory = vdirectory
End Function

Hi,

I have modified ur code. Check this:

Option Explicit
Dim HdrFName as String
Dim DatFName As String

Private Sub CmdChkFile_Click()

If Trim(DatFName) ="" Then Exit Sub
If Trim(HdrFName) ="" Then Exit Sub

Dim FileName As String
Dim a As String, b As String
Dim fs As FileSystemObject
Dim ts As TextStream, ts1 As TextStream
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(HdrFName, ForReading)
Set ts1 = fs.OpenTextFile(DatFName, ForReading)
txtdata(0).Text = rtndirectory(Trim(CommonDialog1.FileName))
txtdata(1).Text = rtndirectory(Trim(CommonDialog1.FileName))

If txtdata(0).Text = "" Then Exit Sub
If txtdata(1).Text = "" Then Exit Sub


Do While Not ts.AtEndOfStream
a = ts.ReadLine
b = ts1.ReadLine
Loop

Debug.Print


End Sub

Private Sub cmdFileFmt_Click()

On Error GoTo err

CommonDialog1.Filter = ".hdr"
CommonDialog1.InitDir = App.Path & "\BatchFile"
CommonDialog1.FileName = "Header"
CommonDialog1.ShowOpen

If Trim(CommonDialog1.FileName) = "" Then Exit Sub

HdrFName = CommonDialog1.FileName

Exit Sub
err:
MsgBox err.Description, vbCritical, "Error lines " + err.Number


End Sub


Private Sub Cmdsource_Click()
On Error GoTo err

CommonDialog1.Filter = ".Dat"
CommonDialog1.InitDir = App.Path & "\BatchFile"
CommonDialog1.FileName = "DAT"
CommonDialog1.ShowOpen

If Trim(CommonDialog1.FileName) = "" Then Exit Sub

DatFName = CommonDialog1.FileName

Exit Sub
err:
MsgBox err.Description, vbCritical, "Error lines " + err.Number

End Sub

Public Function rtndirectory(vdirectory As String) As String
Dim vtxt As Integer
vtxt = InStr(vdirectory, "\\")
Do While Not vtxt = 0
vdirectory = Mid(vdirectory, 1, vtxt) & Right(vdirectory, Len(vdirectory) - (vtxt + 1))
vtxt = InStr(vdirectory, "\\")
Loop
rtndirectory = vdirectory
End Function

Regards
Veena

veena thank you ...... millions of thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.