locked
Code is not work on my Expectation RRS feed

  • Question

  • Module Module1
      Sub Main()
        Dim x As New xxCalc
        Dim s As String = ("+ - *")
        Dim xi As Integer = 2
        Dim xj As Integer = 2
        Dim xk As Integer = 2
        Dim xl As Integer = 2
        Console.WriteLine(x.xcalc(xi, xj, xk, xl, s))
        Console.ReadLine()
      End Sub
      Public Class xxCalc
        Function xcalc(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer, ByVal opt As String) As Object
          Dim word As String() = opt.Split(New Char() {" "c})
          Return i & word(0) & j & word(1) & k & word(2) & l
        End Function
      End Class
    End Module
    

    Console Show 2+2-2*2 ???

    I want to Mathmeticaly Calculate it


    www.shariqdon.com
    Wednesday, June 1, 2011 10:58 PM

Answers

  • have a look at my inline calculator:

    http://www.vbforums.com/showthread.php?t=624262


    thanks for any help
    Wednesday, June 1, 2011 11:49 PM
  • you can't calculate an arithmetical computation from a string in vb.net.

    my link shows how you can use SQL to do that though.


    thanks for any help


    any other way???

    why "Cormilo La Monica" Provided Code Work ??? iThe Results is Garbage Value, but its work.


    www.shariqdon.com


    it gave a garbage value because, Carmelo La Monica's code:

    Return i + Char.IsSymbol(word(0)) + j + Char.IsSymbol(word(1)) + k + Char.IsSymbol(word(2)) + l

    is equal to:

    Return i + true + j + true + k + true + l

     


    thanks for any help
    • Marked as answer by Shariq Ayaz Thursday, June 2, 2011 2:03 AM
    Thursday, June 2, 2011 1:37 AM
  • Module Module1
     Sub Main()
     Dim x As New xxCalc
     Dim s As String = ("+ - *")
     Dim xi As Integer = 2
     Dim xj As Integer = 2
     Dim xk As Integer = 2
     Dim xl As Integer = 2
     Console.WriteLine(x.xcalc(xi, xj, xk, xl, s))
     Console.ReadLine()
     End Sub
     Public Class xxCalc
     Function xcalc(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer, ByVal opt As String) As Object
     Dim word As String() = opt.Split(New Char() {" "c})
     Return i & word(0) & j & word(1) & k & word(2) & l
     End Function
     End Class
    End Module
    

    Console Show 2+2-2*2 ???

    I want to Mathmeticaly Calculate it


    www.shariqdon.com


    Hello ShariqDON,

     

    try this code , i think it should work

     

     

    Module Module1
     Sub Main()
     Dim x As New xxCalc
     Dim s As String = ("+ - *")
     Dim xi As Integer = 2
     Dim xj As Integer = 2
     Dim xk As Integer = 2
     Dim xl As Integer = 2
     Console.WriteLine(x.xcalc(xi, xj, xk, xl, s))
     Console.ReadLine()
     End Sub
    
    
     Public Class xxCalc
     Function xcalc(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer, ByVal opt As String) As Object
      Dim word As String() = opt.Split(New Char() {" "c})
    
      Return i + Char.IsSymbol(word(0)) + j + Char.IsSymbol(word(1)) + k + Char.IsSymbol(word(2)) + l
     End Function
     End Class
    End Module
    
    

     

     

    Hello


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/

    Wednesday, June 1, 2011 11:35 PM

