Data Types Cheat Sheet

Base Data Types

String
UiPathstrMyVar (String) Default is Null (Nothing)
VBDim strMyVar As String
C#string strMyVar;

strMyVar = “double quotes are needed”

String.IsNullOrEmpty(strMyVar) => test for if not initialized

strMyVar + ” and another string” => concatenation

Split(strMyVar, ” “) => returns array – second arg is delim

strMyVar.Replace(vbcr, ” “).Replace(vblf, ” “) => strips carriage returns

strMyVar.IndexOf(searchFor) => returns integer position where 1st found

strMyVar.IndexOf(searchFor, startpos, countOfLettersToSearch) => to limit search

strMyVar.Substring(startPos, length) => return an embedded string

Left(strMyVar, numChars) => return left (or right) side of string

Trim(strMyVar) => trims whitespace both sides – also RTrim and LTrim

Boolean
UiPathboolMyVar (Boolean) Default is False
VBDim boolMyVar As Boolean
C#bool boolMyVar;

boolMyVar = True

boolMyVar = (1 + 2 = 3)

Int32
UiPathintMyVar (Int32) Default is 0
VBDim intMyVar As Integer
C#int intMyVar;

intMyVar = 123

intMyVar = 123.45 Not allowed

CInt(strNumericVal) => ex: “2” (“2.5” will be rounded to 3)

Double
UiPathdblMyVar (System.Double) Default is 0
VBDim dblMyVar As Double OR Dim dblMyVar#
C#double dblMyVar;

dblMyVar = 123.45

boolSuccess = Double.TryParse(strValue, 0) => test if can parse
dblMyVar = CDbl(strValue) => parse
dblMyVar = Double.Parse(strValue) => parse

strMyVar = dblMyVar.ToString(“F2”) => prints with 2 decimals (rounded)

Math.Round(dblMyVar, x) => rounds to x digits

DateTime
UiPathdteMyVar (System.DateTime or System.DateOnly)
Default is 01/01/0001 00:00:00
(Internally stored as number need to format as a string to get month day year etc)
VBDim dteMyVar As DateTime
C#DateTime dteMyVar;

dteMyVar = new DateTime(2020, 02, 12, 2, 35, 07) => (year, month, day, hour, minute, second) – time always defaults to 00:00:00 midnight unless specified

dteMyVar = DateTime.Now OR Date.Now => for timestamps

dteMyVar = DateTime.Today OR Date.Today => default time will be midnight


dteMyVar = CDate(“01/05/1960”)

formatting symbols
  • yyyy – 2001
  • yy – 01
  • y – 1
  • MMMM – January
  • MMM – Jan
  • MM – 01
  • M -1
  • dddd – Friday
  • ddd – Fri
  • dd – 05
  • d – 5
  • HH – 14
  • H – 14
  • hh – 02
  • h – 2
  • mm – 06
  • m – 6
  • ss – 07
  • s – 7
  • tt – PM
  • For more click here

Format any DateTime by using pattern made from symbols listed above
dteMyVar.ToString(“MM/dd/yy”) => 01/05/01

Date.ParseExact(strDate, “dd-MM-yyyy”, System.Globalization.DateTimeFormatInfo.InvariantInfo)
=> to convert date string into DateTime by local formatting (make pattern what input is)

dteMyVar.AddDays(x) => x days from date, can do negatives to go backwards

Structured Data Types

Array

IMPORTANT! It’s not easy to add elements to array at runtime. Use List for dynamic arrays.

UiPatharrMyVar (Array of [T]) Default is Null (Nothing)
VBDim arrMyVar(20) As Integer
OR
Dim arrMyVar(0 To 20) As Integer
=> creates array with 21 spots for whatever data type
C#int[] arrMyVar;

arrMyVar = New Integer(){} => will need to init with elements later
arrMyVar = New Integer(10){} => with 11 places
arrMyVar = New Integer(){1,2,3} => init with elements

ASSIGN

