By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Selecting Proper Variables

P: n/a
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

Nov 21 '05 #1
Share this Question
Share on Google+
42 Replies


P: n/a
Dooglo,

Converting in Visual basic is very easy.

A text in the textbox text property is a String, however to use it as an
Integer you can (after testing that it is completly numeric) do
myvalue as integer = CInt(mytextbox.text)

When it is not completly numeric where - and plus are signs, than it will
throw an error.

Doing this back from text to int you can do

mytextbox.text = Cstr(myvalue) however mostly is used here
mytextbox.text = myvalue.ToString

I hope this helps so far?

Cor
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not valid." Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12) / 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

Nov 21 '05 #2

P: n/a
The problem is that you aren't checking the textboxes for no data, you are
checking for a space character, rather than and empty string:

If Me.txtLInch.Text = " " Then TInch = 0
....should be...
If Me.txtLInch.Text = "" Then TInch = 0

So, when no data is entereed, it is not getting set to zero and when you try
to take the textbox value and set it into the integer varaible, you are
tring to take an empty string and make it become an integer which is what
the error message is reporting.

Second, I think it is better to keep the feet and inches as separate
textboxes, rather that try to make them one.

Third, I don't think you'll need your variable declared as Public unless you
intend to use them in another class so Private will do.

Next, you can combine the check for no data and the assignment of a value to
one If statement:

'Check for empty textboxes
If txtLInch.Text = "" Then
TInch = 0
Else
TInch = CType(txtTInch.Text, Integer)
End If

Next, the use of the keyword "Me" is certainly ok, but not required and can
make your statements cleaner to write. Instead of:

If Me.WInch = 0 And Me.LInch = 0 Then
Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet
Else
Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))
Me.SqrFeet = Me.txtSqrFeet.Text
End If

You can write:

If WInch = 0 And LInch = 0 Then
txtSqrFeet.Text = LFeet * WFeet
Else
txtSqrFeet.Text = (LFeet + (LInch / 12)) * (WFeet + (WInch / 12))
SqrFeet = txtSqrFeet.Text
End If
Good Luck!


"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user
inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not
valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

Nov 21 '05 #3

P: n/a
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not valid." Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12) / 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

Nov 21 '05 #4

P: n/a
Dooglo,

hmmm.

Well,

Split function is easy
just like
dim SomeStrings() as string=WhateverString.Split(";")
where ; is the separator--this would build a string array "SomeString" where
; was the separator to determine separate strings.

Now in making text boxes for this... I have 2 suggestions.
One if you are going to use text boxes, don't include the units.... the
double quote is a special char anyway and might cause you some
problems...besides you only need the numbers
So Idea #1

[Use the Up/Down Numeric Control] <labelcontrol here that has 'feet'> [Use
the Up/Down Numeric Control] <labelcontrol here that has the word 'inches'
or if you prefer the "

This avoids the issues of having any chars--just whole numbers.

Idea #2
If you have a very limited number of expected lengths and widths you might
use one combo box for each and fill it will all possible lengths....like
1foot, 1 inch, etc or 1' 1"

and of course each combo item would be from a class that has a property for
feet and one for inches and overrides tostring to show them together(that's
what the combobox uses to display)

I'm not sure which way you would prefer--if there will be too many
combinations, Idea 1 is better... and users may prefer idea #1

don't use "" for empty string, use string.empty----(doing so is more
efficient)

using the numeric control(again don't remember it's name and not in the IDE
right now, but it is an updown control that only allows numbers) instead of
a text box
you could say
TInch=CStr(YourNumericControlInches.Text) (or maybe .Value instead of
..Text; don't remember)

That way it will always have some value and you shouldn't get the error...
they will have to at least have 0 in the numeric control.

Hope this helps some....

Shane
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not valid." Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12) / 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #5

P: n/a
oops... I meant use CInt()
instead of CStr()

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dooglo,

hmmm.

Well,

Split function is easy
just like
dim SomeStrings() as string=WhateverString.Split(";")
where ; is the separator--this would build a string array "SomeString" where ; was the separator to determine separate strings.

Now in making text boxes for this... I have 2 suggestions.
One if you are going to use text boxes, don't include the units.... the
double quote is a special char anyway and might cause you some
problems...besides you only need the numbers
So Idea #1

[Use the Up/Down Numeric Control] <labelcontrol here that has 'feet'> [Use the Up/Down Numeric Control] <labelcontrol here that has the word 'inches'
or if you prefer the "

This avoids the issues of having any chars--just whole numbers.

Idea #2
If you have a very limited number of expected lengths and widths you might
use one combo box for each and fill it will all possible lengths....like
1foot, 1 inch, etc or 1' 1"

and of course each combo item would be from a class that has a property for feet and one for inches and overrides tostring to show them together(that's what the combobox uses to display)

I'm not sure which way you would prefer--if there will be too many
combinations, Idea 1 is better... and users may prefer idea #1

don't use "" for empty string, use string.empty----(doing so is more
efficient)

using the numeric control(again don't remember it's name and not in the IDE right now, but it is an updown control that only allows numbers) instead of a text box
you could say
TInch=CStr(YourNumericControlInches.Text) (or maybe .Value instead of
.Text; don't remember)

That way it will always have some value and you shouldn't get the error...
they will have to at least have 0 in the numeric control.

Hope this helps some....

Shane
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

my program works and figures out the correct answer. But when I enter it differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /

12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27
End Sub
I know that I'm using the wrong variables here, I can't quit figure it out though.

Thanks to Anyone Who Replies.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #6

P: n/a
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
I'm writting a program to figure square feet and yards when the user inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.


Turn on 'Option Strict On' and take a look at the 'C*' functions
('CInt', ...).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

P: n/a
But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user

inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /

12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27
End Sub
I know that I'm using the wrong variables here, I can't quit figure it out though.

Thanks to Anyone Who Replies.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #8

P: n/a
Thanks - never even realized string.empty was there. I'll be sure to use
that in the future.

Wayne

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OX*************@TK2MSFTNGP10.phx.gbl...
But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.
My question is;

I'm writting a program to figure square feet and yards when the user inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet + (Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
/
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))

