Click here to Skip to main content
15,890,123 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
bluatigro5-Sep-17 22:10
bluatigro5-Sep-17 22:10 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz5-Sep-17 22:40
professionalArthur V. Ratz5-Sep-17 22:40 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz6-Sep-17 4:49
professionalArthur V. Ratz6-Sep-17 4:49 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz6-Sep-17 4:56
professionalArthur V. Ratz6-Sep-17 4:56 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
bluatigro6-Sep-17 21:56
bluatigro6-Sep-17 21:56 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
bluatigro7-Sep-17 1:21
bluatigro7-Sep-17 1:21 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz7-Sep-17 3:15
professionalArthur V. Ratz7-Sep-17 3:15 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz7-Sep-17 7:44
professionalArthur V. Ratz7-Sep-17 7:44 
Here we go. Now, I'm ready to come up with the code in VB.NET 2017 you've been requesting for:

Probably, this is a correct solution. Just check it:

VB
Module Module1
    Function Compute(expr As String)
        Dim Result As Int32 = 0
        Dim val As String = ""
        Dim op() As String = {"+", "-", "*", "/"}
        Dim strings As List(Of String) = New List(Of String)
        For index = 0 To expr.Length() - 1 Step 1
            If IsNumeric(expr(index)) Then
                val = Nothing
                Dim done As Boolean = False
                While index < expr.Length() And done = False
                    If IsNumeric(expr(index)) Then
                        val += expr(index)
                        index = index + 1
                    Else done = True
                    End If
                End While
                strings.Add(val)
            ElseIf expr(index) = op(0) Then
                strings.Add(op(0))
            ElseIf expr(index) = op(1) Then
                strings.Add(op(1))
            ElseIf expr(index) = op(2) Then
                strings.Add(op(2))
            ElseIf expr(index) = op(3) Then
                strings.Add(op(3))
            End If
        Next

        Dim n As Int32 = 0
        While strings.Contains("*") Or strings.Contains("/")
            Dim found As Boolean = False
            While n < strings.Count() And found = False
                If strings(n) = op(2) Then
                    Dim op1 As Int32 = Integer.Parse(strings(n - 1))
                    Dim op2 As Int32 = Integer.Parse(strings(n + 1))
                    Dim Res = op1 * op2
                    strings.RemoveAt(n - 1)
                    strings(n - 1) = Res
                    strings.RemoveAt(n)
                    Result = Res
                    found = True
                    n = 0
                End If

                If strings(n) = op(3) Then
                    Dim op1 As Int32 = Integer.Parse(strings(n - 1))
                    Dim op2 As Int32 = Integer.Parse(strings(n + 1))
                    Dim Res = CInt(op1 / op2)
                    strings.RemoveAt(n - 1)
                    strings(n - 1) = Res
                    strings.RemoveAt(n)
                    Result = Res
                    found = True
                    n = 0
                End If
                n = n + 1
            End While
        End While

        n = 0
        While strings.Contains("+") Or strings.Contains("-")
            Dim found As Boolean = False
            While n < strings.Count() And found = False
                If strings(n) = op(0) Then
                    Dim op1 As Int32 = Integer.Parse(strings(n - 1))
                    Dim op2 As Int32 = Integer.Parse(strings(n + 1))
                    Dim Res = op1 + op2
                    strings.RemoveAt(n - 1)
                    strings(n - 1) = Res
                    strings.RemoveAt(n)
                    Result = Res
                    found = True
                    n = 0
                End If

                If strings(n) = op(1) Then
                    Dim op1 As Int32 = Integer.Parse(strings(n - 1))
                    Dim op2 As Int32 = Integer.Parse(strings(n + 1))
                    Dim Res = op1 - op2
                    strings.RemoveAt(n - 1)
                    strings(n - 1) = Res
                    strings.RemoveAt(n)
                    Result = Res
                    found = True
                    n = 0
                End If
                n = n + 1
            End While
        End While
        Return Result
    End Function
    Function Parse(input As String)
        Dim t As Int32 = 0
        Dim oe(0) As Int32
        Dim strings As List(Of String) = New List(Of String)
        For index = input.Length() - 1 To 0 Step -1
            If input(index) = "(" Or index = 0 Then
                Dim sb As String = ""
                Dim n As Int32 = 0
                If index = 0 Then
                    n = index
                Else n = index + 1
                End If

                Dim exists As Boolean = False
                Do
                    exists = False
                    Dim bracket As Boolean = False
                    While n < input.Length() And bracket = False
                        If input(n) <> ")" Then
                            sb += input(n)
                        Else bracket = True
                        End If
                        n = n + 1
                    End While

                    If exists <> True Then
                        Dim r As Int32 = 0
                        While r < oe.Count() And exists = False
                            If oe(r) = n Then
                                exists = True
                                sb += ") "
                                n = n + 1
                            End If
                            r = r + 1
                        End While
                    End If

                Loop While exists = True

                If exists = False Then
                    Array.Resize(oe, oe.Length + 1)
                    oe(t) = n
                    t = t + 1
                End If

                strings.Add(sb)

            End If
        Next

        For index = 0 To strings.Count() - 1 Step 1
            Dim Result As String = Compute(strings.Item(index)).ToString()
            For n = index To strings.Count() - 1 Step 1
                strings(n) = strings.ElementAt(n).Replace("(" + strings.Item(index) + ")", Result)
            Next
        Next
        Return Compute(strings.Item(strings.Count() - 1))
    End Function
    Sub Main()
        Dim input As String = "1769 - (40 + 80 / (60 - 1 * 20) + 6) / 15 + 1"

        Console.WriteLine(input)

        Console.WriteLine("Result = {0}", Parse(input))

        Console.ReadKey()
    End Sub

