-
Plz help im very new to this
Hello im really new to this, and I have a problem with some code. I need to make a form for users to enter two values to raise one number to a power, the calculator should use the exponential operator to calculate the result of raising the first number to the second.
Here's what I got:
'Calculate txtBase raised to 'x' power and display in lblResult
lblResult.Text = Val(txtBase.Text) ^ txtExponent
When I debug the program it says that there were build errors and it also says "Declaration Expected", It says that the problem is with "lblResult"
This is my second program that I have ever made, I am an extreme beginner lol, Plz Plz Plz Help me!
-
Do you have a label on your form named lblResult? Also, labels do not have a .Text property; try changing it to lblResult.Caption.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
im so lost :(
I still can't get it I actually have a step by step guide but it doesn't say anything about errors, and I followed all of the steps correctly. Here's the steps:
1.start visual studio 2005 and open a new project. save the project as exponent.
2.use the textbox tool to insert two text boxes with one slightly above and to the right of the other one. the lower text box should be named txtBase, and the upper text box should be named txtExponent. change the text property for both text boxes to 0.
3.use the label tool to add the label for the equal sign. it should be named lblEqual, and the caption should be the = sign. change the font size property to 14 point.
4.use the label tool to add a blank label to the right of the equal sign. it should be named lblResult, and the caption should be deleted. the font should also be 14 point.
5.add a Calculate button.
6.give your form an appropriete title for the title bar.
7.add code to the Calculate button so that the text value of the label named lblResult will contain the answer of the number entered for txtBase raised to the number entered for txtExponent.
8.close the code window, start debugging the program, enter a value for the base (the lower text box) and a value for the exponent (the upper text box), and click Calculate.
9.end the program.
10.save your program and close the project.
I did all of that right and I did it over about 10 times and its still the same.
Plz help T_T
-
OK, first of all, you posted to the VB Classic forum, which is for questions about VB6 and earlier, so disregard my previous reply about the label's .Caption property. I have moved your question to the .NET forum.
Try changing the code in your button's Click event to this:
lblResult.Text = Val(txtBase.Text) ^ Val(txtExponent.Text)
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
?thats weird it still doesn't work?
-
What? Do you get any errors or messages?
-
yah it says that there were still build errors and they say that the declaration is expected, the only thing that I can think of is something in the properties went wrong but I can't find anything?
-
The previous code worked but I modified it to a more .net syntax. Val is a VB 6 carry-over. Its not bad but to learn .net you should use .net
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Make sure each has something in them
If txtBase.Text.Length > 0 And txtExponent.Text.Length > 0 Then
lblResult.Text = CStr(CType(txtBase.Text, Double) ^ CType(txtExponent.Text, Double))
End If
End Sub
-
Yay it worked thank you so much for helping me :P
Similar Threads
-
By exo15 in forum VB Classic
Replies: 4
Last Post: 11-24-2006, 08:25 AM
-
Replies: 2
Last Post: 06-22-2006, 12:12 PM
-
By Apocalyp5e in forum Java
Replies: 11
Last Post: 12-22-2005, 09:03 PM
-
Replies: 4
Last Post: 08-10-2005, 10:30 AM
-
By nsbscool in forum Java
Replies: 1
Last Post: 05-02-2005, 08:01 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|