/ 27
End Sub
I know that I'm using the wrong variables here, I can't quit figure it out though.

Thanks to Anyone Who Replies.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004

Nov 21 '05 #9

P: n/a
you should check the contents of the text boxes first to see if they can be
converted to numbers. - (use the isnumeric function)
then you should convert to and assign to -> variables of a numeric data
type - like double.
then use the numeric variables to do your calculations.
by the way - at the top - you should type 'option strict on' and 'option
explicit on'
vb 6.0 was much easier to learn for newbies.
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not valid." Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12) / 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #10

P: n/a
IsNumeric doesn't always give you an accurate answer though.

124EZ would be considered numeric, but would show up as 12
EZ12 would not be considered numeric

Using regular expressions would be better.
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Io*******************@bignews1.bellsouth.net. ..
you should check the contents of the text boxes first to see if they can
be
converted to numbers. - (use the isnumeric function)
then you should convert to and assign to -> variables of a numeric data
type - like double.
then use the numeric variables to do your calculations.
by the way - at the top - you should type 'option strict on' and 'option
explicit on'
vb 6.0 was much easier to learn for newbies.
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user

inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a
single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /

12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) /
27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it
out
though.

Thanks to Anyone Who Replies.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

Nov 21 '05 #11

P: n/a
Regular expressions - as you say is the best approach - but the OP is new to
programming
Regular expressions to a newbie is pretty intimidating. But is worth
learning - for any language.
"Scott M." <s-***@nospam.nospam> wrote in message
news:O3**************@TK2MSFTNGP15.phx.gbl...
IsNumeric doesn't always give you an accurate answer though.

124EZ would be considered numeric, but would show up as 12
EZ12 would not be considered numeric

Using regular expressions would be better.
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Io*******************@bignews1.bellsouth.net. ..
you should check the contents of the text boxes first to see if they can
be
converted to numbers. - (use the isnumeric function)
then you should convert to and assign to -> variables of a numeric data
type - like double.
then use the numeric variables to do your calculations.
by the way - at the top - you should type 'option strict on' and 'option explicit on'
vb 6.0 was much easier to learn for newbies.
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user

inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a
single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
/ 12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) /
27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it
out
though.

Thanks to Anyone Who Replies.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #12

P: n/a
I know brother... there's too much for any of us to know it all.
Thank goodness we have this group. :)

Shane

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:um*************@TK2MSFTNGP09.phx.gbl...
Thanks - never even realized string.empty was there. I'll be sure to use
that in the future.

Wayne

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OX*************@TK2MSFTNGP10.phx.gbl...
But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...

> I'm new VB and programming all together, but I'm getting he hang of it. >
> My question is;
>
> I'm writting a program to figure square feet and yards when the user
inputs
> "Length in feet and inch ( seperate boxes), Width in feet and inches
> (seperate boxes), and thickness in feet and inches (all so in seperate > boxes). I haven't quit figured out the split function yet to use a single
> text box for each. Anyways, when I enter data in each box; eg.
>
> Length 2' 0"
> Width 2' 0"
> Thickness 0' 4"
>
> my program works and figures out the correct answer. But when I enter
it
> differently, like this;
>
> Lenght 2' not entering inches leaving box empty
> Widht 2' not entering inches leaving box empty
> Thickness not entering feet leaving box empty but entering 4"
>
> it gives me an error "Cast from string " " to type 'Integer' is
not valid."
> Here is some of what Ive written.
>
>
> Public LFeet, WFeet, TFeet As Integer
> Public LInch, WInch, TInch As Integer
> Public SqrFeet, Yard As Integer
>
> Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles btnCompute.Click
>
> If Me.txtLInch.Text = " " Then TInch = 0
> If Me.txtWInch.Text = " " Then WInch = 0
> If Me.txtTFeet.Text = " " Then TInch = 0
>
> Me.LFeet = Me.txtLFeet.Text
> Me.LInch = Me.txtLInch.Text
> Me.WFeet = Me.txtWFeet.Text
> Me.WInch = Me.txtWInch.Text
> Me.TFeet = Me.txtTFeet.Text
> Me.TInch = Me.txtTInch.Text
>
> If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =
Me.LFeet
> * Me.WFeet Else
>
> Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) *
(Me.WFeet + > (Me.WInch / 12))
>
> Me.SqrFeet = Me.txtSqrFeet.Text
>
> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *
(Me.TInch
/ 12)
> / 27) Else
>
> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /
12))) /
27
>
> End Sub
>
>
> I know that I'm using the wrong variables here, I can't quit figure

it out
> though.
>
> Thanks to Anyone Who Replies.
>
>
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #13

P: n/a
Why bother with either when there is already an up down control that only
takes numbers???

Seems to me the more logical choice in this circumstance... But if I were
going to use a textbox,
I'd trap the keypress event and only allow ASCII values for digits or "." or
Backspace

And of course check to allow only one "."

Seems easier to just use the numeric control.

My 2 cents....

Shane
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Y5*******************@bignews1.bellsouth.net. ..
Regular expressions - as you say is the best approach - but the OP is new to programming
Regular expressions to a newbie is pretty intimidating. But is worth
learning - for any language.
"Scott M." <s-***@nospam.nospam> wrote in message
news:O3**************@TK2MSFTNGP15.phx.gbl...
IsNumeric doesn't always give you an accurate answer though.

124EZ would be considered numeric, but would show up as 12
EZ12 would not be considered numeric

