A
amazonmike
Guest
This module is called "modConvertUnixToWindows". Could someone take a look the code and see if you can spot a flaw? (I don't know VB well yet). I picked up this project from someone else, and it looks to me like she didn't finish modifying this module for our database. After the text is converted, it won't import properly into my table. I can't figire out why, and I'm wondering if one of these fuctions is to blame.
I would also like the message box and "successfully created" message to appear, but they don't, and they seem to be commented out in this example. How might I get it to work? Any feedback would be greatly appreciated. Thank you for your time.
Function TestImportText(ImportTextFile As String)
Dim ImportTextFilePath As String
Dim x As String, y As String
Dim NumberOfCarriageReturns As Long
Dim NumberOfLineFeeds As Long
NumberOfCarriageReturns = 0
NumberOfLineFeeds = 0
ImportTextFilePath = ("\\dummyFile\****\****\******\*******\********\*****\******." & ImportTextFile)
Open ImportTextFilePath For Input As #1
Do Until EOF(1)
Line Input #1, x
If InStr(1, x, Chr(13)) > 0 Then
NumberOfCarriageReturns = NumberOfCarriageReturns + 1
End If
If InStr(1, x, Chr(10)) > 0 Then
NumberOfLineFeeds = NumberOfLineFeeds + 1
End If
Loop
Close #1
'If no Carriage returns found, run the next function to modify
'the text file.
If NumberOfCarriageReturns < NumberOfLineFeeds And NumberOfLineFeeds > 0 Then
Dim NameOfNewText As String
NameOfNewText = ("\\DummyFile***\****\****\***********\****Files\" & ImportTextFile & ".txt")
y = ImportText(ImportTextFilePath, NameOfNewText)
End If
End Function
Function ImportText(OldText As String, NewText As String)
Dim x As String, Endvalue As Integer
Dim StartValue As Integer, OutputTxt As String
Open OldText For Input As #1
Open NewText For Output As #2
Do Until EOF(1)
Line Input #1, x
Endvalue = InStr(1, x, Chr(10))
StartValue = 1
Do Until Endvalue = 0
If Endvalue > 0 Then
OutputTxt = Mid(x, 1, (Endvalue - 1))
Print #2, OutputTxt
StartValue = Endvalue + 1
x = Mid(x, StartValue)
Endvalue = InStr(1, x, Chr(10))
End If
Loop
Loop
Close #1
Close #2
' MsgBox NewText & " Successfully created."
End Function
I would also like the message box and "successfully created" message to appear, but they don't, and they seem to be commented out in this example. How might I get it to work? Any feedback would be greatly appreciated. Thank you for your time.
Function TestImportText(ImportTextFile As String)
Dim ImportTextFilePath As String
Dim x As String, y As String
Dim NumberOfCarriageReturns As Long
Dim NumberOfLineFeeds As Long
NumberOfCarriageReturns = 0
NumberOfLineFeeds = 0
ImportTextFilePath = ("\\dummyFile\****\****\******\*******\********\*****\******." & ImportTextFile)
Open ImportTextFilePath For Input As #1
Do Until EOF(1)
Line Input #1, x
If InStr(1, x, Chr(13)) > 0 Then
NumberOfCarriageReturns = NumberOfCarriageReturns + 1
End If
If InStr(1, x, Chr(10)) > 0 Then
NumberOfLineFeeds = NumberOfLineFeeds + 1
End If
Loop
Close #1
'If no Carriage returns found, run the next function to modify
'the text file.
If NumberOfCarriageReturns < NumberOfLineFeeds And NumberOfLineFeeds > 0 Then
Dim NameOfNewText As String
NameOfNewText = ("\\DummyFile***\****\****\***********\****Files\" & ImportTextFile & ".txt")
y = ImportText(ImportTextFilePath, NameOfNewText)
End If
End Function
Function ImportText(OldText As String, NewText As String)
Dim x As String, Endvalue As Integer
Dim StartValue As Integer, OutputTxt As String
Open OldText For Input As #1
Open NewText For Output As #2
Do Until EOF(1)
Line Input #1, x
Endvalue = InStr(1, x, Chr(10))
StartValue = 1
Do Until Endvalue = 0
If Endvalue > 0 Then
OutputTxt = Mid(x, 1, (Endvalue - 1))
Print #2, OutputTxt
StartValue = Endvalue + 1
x = Mid(x, StartValue)
Endvalue = InStr(1, x, Chr(10))
End If
Loop
Loop
Close #1
Close #2
' MsgBox NewText & " Successfully created."
End Function