Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Rosetta Stone
      '// Pseudocode translation to C++, C#, or VB
      
      
      '// This shows only in vb
      '//This shows in C# and VB, not C++
      '//This shows in C++ and VB, not C#
      
      
      '// Tags (c, cpp, cs, vb, NotCpp, NotCs, NotVb, etc.,) are not case-sensitive
      
      Console.Write("w() prints text without ")
      Console.Write("a new line at the end.")
      Console.WriteLine() '// Moves to a new line
      Console.WriteLine("wl() prints a line, ending with a newline.")
      Console.WriteLine("Line 2")
      Console.WriteLine("Line 3")
      Console.WriteLine($"{123} multiple args for wl()")
      Console.Write("multiple ")
      Console.Write("args ")
      Console.Write("for w() too")
      Console.WriteLine("")
      
      Dim t = uc.NewTransformer()
      '// Property setter syntax: @ followed by property name and value in parenthesis
      t.Description = "Some description goes here"
      
      '// Property getter sytanx: @ followed by property name, and empty parenthesis
      Console.WriteLine(t.Description)
      
      '// Each property has an alternative getter and setter function syntax
      '// with the Get or Set prefix like this:
      t.SetDescription("A new description")
      Console.WriteLine(t.GetDescription())
      
      '// Using the alternative function syntax for a property can be useful when chaining calls
      '// I use the c tag for the sake of VB that wants everything on the same line.
      t.SetText("Some Text").SetDescription("Some description").FromTo("Text", "String").SetCaseSensitive(true).SetMinimum(1).SetMaximum(5).GetParentTransformer().Transform()
      Console.WriteLine(t.Text)
      
      '// For compatibility across C++, C#, and VB, use the Verbatim tag for multi-line
      '// strings.  Do not use escapes or specialized double-quote syntax in a string.
      Dim MyString = "Here is some ""quoted"" text on one line
And some random text on another line"
      Console.WriteLine(MyString)
      
      '// Use this syntax to define a variable with a uCalc-related type
      '// Either with or without an initial value
      Dim MyStringA As uCalc.String
      Dim MyStringB As uCalc.String = "This is some text."
      MyStringA = MyStringB.Text + " Some more text"
      Console.WriteLine(MyStringA.Text)
      
      '// For simple types not belonging to uCalc, use this C#-like notation instead:
      
      Dim OtherString = "Some other string "
      Dim MyNumber = 12345
      Console.WriteLine($"{OtherString}{MyNumber}")
      
      '// Another way to define a new variable (with a uCalc type) is with the more
      '// flexible New.  Use this especially if you need to use arguments:
      
      Dim MyVar As New uCalc.Item("Variable: x = 123")
      Dim MyFunc As New uCalc.Item(uc, "Function: f(x) = x^2")
      Console.WriteLine(uCalc.DefaultInstance.Eval("x"))
      Console.WriteLine(uc.Eval("f(5)"))
      
      '// To define a uCalc object that gets released when the object goes out of scope, do:
      Using tr As New uCalc.Transformer()
         tr.FromTo("This", "That")
         Console.WriteLine(tr.Transform("This car").Text)
         '// To accomodate other languages besides C#, you must explicitely end the using block
      End Using
      
      '// Use the C++ style to_string to convert a value to a string
      Console.WriteLine("Value: " + (100 + 25).ToString())
      
      '// Always use the C++ double colon, ::, for scope resolution
      '// (it gets translated to a dot, ., in C# and VB
      Dim MyTokens = t.Tokens
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Float_Double).Name)
      
      '// Other supported constructs
      For x  As Double = 1 To 10
         Console.WriteLine(x)
      Next
      
      For x  As Double = 1 To 10  Step 2
         Console.WriteLine(x)
      Next
      
      For Each dType In uc.DataTypes
         Console.WriteLine(dType.Name)
      Next
      
      Dim count = 0
      
      While count <= 5
         Console.WriteLine(count)
         count += 1
      End While
      
      Do
         Console.WriteLine(count)
         count = count + 1
      Loop While count <= 10
      
      If count < 100 Then
         Console.WriteLine("count is less than 100")
      End If
      
      If count < 5 Then
         '// Some lines of code
         Console.WriteLine("count is less than 5")
         ElseIf count <= 50 Then
         '// . . .
         Console.WriteLine("count is less than or equal to 50")
      Else
         '// More lines of code
         Console.WriteLine("count is greater than 50")
      End If
      
      '// Declare and initialize a string array
      Dim items() As String = {"Apple", "Banana", "Cherry"}
      
      '// Get the size of the array
      count = items.Length
      Console.WriteLine($"Total items: {count}")
      
      '// Access and modify elements
      Console.WriteLine($"First item: {items(0)}")
      items(1) = "Blueberry"
      
      '// Iterate through the array
      Dim i = 0
      Do
         Console.WriteLine(items(i))
         i = i + 1
      Loop While i < items.Length
      
      '// For proper translation into the 3 supported languages, wrap Boolean values with
      '// bool.  When pseudocode contains the bool function, a helper function named tf is
      '// inserted towards to the top of the code
      
      Console.WriteLine($"{uc.EvalStr("'Cos is a function? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Function)}")
      Console.WriteLine($"{uc.EvalStr("'Cos is a variable? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Variable)}")
   End Sub
End Module