Using regular expressions would be better.
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Io*******************@bignews1.bellsouth.net. ..
you should check the contents of the text boxes first to see if they can be
converted to numbers. - (use the isnumeric function)
then you should convert to and assign to -> variables of a numeric data type - like double.
then use the numeric variables to do your calculations.
by the way - at the top - you should type 'option strict on' and 'option explicit on'
vb 6.0 was much easier to learn for newbies.
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
> I'm new VB and programming all together, but I'm getting he hang of it.>
> My question is;
>
> I'm writting a program to figure square feet and yards when the user
inputs
> "Length in feet and inch ( seperate boxes), Width in feet and inches
> (seperate boxes), and thickness in feet and inches (all so in seperate> boxes). I haven't quit figured out the split function yet to use a
> single
> text box for each. Anyways, when I enter data in each box; eg.
>
> Length 2' 0"
> Width 2' 0"
> Thickness 0' 4"
>
> my program works and figures out the correct answer. But when I enter
it
> differently, like this;
>
> Lenght 2' not entering inches leaving box empty
> Widht 2' not entering inches leaving box empty
> Thickness not entering feet leaving box empty but entering 4"
>
> it gives me an error "Cast from string " " to type 'Integer' is not
valid."
> Here is some of what Ive written.
>
>
> Public LFeet, WFeet, TFeet As Integer
> Public LInch, WInch, TInch As Integer
> Public SqrFeet, Yard As Integer
>
> Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e
As> System.EventArgs) Handles btnCompute.Click
>
> If Me.txtLInch.Text = " " Then TInch = 0
> If Me.txtWInch.Text = " " Then WInch = 0
> If Me.txtTFeet.Text = " " Then TInch = 0
>
> Me.LFeet = Me.txtLFeet.Text
> Me.LInch = Me.txtLInch.Text
> Me.WFeet = Me.txtWFeet.Text
> Me.WInch = Me.txtWInch.Text
> Me.TFeet = Me.txtTFeet.Text
> Me.TInch = Me.txtTInch.Text
>
> If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =
Me.LFeet
> * Me.WFeet Else
>
> Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +> (Me.WInch / 12))
>
> Me.SqrFeet = Me.txtSqrFeet.Text
>
> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
/ 12)
> / 27) Else
>
> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))

/> 27
>
> End Sub
>
>
> I know that I'm using the wrong variables here, I can't quit figure it> out
> though.
>
> Thanks to Anyone Who Replies.
>
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #14

P: n/a
> Why bother with either when there is already an up down control that only
takes numbers???
If this is an ASP.NET Web Application, then the control you are talking
about doesn't exist (however there are validation controls to take care of
inputting only numeric values). But that wasn't what the question was.
Seems to me the more logical choice in this circumstance... But if I were
going to use a textbox,
I'd trap the keypress event and only allow ASCII values for digits or "."
or
Backspace
For a web application, this would have to be done client-side with
JavaScript (pain) and even for a Windows application it is a pretty
inefficient approach.

And of course check to allow only one "."

Seems easier to just use the numeric control.

My 2 cents....

Shane
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Y5*******************@bignews1.bellsouth.net. ..
Regular expressions - as you say is the best approach - but the OP is new

to
programming
Regular expressions to a newbie is pretty intimidating. But is worth
learning - for any language.
"Scott M." <s-***@nospam.nospam> wrote in message
news:O3**************@TK2MSFTNGP15.phx.gbl...
> IsNumeric doesn't always give you an accurate answer though.
>
> 124EZ would be considered numeric, but would show up as 12
> EZ12 would not be considered numeric
>
> Using regular expressions would be better.
>
>
> "Hal Rosser" <hm******@bellsouth.net> wrote in message
> news:Io*******************@bignews1.bellsouth.net. ..
> > you should check the contents of the text boxes first to see if they can > > be
> > converted to numbers. - (use the isnumeric function)
> > then you should convert to and assign to -> variables of a numeric data > > type - like double.
> > then use the numeric variables to do your calculations.
> > by the way - at the top - you should type 'option strict on' and

'option
> > explicit on'
> > vb 6.0 was much easier to learn for newbies.
> >
> >
> > "Dooglo" <Do****@discussions.microsoft.com> wrote in message
> > news:08**********************************@microsof t.com...
> >> I'm new VB and programming all together, but I'm getting he hang of it. > >>
> >> My question is;
> >>
> >> I'm writting a program to figure square feet and yards when the user
> > inputs
> >> "Length in feet and inch ( seperate boxes), Width in feet and inches
> >> (seperate boxes), and thickness in feet and inches (all so in seperate > >> boxes). I haven't quit figured out the split function yet to use a
> >> single
> >> text box for each. Anyways, when I enter data in each box; eg.
> >>
> >> Length 2' 0"
> >> Width 2' 0"
> >> Thickness 0' 4"
> >>
> >> my program works and figures out the correct answer. But when I enter
it
> >> differently, like this;
> >>
> >> Lenght 2' not entering inches leaving box empty
> >> Widht 2' not entering inches leaving box empty
> >> Thickness not entering feet leaving box empty but entering 4"
> >>
> >> it gives me an error "Cast from string " " to type 'Integer' is
> >> not
> > valid."
> >> Here is some of what Ive written.
> >>
> >>
> >> Public LFeet, WFeet, TFeet As Integer
> >> Public LInch, WInch, TInch As Integer
> >> Public SqrFeet, Yard As Integer
> >>
> >> Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e

As > >> System.EventArgs) Handles btnCompute.Click
> >>
> >> If Me.txtLInch.Text = " " Then TInch = 0
> >> If Me.txtWInch.Text = " " Then WInch = 0
> >> If Me.txtTFeet.Text = " " Then TInch = 0
> >>
> >> Me.LFeet = Me.txtLFeet.Text
> >> Me.LInch = Me.txtLInch.Text
> >> Me.WFeet = Me.txtWFeet.Text
> >> Me.WInch = Me.txtWInch.Text
> >> Me.TFeet = Me.txtTFeet.Text
> >> Me.TInch = Me.txtTInch.Text
> >>
> >> If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =
> > Me.LFeet
> >> * Me.WFeet Else
> >>
> >> Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) *
> >> (Me.WFeet + > >> (Me.WInch / 12))
> >>
> >> Me.SqrFeet = Me.txtSqrFeet.Text
> >>
> >> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
/
> > 12)
> >> / 27) Else
> >>
> >> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /
> >> 12)))