End Module


Looking forward to your feedback. Smile | :)
GeneralRe: vb 2017 : AI : Genetic Programming Pin
bluatigro7-Sep-17 23:26
bluatigro7-Sep-17 23:26 
GeneralRe: vb 2017 : AI : Genetic Programming Pin
Arthur V. Ratz7-Sep-17 23:37
professionalArthur V. Ratz7-Sep-17 23:37 
QuestionImport Outlook calendar entries from Excel with VBscript? Pin
xs13x31-Aug-17 11:03
xs13x31-Aug-17 11:03 
SuggestionRe: Import Outlook calendar entries from Excel with VBscript? Pin
Ralf Meier31-Aug-17 20:47
mveRalf Meier31-Aug-17 20:47 
AnswerRe: Import Outlook calendar entries from Excel with VBscript? Pin
Chris Quinn31-Aug-17 22:20
Chris Quinn31-Aug-17 22:20 
AnswerRe: Import Outlook calendar entries from Excel with VBscript? Pin
Ralf Meier1-Sep-17 0:32
mveRalf Meier1-Sep-17 0:32 
AnswerRe: Import Outlook calendar entries from Excel with VBscript? Pin
Richard Deeming1-Sep-17 2:47
mveRichard Deeming1-Sep-17 2:47 
GeneralRe: Import Outlook calendar entries from Excel with VBscript? Pin
xs13x1-Sep-17 3:13
xs13x1-Sep-17 3:13 
GeneralRe: Import Outlook calendar entries from Excel with VBscript? Pin
Richard Deeming1-Sep-17 4:00
mveRichard Deeming1-Sep-17 4:00 
QuestionI need to load a JP2 into an ImageList. All info I've found is out of date. Pin
Member 1338764431-Aug-17 5:19
Member 1338764431-Aug-17 5:19 
QuestionMessage Removed Pin
30-Aug-17 17:49
compcanada201730-Aug-17 17:49 
QuestionOpenFileDialog - Specific Path Pin
purushotham.k929-Aug-17 6:00
purushotham.k929-Aug-17 6:00 
AnswerRe: OpenFileDialog - Specific Path Pin
A_Griffin29-Aug-17 8:07
A_Griffin29-Aug-17 8:07 
QuestionUsing Webclient.uploadfile files is never copied to website Pin
Member 1098357222-Aug-17 12:47
Member 1098357222-Aug-17 12:47 
Questionvb.net desktop app zoom feature Pin
dcof22-Aug-17 6:34
dcof22-Aug-17 6:34 
AnswerRe: vb.net desktop app zoom feature Pin
Eddy Vluggen22-Aug-17 8:15
professionalEddy Vluggen22-Aug-17 8:15 
GeneralRe: vb.net desktop app zoom feature Pin
dcof23-Aug-17 8:49
dcof23-Aug-17 8:49 

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.