473,657 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a variable to accept Decimals.

I'm using VS2005 and creating a simple test ASPX page in VB.

I have a simple FORMVIEW1 with a label "YTDLabel" databound to a SQL DB.
The DB datatype is set to decimal (18,2) and the value of this cell is 16.1.
Here is my simple Page_Load code and all I want it to do is see if the
decimal figure is greater than 1, if it is, then hide the YTDLabel. The
error message I'm getting from VS2005 is that
FormView1.FindC ontrol("YTDLabe l") is underlined and it says "Value fo Type
'System.Web.UI. Control' can not be converted to 'Decimal'". Can someone
help me out? I'm just a newbie trying to learn. Thanks!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Dim YTDtest As Decimal
YTDtest = FormView1.FindC ontrol("YTDLabe l")

If YTDtest 0 Then
FormView1.FindC ontrol("YTDLabe l").Visible = False
End If
End Sub

Oct 10 '06 #1
4 1535
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(Y TDLabel.Text)

Oct 10 '06 #2
Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

If YTDtest 0 Then

FormView1.FindC ontrol("YTDLabe l").Visible = False

End If

End Sub


"Gozirra" <rm********@hot mail.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(Y TDLabel.Text)

Oct 10 '06 #3
The type is a Decimal. Decimal.Parse converts the value of the labels
text property to a decimal type and assigns it to your variable. I
have tested a very simple example of this to make sure it works and
have had no problems. Can you step through the code and see what's
going on? I wonder if the FormView is causing problems. My small
sample does not use a FormView and works perfectly.

Phillip Vong wrote:
Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

If YTDtest 0 Then

FormView1.FindC ontrol("YTDLabe l").Visible = False

End If

End Sub


"Gozirra" <rm********@hot mail.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(Y TDLabel.Text)
Oct 11 '06 #4
This is what someone else told me to use and it worked. Gozirra, thanks for
your help!!!

Dim YTDLabel As Label
YTDLabel = DirectCast(Form View1.FindContr ol("YTDLabel") , Label)

Dim YTDtest As Decimal
YTDTest = Decimal.Parse(Y TDLabel.Text)



"Gozirra" <rm********@hot mail.comwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
The type is a Decimal. Decimal.Parse converts the value of the labels
text property to a decimal type and assigns it to your variable. I
have tested a very simple example of this to make sure it works and
have had no problems. Can you step through the code and see what's
going on? I wonder if the FormView is causing problems. My small
sample does not use a FormView and works perfectly.

Phillip Vong wrote:
>Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to
see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventAr gs)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

If YTDtest 0 Then

FormView1.Find Control("YTDLab el").Visible = False

End If

End Sub


"Gozirra" <rm********@hot mail.comwrote in message
news:11******* *************** @m73g2000cwd.go oglegroups.com. ..
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(C Type(FormView1. FindControl("YT DLabel"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(Y TDLabel.Text)

Oct 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
7192
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be created if they don't already exist, and if the drive happens to be one a folder cannot be created on (ie a cdrom drive) it would just be skipped without the code generating any errors. your help on this would be most appreciated. jenny
5
9826
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ------------------------------------------------------ static void addQuantity(int rowNum, int oldQuantity) { int newQuantity = oldQuantity++; SqlConnection thisConnection = new SqlConnection (@"Data Source=(local);Integrated Security=SSPI;" +
1
2524
by: kennethfine | last post by:
I'm transitioning from ASP development, please excuse these basic questions. One thing I did often in ASP was create a "translate" function to render one string to another, strip out excess carriage returns, etc. I want to do the same thing in ASP.NET. I have a mail component that will accept HTML, but it requires all HTML to be listed on a single line. It takes the syntax: msgObj.BodyParts.Add(" <html markup here> "),
12
3153
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass something else that strings between the domains...
1
2033
by: hygum | last post by:
I've found a useful script that only accepts numbers and a point, and 3 decimals, in an input. But here in denmark we normally use comma as decimal delimiter in numbers, not the point (.) as in english-speaking countries. Can somebody help me making this javascript accept comma as delimiter in the input? I'm thinking that the best solution is that the script converts comma to a point, when the user input a comma. ...
5
1994
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
1
1569
by: dixonjm | last post by:
Hi, I have been given a task to monitor all user behaviour on our web site, this has to include capturing all values of any control which have been changed. I really want to create a standalone module which will do this for me, we have created our own controls - eg a IntegerTexBox that will only numbers, and a floatTextBox which will only accept decimals, and I am wondering if I could add method, or override an existing method, in these...
7
6828
by: nussu | last post by:
Hi, Plz provide me javascript : javascript for a textbox to accept the values in decimals and within range i need to enter a value in textbox like 1.03 and it should be <3 (lessthan 3). Plz help me. Rgds,
12
2090
by: CNiall | last post by:
I am very new to Python (I started learning it just yesterday), but I have encountered a problem. I want to make a simple script that calculates the n-th root of a given number (e.g. 4th root of 625--obviously five, but it's just an example :P), and because there is no nth-root function in Python I will do this with something like x**(1/n). However, with some, but not all, decimals, they do not seem to 'equal themselves'. This is...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.