/ > >> 27
> >>
> >> End Sub
> >>
> >>
> >> I know that I'm using the wrong variables here, I can't quit figure it > >> out
> >> though.
> >>
> >> Thanks to Anyone Who Replies.
> >>
> >>
> >>
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
> >
> >
>
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004

Nov 21 '05 #15

P: n/a
Good plan - I do it that way too -
But- You also have to watch out for the user doing a 'Paste' into the text
box
Seems to me the more logical choice in this circumstance... But if I were
going to use a textbox,
I'd trap the keypress event and only allow ASCII values for digits or "." or Backspace

And of course check to allow only one "."


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #16

P: n/a
Shane,

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

MyString.empty
myString = Nothing
myString = ""
Are all the same

String Is Nothing catches even an not instanced string.

In this newsgroup is always told (not particulary by me) that the prefered
way was myString = "" because that shows exactly the situation. There is a
string however it holds no characters, the other ones can be confusing.

Cor
Nov 21 '05 #17

P: n/a
Scott
124EZ


When something is a numeric expression, what is than false with that, when
it is told that it is, in my opinion only when you have extra conditions,
than can your statement be true.

Cor

Nov 21 '05 #18

P: n/a
Hal,

Probably you know, however to make this thread more complete do I add this
after your name.

Therefore you should use it in my opinion in the way it is done here in the
"validating" event.

Cor
Nov 21 '05 #19

P: n/a
Thanks so much to all of you for replying to my post.
Sorry that I didn't reply back sooner.

Thanks again for the help.
"Scott M." wrote:
The problem is that you aren't checking the textboxes for no data, you are
checking for a space character, rather than and empty string:

If Me.txtLInch.Text = " " Then TInch = 0
....should be...
If Me.txtLInch.Text = "" Then TInch = 0

So, when no data is entereed, it is not getting set to zero and when you try
to take the textbox value and set it into the integer varaible, you are
tring to take an empty string and make it become an integer which is what
the error message is reporting.

Second, I think it is better to keep the feet and inches as separate
textboxes, rather that try to make them one.

Third, I don't think you'll need your variable declared as Public unless you
intend to use them in another class so Private will do.

Next, you can combine the check for no data and the assignment of a value to
one If statement:

'Check for empty textboxes
If txtLInch.Text = "" Then
TInch = 0
Else
TInch = CType(txtTInch.Text, Integer)
End If

Next, the use of the keyword "Me" is certainly ok, but not required and can
make your statements cleaner to write. Instead of:

If Me.WInch = 0 And Me.LInch = 0 Then
Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet
Else
Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))
Me.SqrFeet = Me.txtSqrFeet.Text
End If

You can write:

If WInch = 0 And LInch = 0 Then
txtSqrFeet.Text = LFeet * WFeet
Else
txtSqrFeet.Text = (LFeet + (LInch / 12)) * (WFeet + (WInch / 12))
SqrFeet = txtSqrFeet.Text
End If
Good Luck!


"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user
inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not
valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.


Nov 21 '05 #20

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
MyString.empty
myString = Nothing
myString = ""
Are all the same


They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
are not.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #21

P: n/a
Scott,

I tried what you suggested and it didn't really work. I keep getting same
error, 'to type integer Not valid'. Then I tried what some other guys said,
it didn't work. Help.

Have a look at this and you tell me OK.

Thanks again.

Dim LInch As Double
Dim LFeet As Double
Dim WFeet As Double
Dim WInch As Double
Dim TFeet As Double
Dim TInch As Double
Dim SqrFeet As Double
Dim Yard As Double

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click
If Me.txtLInch.Text Is Nothing Then LInch = 0 Else
Me.LInch = CType(Me.txtLInch.Text, Integer)

If Me.txtWInch.Text Is Nothing Then WInch = 0 Else
Me.WInch = CType(Me.txtWInch.Text, Integer)

If Me.txtTFeet.Text Is Nothing Then TFeet = 0 Else
Me.TFeet = CType(Me.txtTFeet.Text, Integer)
Me.LFeet = Me.txtLFeet.Text
'Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
'Me.WInch = Me.txtWInch.Text
'Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text
If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch / 12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub

"Dooglo" wrote:
Thanks so much to all of you for replying to my post.
Sorry that I didn't reply back sooner.

Thanks again for the help.
"Scott M." wrote:
The problem is that you aren't checking the textboxes for no data, you are
checking for a space character, rather than and empty string:

If Me.txtLInch.Text = " " Then TInch = 0
....should be...
If Me.txtLInch.Text = "" Then TInch = 0

So, when no data is entereed, it is not getting set to zero and when you try
to take the textbox value and set it into the integer varaible, you are
tring to take an empty string and make it become an integer which is what
the error message is reporting.

Second, I think it is better to keep the feet and inches as separate
textboxes, rather that try to make them one.

Third, I don't think you'll need your variable declared as Public unless you
intend to use them in another class so Private will do.

Next, you can combine the check for no data and the assignment of a value to
one If statement:

'Check for empty textboxes
If txtLInch.Text = "" Then
TInch = 0
Else
TInch = CType(txtTInch.Text, Integer)
End If

Next, the use of the keyword "Me" is certainly ok, but not required and can
make your statements cleaner to write. Instead of:

If Me.WInch = 0 And Me.LInch = 0 Then
Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet
Else
Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))
Me.SqrFeet = Me.txtSqrFeet.Text
End If

You can write:

If WInch = 0 And LInch = 0 Then
txtSqrFeet.Text = LFeet * WFeet
Else
txtSqrFeet.Text = (LFeet + (LInch / 12)) * (WFeet + (WInch / 12))
SqrFeet = txtSqrFeet.Text
End If
Good Luck!


