Click here to Skip to main content
16,004,406 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.
I am a very novice coder with only 3 weeks experience. This is the first time I have posted here and this code is for a university assignment. I am using Visual Studio 2010 with visual basic settings.

My problem is that for my assignment, I am required to make a status box made up of a label to display messages regarding the program. e.g. if nothing is inputted into a textbox the status box will show the message "No data has been inputted".

I am able to show the messages alright but the assignment asks to display messages consecutively in the label/status box. Every time I put up a message into the label/status box, it overwrites the old message.

Does anyone know how to put consecutive messages into a label?

Thanks in advance,

A Novice Coder.
Posted
Comments
Gary Vasquez from Unknown 23-Feb-24 16:23pm    
how do you label multiple variables in visual studio?

1 solution

The idea to concatenate any existing text in the label with new text from the textbox, in vb.net, you use & to concatenate.
Say you label will add text from textbox upon a button click, see the following example:
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text.Trim.Count > 0 Then
        Label1.Text = Label1.Text & ", " & TextBox1.Text
    End If
End Sub

I have wrapped the concatenation in an If block, do you know why?

++++++++++++++++++++++++++++++++++++++++++++

I have seen your response, it is not anywhere near your original question. However, I will answer that:
If I understand you correctly now, you are trying to concatenate txtScore1.text and txtScore2.text into the lblBox right?
VB
lblBox.Text = txtScore1.Text & ", " & txtScore2.Text

Isn't this the same idea that I have provided in the above solution.
In addition, you should improve the construction of your program, the hint is you do not have to repeatedly assigning the textbox text to the label box at every if statement, just need to do it once at the end of all the if statements. Specifically how? I shall leave it as homework after all it is, isn't it.
 
Share this answer
 
v6
Comments
Member 10690012 22-Mar-14 1:18am    
I may have mislead you a bit. I understand how to use if statements, it is just how to put multiple lines of text in a label.

Private Sub Score1Messages()
'The purpose of this code is to display the appropriate message for the relevent restrictions
'The if statement directs the code on a path via the conditions that are set
If txtScore1.Text = "" Then 'The condition set here is if the textbox is empty, the message is displayed.
lblBox.Text = "No data inputed into Score 1."
ElseIf Not IsNumeric(txtScore1.Text) Then
lblBox.Text = "The inputed data is not numeric." 'The condition set here is if the inputed data is not numeric, the message is displayed
ElseIf txtScore1.Text < 0 Or txtScore1.Text > 10 Then
lblBox.Text = "The inputed data is not within the Valid range." 'The condition set here is if the inputed data is within the specifiyed range of the condition, the message is displayed
Else
lblBox.Text = "The inputed data is Valid." 'The condition set here is if the inputed data does not match any of the other conditions, the message is displayed
End If
End Sub

This code is for textbox 1. It appears in the status box fine.

Private Sub Score2Messages()
'The purpose of this code is to display the appropriate message for the relevent restrictions
'The if statement directs the code on a path via the conditions that are set
If txtScore2.Text = "" Then 'The condition set here is if the textbox is empty, the message is displayed.
lblBox.Text = "No data inputed into Score 2."
ElseIf Not IsNumeric(txtScore2.Text) Then
lblBox.Text = "The inputed data is not numeric." 'The condition set here is if the inputed data is not numeric, the message is displayed
ElseIf txtScore2.Text < 0 Or txtScore2.Text > 10 Then
lblBox.Text = "The inputed data is not within the Valid range." 'The condition set here is if the inputed data is within the specifiyed range of the condition, the message is displayed
Else
lblBox.Text = "The inputed data is Valid." 'The condition set here is if the inputed data does not match any of the other conditions, the message is displayed
End If
End Sub

But when I refer to the messages for textbox2, the message overwrites any message for textbox 1 in the label/status box.
Peter Leow 22-Mar-14 1:37am    
See my reply in solution 1.
Member 10690012 22-Mar-14 1:52am    
This is an image of the sample interface of the assignment.
http://tinypic.com/r/a0we9t/8

These are the instructions pull from the assignment

Add code so that when the user clicks the
Validate
button, each of the textboxes
is validated.
1. Begin by clearing the Status Box
2.
Add
the single most appropriate message below to the S
tatus Box
o
Score 1 is blank
o
Score 1 is not numeric
o
Score 1 is not in the range: 0-10
o
Score 1 is valid
3. Repeat step 2 for Score 2, Score 3 and Score 4
4. Examine Category value.
Add
the single most appropriate message to the
Status Box
o
Category is blank
o
Category is not a valid value: A, B or C
o
Category is valid
Category values are valid in both lowercase and upp
ercase
The following are
examples
of the text output in the Status Box:
Score 1 is valid or Score 1 is valid
Score 2 is blank or Score 2 is valid
Score 3 is not in the range 0-10 or Score 3 is va
lid
Score 4 is not numeric or Score 4 is valid
Category is not a valid value: A, B or C or Categor
y is valid

But I got stuck when the assignment says to ADD to status update to the status box. I can input the appropriate message but it always overwrites the previous one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900