arrMyVar = {1, 2, 3} => entire array
arrMyVar(2) = 5 => specific element (must be inbounds)

COOL STUFF

arrMyVar.Length => how many places

arrMyVar(0) => get specific element (0-based)

USEFUL ACTIVITIES

For Each => iteration

List
declare
UiPathlstMyVar (List<T> from System.Collections.Generic) Default is Null (Nothing)
VBDim lstMyVar As New List(Of Integer)
C#List<Integer> lstMyVar;
INITIALIZE

(be sure to initialize at Variables panel) New List(Of whatever)

lstMyVar = New List(Of Integer) => count is now 0

lstMyVar = New List(Of Integer) From {1,2,3,4,5} => init and assign

useful activities
  • Create List
  • Append Item To List
  • Update List
  • Read List Item
  • For Each
COOL STUFF

lstMyVar.Count => how many elements

lstMyVar.Item(0) => get specific element (0-based)

Enumerable.Concat(1stList, 2ndList).ToList => join two lists together

String.Join(“,”, lstMyVar) => all elements into string for printing

Dictionary
declare
UiPathdicMyVar (Dictionary<TKey, TValue> from System.Collections.Generic)
Default is Null (Nothing)
VBDim dicMyVal As New Dictionary(Of String, Integer)
C#IDictionary<int, string> dicMyVar;
INITIALIZE

dicMyVar = New Dictionary(Of Integer, String) => count is now 0 (can be used to clear)

dicMyVar = New Dictionary(Of Integer, String) From {{1, “val1”}, {2, “val2”}} => init and assign

assign

dicMyVar(keyname) = whatever => will overwrite if key already there else will add

useful activities
  • For Each => key in dicMyVar.Keys (arg type same as key type) then to get value dicMyVar(key)
COOL STUFF

dicMyVar.Count => how many elements

dicMyVar(keyname) => get value by key

dicMyVar.Keys => array of keynames

boolKeyExists = dicMyVar.ContainsKey(keyname)

boolValExists = dicMyVar.ContainsValue(value)

boolWasRemoved = dicMyVar.Remove(keyname)

dict = dict.Concat(New Dictionary(Of String,Int32)From{{“Teacher”,3},{“Doctor”,3}}).ToDictionary(Function(kv) kv.Key,Function(kv) kv.Value)
=> Concat a second dictionary to first

dict2 = dict1.ToDictionary(Function(kv) kv.Key,Function(kv) kv.Value.Copy) => deep copy one dict into another

Data Table
declare
UiPathdtMyVar (DataTable from System.Data) Default is Null (Nothing)
VBDim dtMyVar As new DataTable()
C#DataTable dtMyVar = new DataTable();
INITIALIZE

dtMyVar = New DataTable()

dtMyVar.Columns.Add(“ColumnName”, GetType(System.String)) => assign to Object data type

useful activities
  • Read Range Workbook => save to data table variable Properties > Data Table
  • Build Data Table => wizard to build columns/values put variable name in Properties > Output
  • Add Data Column
  • Add Data Row
  • Clear Data Table
  • Sort Data Table
  • Filter Data Table
  • For Each Row in Data Table => loop
  • Output Data Table as Text => outputs to string so can log
  • Write Data Table To Excel
COOL STUFF

dtMyVar.Rows.Count-1 => last row

dtMyVar.Rows(rownum).Item(“ColumnName”) => value in column/row

CurrentRow.Item(“ColumnName”) => value in loop

dtMyVar.Rows.Add(“ColumnName”, 32 ) => add row and data all at once

dtTable.Rows(0)(“ColumnName”).GetType().ToString() => check the data type of a column

‘Loop through data and change data type (Using invoke code)
dtTable.AsEnumerable().ToList().ForEach (
Sub(rs)
rs(“Date”)=CDate(rs(“Date”))
End Sub
)


I highly recommend a package called BalaReva.EasyDataTable.Activities. It makes changing data types of a column much easier. Learn how to use it here.