Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a text file which is used as a input for other system It contains data like

city,date
new york,17/02/2012
chicago,17/03/2011

I need to build a frontend on top of this text file to validate any user input . Basically need to make sure date is entered correct etc .

I need to build a form/web page anything which will take input from user and have a text file as above as a database .

can you please tell me which is the best way to do this ?

What I have tried:

angularjs html5 excel-vba csv javascript
Posted
Updated 21-Jul-17 1:42am
Comments
Richard MacCutchan 21-Jul-17 3:17am    
"I need to build a form/web page"
The first thing to decide is which one you plan to use. Web pages and Windows Forms are totally different in implementation.

1 solution

If excel vba is an acceptable solution:

Option Explicit


Sub ValidateMyFile()

Dim FileName As String
Dim iFileNo As Integer
Dim sCity As String
Dim sDate As String
Dim lLineCounter As Long
Dim lErrorCount As Long
Dim iLinesToSkip As Integer  ' to skip any header lines
iLinesToSkip = 1

On Error GoTo ErrorHandler

'this next line assumes that you have a named range in your workbook
'that contains the full path of the file to process
'FileName = Range("FileNameToProcess")

'or you could prompt the user for a file path\name:
'FileName = InputBox("Enter file path and name: ", "File to Validate")

'for testing I created a test file and hard coded the path\name
FileName = "C:\temp\TestFile.txt"

'check to see if the file exists
If Dir(FileName) = "" Then
    MsgBox "File not found... exiting", vbCritical, "File Validatorizer"
    Exit Sub
End If

iFileNo = FreeFile

Open FileName For Input As iFileNo
lLineCounter = 0

For lLineCounter = 1 To iLinesToSkip
    Input #iFileNo, sCity, sDate
Next

Do While Not EOF(iFileNo)
    lLineCounter = lLineCounter + 1
    
    Input #iFileNo, sCity, sDate
    If Not IsDate(sDate) Then
        MsgBox "Bad date at line: " & lLineCounter & "  for city: " & sCity & " Bad Date: " & sDate
        lErrorCount = lErrorCount + 1
    End If
Loop
Close

MsgBox "Done!" & vbCrLf & vbCrLf & "Processed: " & lLineCounter & " lines" & vbCrLf & "Found: " & lErrorCount & " errors", vbExclamation

Exit Sub

ErrorHandler:

MsgBox Err.Description & vbCrLf & vbCrLf & "Exiting ..."


End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900