---
title: "IF/ELSE Statement doesn't work"  
description: "IF/ELSE Statement doesn't work"  
author: "Anonymous User"  
published: 2013-06-11  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1044/if-else-statement-doesn-t-work  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# IF/ELSE Statement doesn't work

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances), \
I have a [ComboBox](https://www.mindstick.com/articles/57/display-record-according-to-combobox-selection-in-csharp-dot-net) containing 5 values. An empty line, "**[Credit](https://www.mindstick.com/articles/85765/building-your-credit-score-when-you-re-an-uber-driver)**", "**Debit**", "**Credit Settlement**", and "**Debit Settlement**". I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to perform an error [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) on it. If the user types anything in the ComboBox or if the [selection](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) of the [empty string](https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string) is made, I want to [trigger](https://www.mindstick.com/blog/167/triggers-in-wpf) an error. This is what I have now but it doesn't work. Any ideas?\
**If cboTypeRes.Text.Trim = "" or cboTypeRes.Text.Trim <> "Debit" Or cboTypeRes.Text.Trim <> "Credit" Or cboTypeRes.Text.Trim = "Debit Settlement" Or** **\****cboTypeRes.Text.Trim = "Credit Settlement" Then****\**Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) for any recommendations or solutions.\

## Replies

### Reply by AVADHESH PATEL

Hi Babe,\
Check if the selected item is contained in the Items collection\

```
if cboTypesRes.SelectedItem Is Nothing Then    Console.WriteLine("Error")Else    Dim curText = cboTypesRes.SelectedItem.ToString().Trim()    if curText.Length = 0 OrElse Not cboTypesRes.Items.Contains(curText) Then        Console.WriteLine("Error")    End IfEnd If
```

**\**A little update:\
The SelectedItem property could be Nothing when the user types the word directly or you user could types the word with a lower case first letter.If you find these scenarios acceptable then you could try with this change\

```
Dim curText = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(cboTypeRes.Text)if curText.Length = 0 OrElse Not cbo.Items.Contains(curText) Then    Console.WriteLine("Error")End If
```

**\** I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1044/if-else-statement-doesn-t-work

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
