473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Defining a variable

I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

would work but in this program side1.text will be filled
later when the other data is computed, so I need to figure
out a way for it to just ignore it until that happens, any
help would be appreciated. Thanks.
-Adam

Nov 20 '05 #1
4 1158
exactly as you said except =<>

If Side1.Text <> "" Then s1=cdbl(Side1.Text)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Adam" <ad**@vampiressuck.com> wrote in message
news:08****************************@phx.gbl...
I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

would work but in this program side1.text will be filled
later when the other data is computed, so I need to figure
out a way for it to just ignore it until that happens, any
help would be appreciated. Thanks.
-Adam

Nov 20 '05 #2
Try

s1 = Val(side1.Text)

this will return 0 if text is not numeric.

You may need to make a reference to the VB6 compatibility lib.

You can test "side1.Text" if Val is 0

"Adam" <ad**@vampiressuck.com> wrote in message
news:08****************************@phx.gbl...
I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

would work but in this program side1.text will be filled
later when the other data is computed, so I need to figure
out a way for it to just ignore it until that happens, any
help would be appreciated. Thanks.
-Adam

Nov 20 '05 #3
yes, but this would then falsely give a numeric value from a non numeric
input. I would suggest.

1.) Trap the keydown event and only allow numerics and decimal points (
make sure only one decimal point exists )

2.) Test as suggested for the box being empty before assigning the value
OHM

Michael Fitzpatrick wrote:
Try

s1 = Val(side1.Text)

this will return 0 if text is not numeric.

You may need to make a reference to the VB6 compatibility lib.

You can test "side1.Text" if Val is 0

"Adam" <ad**@vampiressuck.com> wrote in message
news:08****************************@phx.gbl...
I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

would work but in this program side1.text will be filled
later when the other data is computed, so I need to figure
out a way for it to just ignore it until that happens, any
help would be appreciated. Thanks.
-Adam


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #4
* "Adam" <ad**@vampiressuck.com> scripsit:
I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)
How is 's1' defined?
This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if


\\\
Dim s1 As Double
If Double.TryParse(side1.Text, Nothing, s1) Then
MsgBox(s1.ToString())
Else
MsgBox("No number!")
End If
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

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

Similar topics

2
by: Sriram Chadalavada | last post by:
Hello everyone, I am a newbie to Python with experience in C programming. For my project, I am re-writing C routines as Python functions. I am currently using raw numerical values and was...
0
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they...
2
by: Hamish Symington | last post by:
Hello, I'm trying to re-code a site which I wrote in PHP into ASP.NET using Visual Basic .NET. Something PHP has which has proved invaluable is the concept of variable variables. I haven't...
10
by: nambissan.nisha | last post by:
I am facing this problem.... I have to define a structure at runtime as the user specifies... The user will tell the number of fields,the actual fields...(maybe basic or array types or...
11
by: Rahul | last post by:
Hi, Is the following correct? Here i have declaread a char array in case 1: and am using the same in case 2: first I tried another definition of ch in case 2: assuming that if i=2 then char ch...
1
by: Gary Wessle | last post by:
Hi can I declare an ofstream in a class declaration in .h file and define it inside a method in the .cpp file? if so, what does the syntax of defining it looks like. I tried .... ofstream...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
1
by: mrsmith221189 | last post by:
Hello everyone. I'm a novice to XML/XSL so it would be great to learn from the experts. The ouput of my xml file is BBC EPG(Electronic Programme Guide) table. I'm having problems defining a...
2
by: ismailc | last post by:
Hi, I don't know xml. The stylesheet identifies all the objects from DB & as it reads through the DB, it checks the next object "for-each", I need to check the third object as well & define within...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.