473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Checking for empty text boxes

I am using Visual Basic for a Psychology experiment and I would like to check and see if the participants answered all of the questions on one form before moving on to the next. So far this is what I have done and it is not working.

If txbAge.Text = String.Empty Then
MsgBox("Wie Alt bist du?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If female.Checked = False And male.Checked = False Then
MsgBox("Was ist dein Geschlecht?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If txbMajor.Text = String.Empty Then
MsgBox("Was studierst du")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If txbSemester.Text Is Nothing Then
MsgBox("In welchem Semester bist du?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If

Using this code, it does check to see if the textboxes are empty but if the participant clicks on the next button without answering any of the questions the message boxes appear one after the other and then the next form appears without giving the participant the chance to answer the items they missed. I am sure this code is not the most efficient or best way to do this (obviously since it isn't working) and would appreciate any and all help. I am completely new at programming.

Thanks!
Nov 1 '11 #1
2 2407
Killer42
8,435 Expert 8TB
That's because you are not stopping after you check each one. I'd suggest adding Exit Sub after each MsgBox.

Also, I'd recommend removing the extra ":" after each Else.

By the way, judging from the syntax, I'd guess you'll get a better response in the Visual Basic .Net forum. This one is for much older versions of VB, which work a bit differently.
Dec 18 '11 #2
While is not working is because you are asking the program to move to the next form if any of the textboxes is not empty.
You are supposed to check for all textboxes before call .ShowDialog
Try the below codes I believed it should work and post your feedback.
Expand|Select|Wrap|Line Numbers
  1. If txbAge.Text = String.Empty Then
  2. MsgBox("Wie Alt bist du?")
  3.  
  4. ElseIf txbSemester.Text Is Nothing Then
  5. MsgBox("In welchem Semester bist du?")
  6.  
  7. ElseIf txbMajor.Text = String.Empty Then
  8. MsgBox("Was studierst du")
  9.  
  10. ElseIf female.Checked = False And male.Checked = False Then
  11. MsgBox("Was ist dein Geschlecht?")
  12. Else 
  13. Me.Hide()
  14. AnagramExample.ShowDialog()
  15. End If
  16.  
Jul 22 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
3
by: Derek | last post by:
I am trying to add the text of several textboxes as a sum using the + sign but even converting to integer it is concatenating. Any help would be greatly appreciated. Dim price1 As...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
7
by: RC | last post by:
I have a form with five text boxes on it. The format for all the boxes is set as General Number. In four of the boxes the user can enter a number, the fifth box totals up the values in the other...
4
by: Enterprise | last post by:
Hi, I have 25 text boxes in a form. Lets say TB1 through TB25 are the Names of the boxes. They have no controll sources. I want to be able to check whether the text box is empty. Is there anyway I...
7
by: Mark | last post by:
Hi All, I have a report which is based on a query which is used to produce QC check sheets. I have quite a few text boxes which are used to display questions depending on the value of one...
0
by: Marty U. | last post by:
I am building a 3 level deep heirarchy tree for an application requirement. I need the ability at any level to add an item to the tree. However, when something is added all 3 levels must be...
1
by: adarshyam | last post by:
can anybody tel me how to clear values from dynamically created text boxes?? using a clear button.. this is the code used to create dynamic text boxes.. if i press clear button then it must clear all...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
12
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi i have a problem. I have 7 text boxex with different id's. I want to run a script via AJAX and i want to populate the result of the script in to these text boxes. The code is function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.