> For the complete documentation index, see [llms.txt](https://kb.logicerp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/writing-formulas-in-the-script-editor/writing-vb.net-formulas.md).

# Writing VB.NET Formulas

**VB.NET** is the language to use for new formulas. A VB.NET formula works the same on the desktop, in the 64-bit version and on the web.

> **Why convert older formulas?**
>
> Most formulas written in **VBScript** are not run on the web or in the 64-bit version of Logic ERP - only very simple one-line sums are still worked out, and everything else stays **0**. Open such a formula and press **Convert to VB.NET** (see **Convert to VB.NET**).

The field names below (**DA**, **HRA**, **ESIC**, **PF**, **INCENTIVE**) stand for allowances and the rates are only examples. Use the names in your own **Field List** - in payroll they come from your company's allowance list. **BASIC\_SALARY**, **GROSS\_SALARY** and **DEPARTMENT\_NAME** are standard payroll fields.

### **Store the result in a field**

A formula works out a value and **stores it in a field** with **=**:

* `DA = GROSS_SALARY * 0.3065`
* A line that only works out a value, such as `GROSS_SALARY * 0.3065`, stores nothing. **Check & Fix** reports it as *this line works out a value but does not store it* (other messages may appear on the same line; adding the **NAME =** clears them).

### **Choose between values - If**

```
If GROSS_SALARY > 21000 Then
    ESIC = 0
ElseIf GROSS_SALARY > 15000 Then
    ESIC = GROSS_SALARY * 0.0075
Else
    ESIC = GROSS_SALARY * 0.01
End If
```

* Every **If** ends with **End If**. **ElseIf** is one word.
* Compare with **=** (equal), **<>** (not equal), **>**, **<**, **>=**, **<=**. Join conditions with **AndAlso** and **OrElse**.

### **Choose from a list - Select Case**

```
Select Case DEPARTMENT_NAME
    Case "SALES"
        INCENTIVE = BASIC_SALARY * 0.05
    Case "STORES", "DISPATCH"
        INCENTIVE = 500
    Case Else
        INCENTIVE = 0
End Select
```

* Text values are written in double quotes: `"SALES"`.
* Text must match exactly, including capital letters: **"SALES"** does not match **"Sales"**.

### **Your own working values - Dim**

A name that is not a field must be declared with **Dim** before it is used:

```
Dim PF_RATE As Double
PF_RATE = 0.12
PF = BASIC_SALARY * PF_RATE
```

* Do not use names that VB.NET already uses for its own words, such as **Rate**, **Year**, **Month** or **Day** - the message you get is then hard to understand.

### **Notes and layout**

* Text after **'** is a note and is not run - on a line of its own or at the end of a line.
* Indent the lines inside **If**, **Select Case** and loops. The indentation and the blank lines inside the formula are kept when it is saved and opened again (blank lines at the very top and bottom are removed), and they do not change the result.

> **Example - Ravi's HRA**
>
> HRA is 40% of the basic salary, but never more than 8,000. Ravi's basic salary is 25,000.
>
> ```
> HRA = BASIC_SALARY * 0.4
> If HRA > 8000 Then
>     HRA = 8000
> End If
> ```
>
> In the editor, click **BASIC\_SALARY** in the **Field List**, type 25000 in the box next to its name and press **Enter**, then press **Script Watch** under **Script Results**. **HRA** shows 8000 (40% of 25,000 is 10,000, which is more than 8,000).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/writing-formulas-in-the-script-editor/writing-vb.net-formulas.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
