Click here to Skip to main content
14,427,893 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have the X-axis and also legends in my chart which are linked whit text-boxes. every text-box is under randomize value and name means don't have special or static name of number it depends on user inserted data. Sometime when there is same name or numbers in two or more then tow text-boxes after debugging VB form the chart show message (A chart element with the name ' ' already exists in the series collection) the ting is I have to include those text-boxes which have the same name, means I cannot ignore them because every text-box data is impotent. So please how can I prevent this message by using code. thanks 

What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            Me.Chart1.Series(Form3.TextBox6.Text).Points.AddXY(Form3.TextBox6.Text, Val(Form3.txtpi1.Text))
            Me.Chart1.Series(Form3.TextBox17.Text).Points.AddXY(Form3.TextBox17.Text, Val(Form3.txtpi2.Text))
            Me.Chart1.Series(Form3.TextBox23.Text).Points.AddXY(Form3.TextBox23.Text, Val(Form3.txtpi3.Text))
            Me.Chart1.Series(Form3.TextBox29.Text).Points.AddXY(Form3.TextBox29.Text, Val(Form3.txtpi4.Text))
            Me.Chart1.Series(Form3.TextBox35.Text).Points.AddXY(Form3.TextBox35.Text, Val(Form3.txtpi5.Text))

        Catch ex As Exception
        End Try
    End Sub
Updated 28-Oct-19 23:42pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The name is pretty self explanatory: you are trying to add a series to the collection, but a series with the same name is already included. Names have to be unique! At a guess, one or more of your textboxes have duplicate information, probably a space.

But we can't tell, because we don't have access to you code while it's running!
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

And two details, you should think about:
1) Stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
2) At least 35 text boxes on one form? You might want to consider your design - that's not user friendly at all. Consider breaking the form up into tab pages or smaller forms, and using UserControls to "group" related information together. Just chucking controls on a form makes for a very confused interface,m and that promotes input errors and mistakes - and if they reach a DB, it can take considerable work to fix the problems that generated down the line.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,178
Richard MacCutchan 1,899
phil.o 1,270
Patrice T 1,237
MadMyche 1,185

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100