"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.

My question is;

I'm writting a program to figure square feet and yards when the user
inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single
text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it
differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not
valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub
I know that I'm using the wrong variables here, I can't quit figure it out
though.

Thanks to Anyone Who Replies.


Nov 21 '05 #22

P: n/a
Herfried,
MyString.empty
myString = Nothing
myString = ""
Are all the same


They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
are not.

did I write Is Nothing?
Although = Nothing acts the same as Is nothing when there is no reference.

(This = Nothing is me so often told by Armin, that I keep me to that, you
never knows when he comes back to this newsgroup)

:-)

Cor
Nov 21 '05 #23

P: n/a
Correction,

= "" is told by Armin when I was using = Nothing however with a referenced
string they are the same and Armin said than it I should not do that, so I
did = "".

Cor
Nov 21 '05 #24

P: n/a
Did you see that Hefried wrote that when you put on Option Strict on you
would be warned, why you did not do that.

Dim LInch As Double
Dim LFeet As Double
Dim WFeet As Double
Dim WInch As Double
Dim TFeet As Double
Dim TInch As Double
Dim SqrFeet As Double
Dim Yard As Double

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click
If txtWInch.Text Is Nothing


'This is an impossible situation as you write it
As sample
'Dim a as String
'Now a Is Nothing
'Dim a as String = ""
'Now a = Nothing
And because Text is a Text box property it is never Is Nothing

A problem however is that you did not test for numeric
Although this is not always sufficient, it is in most cases

If IsNumeric(txtWInch.Text) then
WInch = Cdbl(WInch.Text)
Else
'Show errormessage and do something.
End if

And than the rest in the same style.

I hope this helps?

Cor
Nov 21 '05 #25

P: n/a
Brrrrrrrrr
Did you see that Hefried wrote that when you put on Option Strict on you
would be warned, why you did not do that.


His name is Herfried, would give me a long message when I did not correct
that.

:-)

Cor
Nov 21 '05 #26

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
MyString.empty
myString = Nothing
myString = ""
Are all the same


They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
are not.

did I write Is Nothing?
Although = Nothing acts the same as Is nothing when there is no reference.


\\\
Dim s1 As String = String.Empty
MsgBox(s1.Length) ' 0.
Dim s2 As String = Nothing
MsgBox(s2.Length) ' 'NullReferenceException'.
///

That's what I was talking about. If you compare a string that is
holding a null reference to 'String.Empty', you will receive a 'True' as
the result of the comparison. Nevertheless, both string variables
behave differently.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #27

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Did you see that Hefried wrote that when you put on Option Strict on you
would be warned, why you did not do that.


His name is Herfried, would give me a long message when I did not correct
that.


LOL!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #28

P: n/a
OK

We have no difference in my opinion about that, I did not understand that
you was meaning "it can be" a null reference.

Therefore I use as well as Armin said String = ""

(As about in reallity about of course for very few things)

:-)

Cor

They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
are not.
did I write Is Nothing?
Although = Nothing acts the same as Is nothing when there is no

reference.
\\\
Dim s1 As String = String.Empty
MsgBox(s1.Length) ' 0.
Dim s2 As String = Nothing
MsgBox(s2.Length) ' 'NullReferenceException'.
///

That's what I was talking about. If you compare a string that is
holding a null reference to 'String.Empty', you will receive a 'True' as
the result of the comparison. Nevertheless, both string variables
behave differently.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #29

P: n/a
When you say "It didn't work", can you be more specific? What error are you
getting?
If Me.txtLInch.Text Is Nothing Then LInch = 0 Else
Me.LInch = CType(Me.txtLInch.Text, Integer)
Should be:

If txtLInch.Text = string.empty Then
LInch = 0
Else
Me.LInch = CType(Me.txtLInch.Text, Integer)
End If
Me.LFeet = Me.txtLFeet.Text
'Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
'Me.WInch = Me.txtWInch.Text
'Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text
Should be:

LFeet = CType(txtLFeet.Text,Double)
LInch = CType(txtLInch.Text,Double)
WFeet = CType(txtWFeet.Text,Double)
WInch = CType(txtWInch.Text,Double)
TFeet = CType(txtTFeet.Text,Double)
TInch = CType(txtTInch.Text,Double)
"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com... Scott,

I tried what you suggested and it didn't really work. I keep getting
same
error, 'to type integer Not valid'. Then I tried what some other guys
said,
it didn't work. Help.

Have a look at this and you tell me OK.

Thanks again.

Dim LInch As Double
Dim LFeet As Double
Dim WFeet As Double
Dim WInch As Double
Dim TFeet As Double
Dim TInch As Double
Dim SqrFeet As Double
Dim Yard As Double

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompute.Click
If Me.txtLInch.Text Is Nothing Then LInch = 0 Else
Me.LInch = CType(Me.txtLInch.Text, Integer)

If Me.txtWInch.Text Is Nothing Then WInch = 0 Else
Me.WInch = CType(Me.txtWInch.Text, Integer)

If Me.txtTFeet.Text Is Nothing Then TFeet = 0 Else
Me.TFeet = CType(Me.txtTFeet.Text, Integer)
Me.LFeet = Me.txtLFeet.Text
'Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
'Me.WInch = Me.txtWInch.Text
'Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text
If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text = Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
(Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch /
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) / 27

End Sub

"Dooglo" wrote:
Thanks so much to all of you for replying to my post.
Sorry that I didn't reply back sooner.