All replies

  • Module Module1
     Sub Main()
     Dim x As New xxCalc
     Dim s As String = ("+ - *")
     Dim xi As Integer = 2
     Dim xj As Integer = 2
     Dim xk As Integer = 2
     Dim xl As Integer = 2
     Console.WriteLine(x.xcalc(xi, xj, xk, xl, s))
     Console.ReadLine()
     End Sub
     Public Class xxCalc
     Function xcalc(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer, ByVal opt As String) As Object
     Dim word As String() = opt.Split(New Char() {" "c})
     Return i & word(0) & j & word(1) & k & word(2) & l
     End Function
     End Class
    End Module
    

    Console Show 2+2-2*2 ???

    I want to Mathmeticaly Calculate it


    www.shariqdon.com


    Hello ShariqDON,

     

    try this code , i think it should work

     

     

    Module Module1
     Sub Main()
     Dim x As New xxCalc
     Dim s As String = ("+ - *")
     Dim xi As Integer = 2
     Dim xj As Integer = 2
     Dim xk As Integer = 2
     Dim xl As Integer = 2
     Console.WriteLine(x.xcalc(xi, xj, xk, xl, s))
     Console.ReadLine()
     End Sub
    
    
     Public Class xxCalc
     Function xcalc(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer, ByVal opt As String) As Object
      Dim word As String() = opt.Split(New Char() {" "c})
    
      Return i + Char.IsSymbol(word(0)) + j + Char.IsSymbol(word(1)) + k + Char.IsSymbol(word(2)) + l
     End Function
     End Class
    End Module
    
    

     

     

    Hello


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/

    Wednesday, June 1, 2011 11:35 PM

  • Your expectations need to change.  & is the string concatenation operator.  The code is doing what you asked it to do.
     
    Calculating the resultant string to get "0" is not in the generic sense trivial.

    --
    Mike
    Wednesday, June 1, 2011 11:45 PM
  • its work but not Calculat Correct

     


    www.shariqdon.com
    Wednesday, June 1, 2011 11:46 PM
  • have a look at my inline calculator:

    http://www.vbforums.com/showthread.php?t=624262


    thanks for any help
    Wednesday, June 1, 2011 11:49 PM
  • have a look at my inline calculator:

    http://www.vbforums.com/showthread.php?t=624262


    thanks for any help

     

    Thats Nice! Yes, Its Work in Your Style.

    How Can I do with My Code


    www.shariqdon.com
    Thursday, June 2, 2011 12:13 AM
  • its work but not Calculat Correct

     


    www.shariqdon.com


    you can't calculate an arithmetical computation from a string in vb.net.

    my link shows how you can use SQL to do that though.


    thanks for any help
    Thursday, June 2, 2011 12:28 AM
  • you can't calculate an arithmetical computation from a string in vb.net.

    my link shows how you can use SQL to do that though.


    thanks for any help


    any other way???

    why "Cormilo La Monica" Provided Code Work ??? iThe Results is Garbage Value, but its work.


    www.shariqdon.com
    Thursday, June 2, 2011 1:33 AM
  • you can't calculate an arithmetical computation from a string in vb.net.

    my link shows how you can use SQL to do that though.


    thanks for any help


    any other way???

    why "Cormilo La Monica" Provided Code Work ??? iThe Results is Garbage Value, but its work.


    www.shariqdon.com


    it gave a garbage value because, Carmelo La Monica's code:

    Return i + Char.IsSymbol(word(0)) + j + Char.IsSymbol(word(1)) + k + Char.IsSymbol(word(2)) + l

    is equal to:

    Return i + true + j + true + k + true + l

     


    thanks for any help
    • Marked as answer by Shariq Ayaz Thursday, June 2, 2011 2:03 AM
    Thursday, June 2, 2011 1:37 AM
  • you can't calculate an arithmetical computation from a string in vb.net.

    my link shows how you can use SQL to do that though.


    thanks for any help


    any other way???

    why "Cormilo La Monica" Provided Code Work ??? iThe Results is Garbage Value, but its work.


    www.shariqdon.com


    it gave a garbage value because, Carmelo La Monica's code:

    Return i + Char.IsSymbol(word(0)) + j + Char.IsSymbol(word(1)) + k + Char.IsSymbol(word(2)) + l

    is equal to:

    Return i + true + j + true + k + true + l

     


    thanks for any help


    Please Explain me This line "

    Dim SQL As String = "SELECT " & TextBox1.Text.ToLower.Replace("math.", "")

    what is math.

     


    www.shariqdon.com
    Thursday, June 2, 2011 2:10 AM
  • for the calculations you want to do you can use:

     

    Dim SQL As String= i.tostring & " " & word(0) & " " & j.tostring & " " & word(1) & " " & k.tostring & " " & word(2) " " & & l.tostring
    
    
    

    thanks for any help
    Thursday, June 2, 2011 2:17 AM