From 4e5cf053962ee40c7f2d6a69584c70ec62d0ae89 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 5 May 2023 12:54:02 -0400 Subject: [PATCH] getcsv --- TheBigOne.cls | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/TheBigOne.cls b/TheBigOne.cls index ca0b1f8..b28c79f 100644 --- a/TheBigOne.cls +++ b/TheBigOne.cls @@ -1876,6 +1876,64 @@ errh: End Function +Function FILEp_GetCSV(filepath As String) As String() + + Dim fileNo As Integer + Dim fileContent As String + Dim fileLines() As String + Dim dataArray() As String + Dim splitArray() As String + Dim rowCount As Long, colCount As Long + Dim i As Long, j As Long + Dim final() As String + + ' Get an available file number + fileNo = FreeFile + + ' Open the file with the available file number + Open filepath For Input As fileNo + + ' Read the entire file content into a single string + fileContent = Input(LOF(fileNo), fileNo) + + ' Close the file + Close fileNo + + ' Split the file content into lines + fileLines = Split(fileContent, vbCrLf) + + ' Get the number of rows (lines) + rowCount = UBound(fileLines) - LBound(fileLines) + + ' Check if there are any lines in the file + If rowCount > 0 Then + ' Split the first line into columns (using comma as a delimiter) + dataArray = Split(fileLines(0), ",") + + ' Get the number of columns + colCount = UBound(dataArray) - LBound(dataArray) + + ' Redimension the dataArray to the appropriate size + ReDim dataArray(0 To rowCount, 0 To colCount) + + ' Loop through the lines and columns to populate the dataArray + For i = 0 To rowCount + ' Split the current line into columns + splitArray = Split(fileLines(i), ",") + + ' Loop through the columns + For j = 0 To colCount + ' Assign the values to the dataArray + dataArray(i, j) = splitArray(j) + Next j + Next i + FILEp_GetCSV = dataArray + Else + MsgBox "The file is empty or not available." + End If + +End Function + Public Function ADOp_Exec(ByRef con As Integer, ByVal sql As String, Optional ApproxSixe As Long, Optional InclHeaders As Boolean, Optional ByVal value As ADOinterface, Optional ConnectTo As String, Optional IntgrtdSec As Boolean, Optional UserName As String, Optional Password As String, Optional textconfigs As String) As Boolean On Error GoTo errflag