Thanks again for the help.
"Scott M." wrote:
> The problem is that you aren't checking the textboxes for no data, you
> are
> checking for a space character, rather than and empty string:
>
> If Me.txtLInch.Text = " " Then TInch = 0
> ....should be...
> If Me.txtLInch.Text = "" Then TInch = 0
>
> So, when no data is entereed, it is not getting set to zero and when
> you try
> to take the textbox value and set it into the integer varaible, you are
> tring to take an empty string and make it become an integer which is
> what
> the error message is reporting.
>
> Second, I think it is better to keep the feet and inches as separate
> textboxes, rather that try to make them one.
>
> Third, I don't think you'll need your variable declared as Public
> unless you
> intend to use them in another class so Private will do.
>
> Next, you can combine the check for no data and the assignment of a
> value to
> one If statement:
>
> 'Check for empty textboxes
> If txtLInch.Text = "" Then
> TInch = 0
> Else
> TInch = CType(txtTInch.Text, Integer)
> End If
>
> Next, the use of the keyword "Me" is certainly ok, but not required and
> can
> make your statements cleaner to write. Instead of:
>
> If Me.WInch = 0 And Me.LInch = 0 Then
> Me.txtSqrFeet.Text = Me.LFeet * Me.WFeet
> Else
> Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet +
> (Me.WInch / 12))
> Me.SqrFeet = Me.txtSqrFeet.Text
> End If
>
> You can write:
>
> If WInch = 0 And LInch = 0 Then
> txtSqrFeet.Text = LFeet * WFeet
> Else
> txtSqrFeet.Text = (LFeet + (LInch / 12)) * (WFeet + (WInch / 12))
> SqrFeet = txtSqrFeet.Text
> End If
>
>
> Good Luck!
>
>
>
>
>
>
> "Dooglo" <Do****@discussions.microsoft.com> wrote in message
> news:08**********************************@microsof t.com...
> > I'm new VB and programming all together, but I'm getting he hang of
> > it.
> >
> > My question is;
> >
> > I'm writting a program to figure square feet and yards when the user
> > inputs
> > "Length in feet and inch ( seperate boxes), Width in feet and inches
> > (seperate boxes), and thickness in feet and inches (all so in
> > seperate
> > boxes). I haven't quit figured out the split function yet to use a
> > single
> > text box for each. Anyways, when I enter data in each box; eg.
> >
> > Length 2' 0"
> > Width 2' 0"
> > Thickness 0' 4"
> >
> > my program works and figures out the correct answer. But when I
> > enter it
> > differently, like this;
> >
> > Lenght 2' not entering inches leaving box empty
> > Widht 2' not entering inches leaving box empty
> > Thickness not entering feet leaving box empty but entering 4"
> >
> > it gives me an error "Cast from string " " to type 'Integer' is not
> > valid."
> > Here is some of what Ive written.
> >
> >
> > Public LFeet, WFeet, TFeet As Integer
> > Public LInch, WInch, TInch As Integer
> > Public SqrFeet, Yard As Integer
> >
> > Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e
> > As
> > System.EventArgs) Handles btnCompute.Click
> >
> > If Me.txtLInch.Text = " " Then TInch = 0
> > If Me.txtWInch.Text = " " Then WInch = 0
> > If Me.txtTFeet.Text = " " Then TInch = 0
> >
> > Me.LFeet = Me.txtLFeet.Text
> > Me.LInch = Me.txtLInch.Text
> > Me.WFeet = Me.txtWFeet.Text
> > Me.WInch = Me.txtWInch.Text
> > Me.TFeet = Me.txtTFeet.Text
> > Me.TInch = Me.txtTInch.Text
> >
> > If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =
> > Me.LFeet
> > * Me.WFeet Else
> >
> > Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet
> > +
> > (Me.WInch / 12))
> >
> > Me.SqrFeet = Me.txtSqrFeet.Text
> >
> > If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
> > /
> > 12)
> > / 27) Else
> >
> > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))
> > / 27
> >
> > End Sub
> >
> >
> > I know that I'm using the wrong variables here, I can't quit figure
> > it out
> > though.
> >
> > Thanks to Anyone Who Replies.
> >
> >
> >
>
>
>

Nov 21 '05 #30

P: n/a
Cor,

I'm not sure I'm following your point. If a user types: 12e4 and then you
check that value with IsNumeric, it will return true, allthough the value is
not completely numeric. If you use IsNumeric as your basis for determining
if doing math (for example) on the input value and the user had typed 12e4,
IsNumeric will return True, you would then assume it is safe to do math and
your statement would fail.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OX*************@TK2MSFTNGP11.phx.gbl...
Scott
124EZ


When something is a numeric expression, what is than false with that, when
it is told that it is, in my opinion only when you have extra conditions,
than can your statement be true.

Cor

Nov 21 '05 #31

P: n/a
Scott,

I hope that this sample makes clear what I want to say.
\\\\
Dim str As String = "12E4"
If IsNumeric(str) Then
MessageBox.Show(CLng(str).ToString)
End If
///

However you can of course test if there is something as

if str.tolower.indexof("e") <> -1 then doError

Cor
Nov 21 '05 #32

P: n/a
On 2004-08-28, Hal Rosser <hm******@bellsouth.net> wrote:
you should check the contents of the text boxes first to see if they can be
converted to numbers. - (use the isnumeric function)
then you should convert to and assign to -> variables of a numeric data
type - like double.
then use the numeric variables to do your calculations.
IsNumeric has extremely limited usefulness, and is worth calling only in
very unique situations. It does little more than waste time, since it
almost never gives you the information you really need to know. It's
much better to simply try to convert to the type of variable you want,
and catch the exception on failure. After all, that's pretty much all
IsNumeric is going to do, except that IsNumeric has to check all kinds
of possibilities that aren't useful in the current context, and you
*still* need to embed your conversion in a Try/Catch because IsNumeric
doesn't tell you whether the string in question is valid for the type
you really need.

For example, in this case, the user really needs integers rather than
doubles, and IsNumeric doesn't tell you whether the current string is a
valid integer.
by the way - at the top - you should type 'option strict on' and 'option
explicit on'
vb 6.0 was much easier to learn for newbies.


Agreed on both wholeheartedly. I would add though, that VB.Net makes it
much easier for experienced programmers to write good programs.
Nov 21 '05 #33

P: n/a
On 2004-08-29, Cor Ligthert <no**********@planet.nl> wrote:
Scott,

