How can I declare the txt.InitialValue.text, txtSalvageValue.Text and TxtAssetLife.Text part of this code? Thanks in advance for any help.

msngInitialValue = ToSingle(txtInitialValue.Text)
        msngSalvageValue = ToSingle(txtSalvageValue.Text)
        mintAssetLife = ToInt32(txtAssetLife.Text)

Recommended Answers

All 13 Replies

How can I declare the InitialValue.text, txtSalvageValue.Text and TxtAssetLife.Text part of this code?

You do not declare InitialValue.text you just declare variable as textbox.
textbox has many properties one of them is text
we access properties of InitialValue variable by typing InitialValue. what comes after its property

to declear textbox

Dim InitialValue as New TextBox
Me.Controls.Add(InitialValue)

see this link to understand textbox more

p.s. i assumed your variables of type textbox

Thank you, I am new to vb.net and do not understand some of it. I will give that at try.

I tried using that and it still says that the (txtInitialValue.Text),(txtSalvageValue.Text),
(txtAssetLife.Text) are not declared.

write your code here please

I tried using that and it still says that the (txtInitialValue.Text),(txtSalvageValue.Text),
(txtAssetLife.Text) are not declared.

You have asked this same question repeatedly and been given help on it. Go back and re-read all of your threads here.

It keeps coming up that it is not declared. I have read and tried all the suggestions and it still does not work.
Those statements keep coming up that they need declared. I am new to this and DO NOT understand all of it, which is why I asked for help on it.

The part in red is what keeps saying it is not declared no matter what I have tried.

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

        Dim InitialValue As New TextBox
        Me.Controls.Add(InitialValue)
        Dim SalvageValue As New TextBox
        Me.Controls.Add(SalvageValue)
        Dim AssetValue As New TextBox
        Me.Controls.Add(AssetValue)

        Dim ppdDepreciation As PrintDialog

        msngInitialValue = ToSingle(txtInitialValue.Text)
        msngSalvageValue = ToSingle(txtSalvageValue.Text)
        mintAssetLife = ToInt32(txtAssetLife.Text)

Dim InitialValue As New TextBox
Me.Controls.Add(InitialValue)
Dim SalvageValue As New TextBox
Me.Controls.Add(SalvageValue)
Dim AssetValue As New TextBox
Me.Controls.Add(AssetValue)

Dim ppdDepreciation As PrintDialog

msngInitialValue = ToSingle(txtInitialValue.Text)
msngSalvageValue = ToSingle(txtSalvageValue.Text)
mintAssetLife = ToInt32(txtAssetLife.Text)

Variables that you declared are different from what you used .

I made a few changes to the code you posted and I am not getting that error that they are not declared. Thanks for your help Manal. It is throwing an exception but I will figure that out.

Why are you creating your textboxes in the button click event? This doesn't make sense.. you are adding textboxes after the user clicks a button, then, without user input you are trying to perform a mathmatic operation on their values? unless you are setting these with initial values you should add the text box controls at design time to your windows or web form(s).

Why are you creating your textboxes in the button click event? This doesn't make sense.. you are adding textboxes after the user clicks a button, then, without user input you are trying to perform a mathmatic operation on their values? unless you are setting these with initial values you should add the text box controls at design time to your windows or web form(s).

Which is the same thing we told him a week ago in a different thread. His logic is poor and it is the basis of his problem.

Which is the same thing we told him a week ago in a different thread. His logic is poor and it is the basis of his problem.

I also stated in BOTH threads that I was new to VB.net. What some suggested DID NOT WORK and I don't know enough about it to fix it, which is why I asked for help. BTW I am not a HE i am a she. Manal's response came close to fixing the problem with a few tweaks. I am sure you did not know everything just learning VB so don't be so negative in your post. I am sorry I am not as smart as you are.

I'm not trying to be negative and I am sorry if you took it that way. I'm trying to point you in the right direction without writing your code for you. That would teach you nothing.

Read what bbqchickenrobot said, as it is pretty close to what I said, i.e., it is illogical to create controls on the fly and then try to pull values out of them before any value has been put in them. It doesn't matter if you write in VB.NET, VB6, C#, C++, Pascal or any other language.

You do have a few problems with the syntax of the language and you seem to be learning about and correcting those issues as they come up, which is what we all do. But outside of the syntax issues is the bigger logic issue, on which you do not seem to want to take guidance.

I'm not here to lord over anyone or prove any superiority; I'm here to help people who want help and to get help when I need it, and I need it often. I have been writing in VB.NET for only three months. Like you I make a ton of syntax errors and then work to correct them. The difference is that I rarely make logic errors, but then, I have been writing code for a very long time.

Show us where your code is at now and we can point you in the right direction. It sounds like you corrected the syntax issues, but still have the underlying logic problems, but if you don't show us the code we really can't tell.

Sorry for assuming you were a "he," most programmers are.

I also stated in BOTH threads that I was new to VB.net. What some suggested DID NOT WORK and I don't know enough about it to fix it, which is why I asked for help. BTW I am not a HE i am a she. Manal's response came close to fixing the problem with a few tweaks. I am sure you did not know everything just learning VB so don't be so negative in your post. I am sorry I am not as smart as you are.

Hey - if you are new and struggling with this concept (which we all had struggle in the beginning of our programming lives) then the best recommendation I have for you (to save you headaches and discouraging failed attempts) is to get Francesco Balena's book on Visual Basic 2005 (I don' think the 2008 book is available yet) .... you won't need to know the advanced (new) features of 2008 yet as you have to learn the basics without adding layers of complexity. You are using Windows forms and 2008 moves to a new model called WPF - but you should learn what you're dealing with now first.

Secondly, nobody is ripping on you - don't take things to heart here or on the net in general. Anyhow - glad your a she - I assumed "he" as well lol as most coders/programmers are. Programming isn't about being smart in most cases.... it's about experience/knowledge... that's all... it's also about knowing and have good resources. That IMO is the most crucial. Looks like you have found that resource here adn you just need one more... which is that book I recommended to you ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.