Click here to Skip to main content
15,889,367 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: how to highlight dates of Month Calendar from database windows form Pin
Meax15-Jul-18 18:18
Meax15-Jul-18 18:18 
Questionhow to create a VB ActiveX interface Pin
Sakthiu1-Jul-18 23:50
Sakthiu1-Jul-18 23:50 
AnswerRe: how to create a VB ActiveX interface Pin
Richard MacCutchan2-Jul-18 0:27
mveRichard MacCutchan2-Jul-18 0:27 
Questionvb.net parsing of string data Pin
dcof26-Jun-18 6:23
dcof26-Jun-18 6:23 
AnswerRe: vb.net parsing of string data Pin
Richard MacCutchan26-Jun-18 6:30
mveRichard MacCutchan26-Jun-18 6:30 
GeneralRe: vb.net parsing of string data Pin
dcof26-Jun-18 7:41
dcof26-Jun-18 7:41 
GeneralRe: vb.net parsing of string data Pin
Richard MacCutchan26-Jun-18 8:40
mveRichard MacCutchan26-Jun-18 8:40 
AnswerRe: vb.net parsing of string data Pin
Richard Deeming26-Jun-18 12:14
mveRichard Deeming26-Jun-18 12:14 
If I've understood what you're asking for, you have a string containing an INSERT command, and you want to extract the values.

The best way to do that would be with a Regular Expression:
Regular Expression Language - Quick Reference | Microsoft Docs[^]

For example:
VB.NET
Public Class StatementInfo
    Private ReadOnly Shared Parser As New Regex(
        "INSERT\s+(INTO\s+)?(?<table>[^(]+)\s*\((?<col>[^,)]+)(,\s*(?<col>[^,)]+))*\)\s*VALUES\s*\((?<val>[^,)]+)(,\s*(?<val>[^,)]+))*\)", 
        RegexOptions.IgnoreCase Or RegexOptions.ExplicitCapture)
    
    Public Shared Function Parse(ByVal input As String) As StatementInfo
        Dim match As Match = Parser.Match(input)
        If Not match.Success Then Return Nothing
        
        Dim tableName As String = match.Groups("table").Value
        Dim columnNames As List(Of String) = match.Groups("col").Captures.Cast(Of Capture)().Select(Function (c) c.Value.Trim()).ToList()
        Dim values As List(Of String) = match.Groups("val").Captures.Cast(Of Capture)().Select(Function (c) c.Value.Trim()).ToList()
        If values.Count <> columnNames.Count Then Throw New ArgumentException("Mis-matched columns and values")
        
        Return New StatementInfo(tableName, columnNames, values)
    End Function
    
    Private Sub New(ByVal tableName As String, ByVal columnNames As List(Of String), ByVal values As List(Of String))
        Me.TableName = tableName
        Me.Values = columnNames _
            .Zip(values, Function (c, v) New With { .Key = c, .Value = v }) _
            .ToDictionary(Function (p) p.Key, Function (p) p.Value, StringComparer.OrdinalIgnoreCase)
    End Sub
    
    Public ReadOnly Property TableName As String
    Public ReadOnly Property Values As IReadOnlyDictionary(Of String, String)
End Class
Usage:
VB.NET
Dim line As String = "INSERT INTO tblInvoiceData(SchNum,InvNum,InvDate,ItemNum, Quantity,UnitPrice,Credit,Amount,VendorId,CatId,Boarddate,RecordId,Imported )VALUES ('896', '558957', '5/2/2016', '3150', '1', '018.99', '', '18.99', '8277', '17', '12/4/2017', '1789655895720160502315018.99', 'Y')"
Dim statement As StatementInfo = StatementInfo.Parse(line)
If statement IsNot Nothing Then
    Console.WriteLine("Table: {0}", statement.TableName)
    For Each pair As KeyValuePair(Of String, String) In statement.Values
        Console.WriteLine("{0} = {1}", pair.Key, pair.Value)
    Next
End If
Output:
Table: tblInvoiceData
SchNum = '896'
InvNum = '558957'
InvDate = '5/2/2016'
ItemNum = '3150'
Quantity = '1'
UnitPrice = '018.99'
Credit = ''
Amount = '18.99'
VendorId = '8277'
CatId = '17'
Boarddate = '12/4/2017'
RecordId = '1789655895720160502315018.99'
Imported = 'Y'




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: vb.net parsing of string data Pin
dcof27-Jun-18 10:52
dcof27-Jun-18 10:52 
QuestionHow to call a 'C' program function from VB code ? Pin
Sakthiu26-Jun-18 3:45
Sakthiu26-Jun-18 3:45 
AnswerRe: How to call a 'C' program function from VB code ? Pin
Richard MacCutchan26-Jun-18 6:25
mveRichard MacCutchan26-Jun-18 6:25 
QuestionHow to run .vba program from specific mail box Pin
Member 1388671525-Jun-18 13:02
Member 1388671525-Jun-18 13:02 
AnswerRe: How to run .vba program from specific mail box Pin
Dave Kreskowiak25-Jun-18 17:26
mveDave Kreskowiak25-Jun-18 17:26 
QuestionHow to pass pre-processor directive to sub-projects Pin
mo149225-Jun-18 3:29
mo149225-Jun-18 3:29 
AnswerRe: How to pass pre-processor directive to sub-projects Pin
Dave Kreskowiak25-Jun-18 4:14
mveDave Kreskowiak25-Jun-18 4:14 
GeneralRe: How to pass pre-processor directive to sub-projects Pin
mo149225-Jun-18 10:44
mo149225-Jun-18 10:44 
QuestionI tried to run your DirectX 9 example in vb.net but received an error Pin
Member 1128712325-Jun-18 3:15
Member 1128712325-Jun-18 3:15 
AnswerRe: I tried to run your DirectX 9 example in vb.net but received an error Pin
Dave Kreskowiak25-Jun-18 4:12
mveDave Kreskowiak25-Jun-18 4:12 
QuestionAccess to and capture NMEA sentences Pin
Member 1352644624-Jun-18 4:06
Member 1352644624-Jun-18 4:06 
AnswerRe: Access to and capture NMEA sentences Pin
Richard MacCutchan24-Jun-18 4:39
mveRichard MacCutchan24-Jun-18 4:39 
GeneralRe: Access to and capture NMEA sentences Pin
Member 1352644626-Jun-18 0:22
Member 1352644626-Jun-18 0:22 
GeneralRe: Access to and capture NMEA sentences Pin
Richard MacCutchan26-Jun-18 0:26
mveRichard MacCutchan26-Jun-18 0:26 
GeneralRe: Access to and capture NMEA sentences Pin
Member 135264463-Jul-18 0:44
Member 135264463-Jul-18 0:44 
GeneralRe: Access to and capture NMEA sentences Pin
Richard MacCutchan3-Jul-18 0:49
mveRichard MacCutchan3-Jul-18 0:49 
QuestionFFT example code in VB.net Pin
Member 1387059319-Jun-18 20:15
Member 1387059319-Jun-18 20:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.