From 95cc8557225a31f1fe1ce3879c79495aeaed0b98 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 24 Sep 2024 11:40:58 -0400 Subject: [PATCH] current state personal macrobook --- TheBigOne.cls | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/TheBigOne.cls b/TheBigOne.cls index 1bca57c..47d6799 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 @@ -2193,7 +2251,7 @@ Function json_concat(list As Range) As String End Function -Public Function ADOp_BuildInsertSQL(ByRef tbl() As String, target As String, trim As Boolean, start As Long, ending As Long, ParamArray ftype()) As String +Public Function ADOp_BuildInsertSQL(ByRef tbl() As String, Target As String, trim As Boolean, start As Long, ending As Long, ParamArray ftype()) As String Dim i As Long @@ -2202,7 +2260,7 @@ Public Function ADOp_BuildInsertSQL(ByRef tbl() As String, target As String, tri Dim sql As String Dim rec As String - sql = "INSERT INTO " & target & " VALUES " & vbCrLf + sql = "INSERT INTO " & Target & " VALUES " & vbCrLf For i = start To ending rec = "" If i <> start Then sql = sql & "," & vbCrLf @@ -3023,6 +3081,8 @@ Function TBLp_VarToString(ByRef t() As Variant) As String() Dim j As Long Dim x() As String + On Error GoTo errh + If LBound(t, 1) = 1 Then End If @@ -3035,6 +3095,11 @@ Function TBLp_VarToString(ByRef t() As Variant) As String() Next i TBLp_VarToString = x + +errh: + If Err.Number <> 0 Then + MsgBox ("error on row: " & i) + End If End Function