I hope that this sample makes clear what I want to say.
\\\\
Dim str As String = "12E4"
If IsNumeric(str) Then
MessageBox.Show(CLng(str).ToString)
End If
///


In which case you just threw an exception if str doesn't fit into a
long. IsNumeric probably took *longer* to run than the CLng, and still
didn't tell you if the CLng would be a valid call.
Nov 21 '05 #34

P: n/a
* David <df*****@woofix.local.dom> scripsit:
I hope that this sample makes clear what I want to say.
\\\\
Dim str As String = "12E4"
If IsNumeric(str) Then
MessageBox.Show(CLng(str).ToString)
End If
///


In which case you just threw an exception if str doesn't fit into a
long. IsNumeric probably took *longer* to run than the CLng, and still
didn't tell you if the CLng would be a valid call.


That's why there will be a 'TryParse' method for the 'Int32' datatype in
..NET 2.0.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #35

P: n/a
Right, that's my point.
"David" <df*****@woofix.local.dom> wrote in message
news:slrncj47v1.lnk.df*****@woofix.local.dom...
On 2004-08-29, Cor Ligthert <no**********@planet.nl> wrote:
Scott,

I hope that this sample makes clear what I want to say.
\\\\
Dim str As String = "12E4"
If IsNumeric(str) Then
MessageBox.Show(CLng(str).ToString)
End If
///


In which case you just threw an exception if str doesn't fit into a
long. IsNumeric probably took *longer* to run than the CLng, and still
didn't tell you if the CLng would be a valid call.

Nov 21 '05 #36

P: n/a
Herfried,

That's why there will be a 'TryParse' method for the 'Int32' datatype in
.NET 2.0.

Which you can make yourself of course by just making a methode which does a
simple calculation. When an error is thrown you know there it is not numeric
or whatever test you put in it, however I do not find that elegant.

Cor
Nov 21 '05 #37

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
That's why there will be a 'TryParse' method for the 'Int32' datatype in
.NET 2.0.


Which you can make yourself of course by just making a methode which does a
simple calculation. When an error is thrown you know there it is not numeric
or whatever test you put in it, however I do not find that elegant.


Sure, you can implement such a method currently too. Nevertheless, I
prefer a speed-optimized version that comes out of the box.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #38

P: n/a
Sure, you can implement such a method currently too. Nevertheless, I
prefer a speed-optimized version that comes out of the box.


ACK

:-)

Cor
Nov 21 '05 #39

P: n/a
SStory,
Better to use string.empty instead. Agree, I normally use String.Empty, although I use "" also.
using "" means vb creates a new string for each "" Not really, the compiler, CLR & JIT will intern "" to the same "" that
String.Empty refers to. In other words they both refer to the same string
instance!

It even appears that String.Trim will return the same instance (when the
result is empty).

Dim s1 As Object = String.Empty
Dim s2 As Object = ""
Dim s3 As Object = "aaa".Trim("a"c)

Debug.WriteLine(s1 Is s2, "s1 Is s2")
Debug.WriteLine(s1 Is s3, "s1 Is s3")
Debug.WriteLine(s2 Is s3, "s2 Is s3")

Remember that the Is operator compares instances, not values:

Dim a1 As String = "aaa"
Dim a2 As String = New String("a"c, 3)
Debug.WriteLine(a1 Is a2, "a1 Is a2")
Debug.WriteLine(a1 = a2, "a1 = a2")
Hope this helps
Jay

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OX*************@TK2MSFTNGP10.phx.gbl... But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I'm new VB and programming all together, but I'm getting he hang of it.
My question is;

I'm writting a program to figure square feet and yards when the user inputs
"Length in feet and inch ( seperate boxes), Width in feet and inches
(seperate boxes), and thickness in feet and inches (all so in seperate
boxes). I haven't quit figured out the split function yet to use a single text box for each. Anyways, when I enter data in each box; eg.

Length 2' 0"
Width 2' 0"
Thickness 0' 4"

my program works and figures out the correct answer. But when I enter it differently, like this;

Lenght 2' not entering inches leaving box empty
Widht 2' not entering inches leaving box empty
Thickness not entering feet leaving box empty but entering 4"

it gives me an error "Cast from string " " to type 'Integer' is not

valid."
Here is some of what Ive written.
Public LFeet, WFeet, TFeet As Integer
Public LInch, WInch, TInch As Integer
Public SqrFeet, Yard As Integer

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0

Me.LFeet = Me.txtLFeet.Text
Me.LInch = Me.txtLInch.Text
Me.WFeet = Me.txtWFeet.Text
Me.WInch = Me.txtWInch.Text
Me.TFeet = Me.txtTFeet.Text
Me.TInch = Me.txtTInch.Text

If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =

Me.LFeet
* Me.WFeet Else

Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet + (Me.WInch / 12))

Me.SqrFeet = Me.txtSqrFeet.Text

If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch
/
12)
/ 27) Else

Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))

/ 27
End Sub
I know that I'm using the wrong variables here, I can't quit figure it out though.

Thanks to Anyone Who Replies.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004

Nov 21 '05 #40

P: n/a
Well that's nice.

I know it wasn't that way in prior version of vb, and for that reason Hard
Core VB mentioned using one globally defined empty instance.

Thanks,

Shane

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
SStory,
Better to use string.empty instead. Agree, I normally use String.Empty, although I use "" also.
using "" means vb creates a new string for each ""

Not really, the compiler, CLR & JIT will intern "" to the same "" that
String.Empty refers to. In other words they both refer to the same string
instance!

It even appears that String.Trim will return the same instance (when the
result is empty).

Dim s1 As Object = String.Empty
Dim s2 As Object = ""
Dim s3 As Object = "aaa".Trim("a"c)

Debug.WriteLine(s1 Is s2, "s1 Is s2")
Debug.WriteLine(s1 Is s3, "s1 Is s3")
Debug.WriteLine(s2 Is s3, "s2 Is s3")

