English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In vb.net 2005.

I am wanting to say at form load that if a global value (strName) has not been used (i.e. has not been entered into), then load another form, how can i do this, i have tried:

If strName.length < 1
strName.Empty

Help!!!

2007-03-12 03:50:05 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

I would use the IsNullOrEmpty property:

Dim strName As String

If strName.IsNullOrEmpty Then
MsgBox("strName Is Null Or Empty!")
End If

BTW, by default, if you declare a string variable, it is empty, not null.

The first answer would not work; it would actually set your string to be empty, which would make the if statement evaluate as true every time.

The second answer would work fine, too, but will only evaluate as true if the string is empty, not if it is null.

2007-03-12 04:01:24 · answer #1 · answered by Anonymous · 0 0

Public Sub Form_Load()

If strName.Length < 1 or strName.Text = String.Empty Then
Form2.Show()

this should load another form if strName is empty.

2007-03-12 12:25:52 · answer #2 · answered by cisconp_kid 2 · 0 0

dhvrm, i have tried this, got this code:

---
If strName.IsNullOrEmpty Then frmTeachBasics.Show()
---

It is now asking me to replace strName with String

Same with Praveen's way, is it cos it is a global variable????


Argggghhhhh! Have i done something wrong?

2007-03-12 11:53:44 · answer #3 · answered by harvey h 1 · 0 0

If strName.Length = 0 then
dim f2 as new form2
f2.show
me.hide

or

if strName.ToString is Nothing Then
dim f2 as new Form2
f2.show
me.hide

2007-03-15 18:38:20 · answer #4 · answered by Anonymous · 0 0

you can check for

if strname.text == string.empty then
do this
else
do this
end if

let me know if it doesnt works.

2007-03-12 10:55:07 · answer #5 · answered by NeevarP M 3 · 0 0

if strName = ""


There ya go.

2007-03-12 10:55:32 · answer #6 · answered by Chip 7 · 0 0

fedest.com, questions and answers