Remember that the Is operator compares instances, not values:

Dim a1 As String = "aaa"
Dim a2 As String = New String("a"c, 3)
Debug.WriteLine(a1 Is a2, "a1 Is a2")
Debug.WriteLine(a1 = a2, "a1 = a2")
Hope this helps
Jay

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OX*************@TK2MSFTNGP10.phx.gbl...
But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
It looks like your test for empty values is looking for a single space
rather than an empty string? Try changing:

If Me.txtLInch.Text = " " Then TInch = 0
If Me.txtWInch.Text = " " Then WInch = 0
If Me.txtTFeet.Text = " " Then TInch = 0
To

If Me.txtLInch.Text = "" Then TInch = 0
If Me.txtWInch.Text = "" Then WInch = 0
If Me.txtTFeet.Text = "" Then TInch = 0
HTH

Wayne

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...

> I'm new VB and programming all together, but I'm getting he hang of it. >
> My question is;
>
> I'm writting a program to figure square feet and yards when the user
inputs
> "Length in feet and inch ( seperate boxes), Width in feet and inches
> (seperate boxes), and thickness in feet and inches (all so in seperate > boxes). I haven't quit figured out the split function yet to use a

single
> text box for each. Anyways, when I enter data in each box; eg.
>
> Length 2' 0"
> Width 2' 0"
> Thickness 0' 4"
>
> my program works and figures out the correct answer. But when I enter
it
> differently, like this;
>
> Lenght 2' not entering inches leaving box empty
> Widht 2' not entering inches leaving box empty
> Thickness not entering feet leaving box empty but entering 4"
>
> it gives me an error "Cast from string " " to type 'Integer' is
not valid."
> Here is some of what Ive written.
>
>
> Public LFeet, WFeet, TFeet As Integer
> Public LInch, WInch, TInch As Integer
> Public SqrFeet, Yard As Integer
>
> Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles btnCompute.Click
>
> If Me.txtLInch.Text = " " Then TInch = 0
> If Me.txtWInch.Text = " " Then WInch = 0
> If Me.txtTFeet.Text = " " Then TInch = 0
>
> Me.LFeet = Me.txtLFeet.Text
> Me.LInch = Me.txtLInch.Text
> Me.WFeet = Me.txtWFeet.Text
> Me.WInch = Me.txtWInch.Text
> Me.TFeet = Me.txtTFeet.Text
> Me.TInch = Me.txtTInch.Text
>
> If Me.WInch = 0 And Me.LInch = 0 Then Me.txtSqrFeet.Text =
Me.LFeet
> * Me.WFeet Else
>
> Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) *
(Me.WFeet + > (Me.WInch / 12))
>
> Me.SqrFeet = Me.txtSqrFeet.Text
>
> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *
(Me.TInch
/ 12)
> / 27) Else
>
> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /
12))) /
27
>
> End Sub
>
>
> I know that I'm using the wrong variables here, I can't quit figure

it out
> though.
>
> Thanks to Anyone Who Replies.
>
>
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
Nov 21 '05 #41

P: n/a
On 2004-08-29, Herfried K. Wagner [MVP] <hi***************@gmx.at> wrote:
* David <df*****@woofix.local.dom> scripsit:
I hope that this sample makes clear what I want to say.
\\\\
Dim str As String = "12E4"
If IsNumeric(str) Then
MessageBox.Show(CLng(str).ToString)
End If
///


In which case you just threw an exception if str doesn't fit into a
long. IsNumeric probably took *longer* to run than the CLng, and still
didn't tell you if the CLng would be a valid call.


That's why there will be a 'TryParse' method for the 'Int32' datatype in
.NET 2.0.


In addition, TryParse has the correct semantics, as opposed to the VB
Is??? functions. TryParse (at least last time I saw it) doesn't just
test, it also performs the conversion, so we can avoid code that looks
like...

If ParseThisOnceJustToTest(myvar) Then
anotherVar = ParseThisAgainJustToWasteTime(myvar)
End If

Nov 21 '05 #42

P: n/a
Shane,
Correct VB6 & prior did not intern string literals.

I should add, that the string interning is true for all string literals.

There is only one instance of the "aaa" string in the following:

Dim s1 As String = "aaa"
Dim s2 As String = "aaa"

Hence the "New String("a"c, 3)" in my example, I was creating a string with
3 a's that was not a literal.

Hope this helps
Jay
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Ow**************@tk2msftngp13.phx.gbl...
Well that's nice.

I know it wasn't that way in prior version of vb, and for that reason Hard
Core VB mentioned using one globally defined empty instance.

Thanks,

Shane

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
SStory,
Better to use string.empty instead.

Agree, I normally use String.Empty, although I use "" also.
using "" means vb creates a new string for each ""

Not really, the compiler, CLR & JIT will intern "" to the same "" that
String.Empty refers to. In other words they both refer to the same string instance!

It even appears that String.Trim will return the same instance (when the
result is empty).

Dim s1 As Object = String.Empty
Dim s2 As Object = ""
Dim s3 As Object = "aaa".Trim("a"c)

Debug.WriteLine(s1 Is s2, "s1 Is s2")
Debug.WriteLine(s1 Is s3, "s1 Is s3")
Debug.WriteLine(s2 Is s3, "s2 Is s3")

Remember that the Is operator compares instances, not values:

Dim a1 As String = "aaa"
Dim a2 As String = New String("a"c, 3)
Debug.WriteLine(a1 Is a2, "a1 Is a2")
Debug.WriteLine(a1 = a2, "a1 = a2")
Hope this helps
Jay

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OX*************@TK2MSFTNGP10.phx.gbl...
But again,

Better to use string.empty instead.

using "" means vb creates a new string for each ""

using string.empty means there is only one instance of "" and it is
string.empty and so it is more efficient.

Shane

<<snip>>
Nov 21 '05 #43

This discussion thread is closed

Replies have been disabled for this discussion.