Selecting Proper Variables | | |
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. | | | | re: Selecting Proper Variables
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
[color=blue]
> 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[/color]
inputs[color=blue]
> "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[/color]
valid."[color=blue]
> 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 =[/color]
Me.LFeet[color=blue]
> * 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 /[/color]
12)[color=blue]
> / 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.
>
>
>[/color] | | | | re: Selecting Proper Variables
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" <Dooglo@discussions.microsoft.com> wrote in message
news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=blue]
> 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.
>
>
>[/color] | | | | re: Selecting Proper Variables
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" <Dooglo@discussions.microsoft.com> wrote in message
news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
[color=blue]
> 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[/color]
inputs[color=blue]
> "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[/color]
valid."[color=blue]
> 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 =[/color]
Me.LFeet[color=blue]
> * 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 /[/color]
12)[color=blue]
> / 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.
>
>
>[/color] | | | | re: Selecting Proper Variables
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" <Dooglo@discussions.microsoft.com> wrote in message
news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=blue]
> 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[/color]
valid."[color=blue]
> 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 =[/color]
Me.LFeet[color=blue]
> * 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 /[/color]
12)[color=blue]
> / 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.
>
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
oops... I meant use CInt()
instead of CStr()
"SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%23M$dODRjEHA.1712@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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"[/color]
where[color=blue]
> ; 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'>[/color]
[Use[color=blue]
> 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[/color]
for[color=blue]
> feet and one for inches and overrides tostring to show them[/color]
together(that's[color=blue]
> 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[/color]
IDE[color=blue]
> right now, but it is an updown control that only allows numbers) instead[/color]
of[color=blue]
> 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" <Dooglo@discussions.microsoft.com> wrote in message
> news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=green]
> > 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[/color][/color]
it[color=blue][color=green]
> > 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[/color]
> valid."[color=green]
> > 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 =[/color]
> Me.LFeet[color=green]
> > * 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 /[/color]
> 12)[color=green]
> > / 27) Else
> >
> > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) /[/color][/color]
27[color=blue][color=green]
> >
> > End Sub
> >
> >
> > I know that I'm using the wrong variables here, I can't quit figure it[/color][/color]
out[color=blue][color=green]
> > though.
> >
> > Thanks to Anyone Who Replies.
> >
> >
> >[/color]
>
>
> ---
> 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
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
* =?Utf-8?B?RG9vZ2xv?= <Dooglo@discussions.microsoft.com> scripsit:[color=blue]
> 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.[/color]
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/> | | | | re: Selecting Proper Variables
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" <wayneDONTWANTSPAM@wengert.com> wrote in message
news:%23HsbTBRjEHA.3320@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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" <Dooglo@discussions.microsoft.com> wrote in message
> news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
>[color=green]
> > 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[/color]
> inputs[color=green]
> > "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[/color][/color]
single[color=blue][color=green]
> > 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[/color][/color]
it[color=blue][color=green]
> > 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[/color]
> valid."[color=green]
> > 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 =[/color]
> Me.LFeet[color=green]
> > * 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 /[/color]
> 12)[color=green]
> > / 27) Else
> >
> > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12))) /[/color][/color]
27[color=blue][color=green]
> >
> > End Sub
> >
> >
> > I know that I'm using the wrong variables here, I can't quit figure it[/color][/color]
out[color=blue][color=green]
> > though.
> >
> > Thanks to Anyone Who Replies.
> >
> >
> >[/color]
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
Thanks - never even realized string.empty was there. I'll be sure to use
that in the future.
Wayne
"SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OXl7kKRjEHA.384@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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" <wayneDONTWANTSPAM@wengert.com> wrote in message
> news:%23HsbTBRjEHA.3320@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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" <Dooglo@discussions.microsoft.com> wrote in message
> > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
> >[color=darkred]
> > > I'm new VB and programming all together, but I'm getting he hang of[/color][/color][/color]
it.[color=blue][color=green][color=darkred]
> > >
> > > My question is;
> > >
> > > I'm writting a program to figure square feet and yards when the user[/color]
> > inputs[color=darkred]
> > > "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[/color][/color]
> single[color=green][color=darkred]
> > > 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[/color][/color]
> it[color=green][color=darkred]
> > > 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[/color]
> > valid."[color=darkred]
> > > 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[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > 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 =[/color]
> > Me.LFeet[color=darkred]
> > > * Me.WFeet Else
> > >
> > > Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet[/color][/color][/color]
+[color=blue][color=green][color=darkred]
> > > (Me.WInch / 12))
> > >
> > > Me.SqrFeet = Me.txtSqrFeet.Text
> > >
> > > If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch[/color][/color][/color]
/[color=blue][color=green]
> > 12)[color=darkred]
> > > / 27) Else
> > >
> > > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))[/color][/color][/color]
/[color=blue]
> 27[color=green][color=darkred]
> > >
> > > End Sub
> > >
> > >
> > > I know that I'm using the wrong variables here, I can't quit figure it[/color][/color]
> out[color=green][color=darkred]
> > > though.
> > >
> > > Thanks to Anyone Who Replies.
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>
> ---
> 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
>
>[/color] | | | | re: Selecting Proper Variables
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" <Dooglo@discussions.microsoft.com> wrote in message
news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=blue]
> 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[/color]
inputs[color=blue]
> "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[/color]
valid."[color=blue]
> 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 =[/color]
Me.LFeet[color=blue]
> * 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 /[/color]
12)[color=blue]
> / 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.
>
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
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" <hmrosser@bellsouth.net> wrote in message
news:Io5Yc.52562$0o5.36271@bignews1.bellsouth.net. ..[color=blue]
> 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" <Dooglo@discussions.microsoft.com> wrote in message
> news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=green]
>> 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[/color]
> inputs[color=green]
>> "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[/color]
> valid."[color=green]
>> 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 =[/color]
> Me.LFeet[color=green]
>> * 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 /[/color]
> 12)[color=green]
>> / 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.
>>
>>
>>[/color]
>
>
> ---
> 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
>
>[/color] | | | | re: Selecting Proper Variables
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-mar@nospam.nospam> wrote in message
news:O3ieNJUjEHA.3696@TK2MSFTNGP15.phx.gbl...[color=blue]
> 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" <hmrosser@bellsouth.net> wrote in message
> news:Io5Yc.52562$0o5.36271@bignews1.bellsouth.net. ..[color=green]
> > 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[/color][/color]
'option[color=blue][color=green]
> > explicit on'
> > vb 6.0 was much easier to learn for newbies.
> >
> >
> > "Dooglo" <Dooglo@discussions.microsoft.com> wrote in message
> > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=darkred]
> >> 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[/color]
> > inputs[color=darkred]
> >> "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[/color][/color][/color]
it[color=blue][color=green][color=darkred]
> >> 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[/color]
> > valid."[color=darkred]
> >> 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 =[/color]
> > Me.LFeet[color=darkred]
> >> * 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[/color][/color][/color]
/[color=blue][color=green]
> > 12)[color=darkred]
> >> / 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.
> >>
> >>
> >>[/color]
> >
> >
> > ---
> > 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
> >
> >[/color]
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
I know brother... there's too much for any of us to know it all.
Thank goodness we have this group. :)
Shane
"Wayne Wengert" <wayneDONTWANTSPAM@wengert.com> wrote in message
news:umCIcGSjEHA.704@TK2MSFTNGP09.phx.gbl...[color=blue]
> Thanks - never even realized string.empty was there. I'll be sure to use
> that in the future.
>
> Wayne
>
> "SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
> news:OXl7kKRjEHA.384@TK2MSFTNGP10.phx.gbl...[color=green]
> > 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" <wayneDONTWANTSPAM@wengert.com> wrote in message
> > news:%23HsbTBRjEHA.3320@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > 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" <Dooglo@discussions.microsoft.com> wrote in message
> > > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
> > >
> > > > I'm new VB and programming all together, but I'm getting he hang of[/color][/color]
> it.[color=green][color=darkred]
> > > >
> > > > 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[/color][/color][/color]
seperate[color=blue][color=green][color=darkred]
> > > > boxes). I haven't quit figured out the split function yet to use a[/color]
> > single[color=darkred]
> > > > 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[/color][/color][/color]
enter[color=blue][color=green]
> > it[color=darkred]
> > > > 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[/color][/color][/color]
not[color=blue][color=green][color=darkred]
> > > 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[/color][/color]
> As[color=green][color=darkred]
> > > > 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)) *[/color][/color][/color]
(Me.WFeet[color=blue]
> +[color=green][color=darkred]
> > > > (Me.WInch / 12))
> > > >
> > > > Me.SqrFeet = Me.txtSqrFeet.Text
> > > >
> > > > If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *[/color][/color][/color]
(Me.TInch[color=blue]
> /[color=green][color=darkred]
> > > 12)
> > > > / 27) Else
> > > >
> > > > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /[/color][/color][/color]
12)))[color=blue]
> /[color=green]
> > 27[color=darkred]
> > > >
> > > > End Sub
> > > >
> > > >
> > > > I know that I'm using the wrong variables here, I can't quit figure[/color][/color][/color]
it[color=blue][color=green]
> > out[color=darkred]
> > > > though.
> > > >
> > > > Thanks to Anyone Who Replies.
> > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >
> > ---
> > 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
> >
> >[/color]
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
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" <hmrosser@bellsouth.net> wrote in message
news:Y57Yc.53504$0o5.24575@bignews1.bellsouth.net. ..[color=blue]
> Regular expressions - as you say is the best approach - but the OP is new[/color]
to[color=blue]
> programming
> Regular expressions to a newbie is pretty intimidating. But is worth
> learning - for any language.
>
>
> "Scott M." <s-mar@nospam.nospam> wrote in message
> news:O3ieNJUjEHA.3696@TK2MSFTNGP15.phx.gbl...[color=green]
> > 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" <hmrosser@bellsouth.net> wrote in message
> > news:Io5Yc.52562$0o5.36271@bignews1.bellsouth.net. ..[color=darkred]
> > > you should check the contents of the text boxes first to see if they[/color][/color][/color]
can[color=blue][color=green][color=darkred]
> > > be
> > > converted to numbers. - (use the isnumeric function)
> > > then you should convert to and assign to -> variables of a numeric[/color][/color][/color]
data[color=blue][color=green][color=darkred]
> > > 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[/color][/color]
> 'option[color=green][color=darkred]
> > > explicit on'
> > > vb 6.0 was much easier to learn for newbies.
> > >
> > >
> > > "Dooglo" <Dooglo@discussions.microsoft.com> wrote in message
> > > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
> > >> I'm new VB and programming all together, but I'm getting he hang of[/color][/color][/color]
it.[color=blue][color=green][color=darkred]
> > >>
> > >> 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[/color][/color][/color]
seperate[color=blue][color=green][color=darkred]
> > >> 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[/color][/color][/color]
enter[color=blue]
> it[color=green][color=darkred]
> > >> 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[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > >> 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[/color][/color][/color]
+[color=blue][color=green][color=darkred]
> > >> (Me.WInch / 12))
> > >>
> > >> Me.SqrFeet = Me.txtSqrFeet.Text
> > >>
> > >> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *[/color][/color][/color]
(Me.TInch[color=blue]
> /[color=green][color=darkred]
> > > 12)
> > >> / 27) Else
> > >>
> > >> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))[/color][/color][/color]
/[color=blue][color=green][color=darkred]
> > >> 27
> > >>
> > >> End Sub
> > >>
> > >>
> > >> I know that I'm using the wrong variables here, I can't quit figure[/color][/color][/color]
it[color=blue][color=green][color=darkred]
> > >> 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
> > >
> > >[/color]
> >
> >[/color]
>
>
> ---
> 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
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
> Why bother with either when there is already an up down control that only[color=blue]
> takes numbers???[/color]
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.[color=blue]
>
> 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[/color]
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.
[color=blue]
>
> And of course check to allow only one "."
>
> Seems easier to just use the numeric control.
>
> My 2 cents....
>
> Shane
> "Hal Rosser" <hmrosser@bellsouth.net> wrote in message
> news:Y57Yc.53504$0o5.24575@bignews1.bellsouth.net. ..[color=green]
>> Regular expressions - as you say is the best approach - but the OP is new[/color]
> to[color=green]
>> programming
>> Regular expressions to a newbie is pretty intimidating. But is worth
>> learning - for any language.
>>
>>
>> "Scott M." <s-mar@nospam.nospam> wrote in message
>> news:O3ieNJUjEHA.3696@TK2MSFTNGP15.phx.gbl...[color=darkred]
>> > 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" <hmrosser@bellsouth.net> wrote in message
>> > news:Io5Yc.52562$0o5.36271@bignews1.bellsouth.net. ..
>> > > you should check the contents of the text boxes first to see if they[/color][/color]
> can[color=green][color=darkred]
>> > > be
>> > > converted to numbers. - (use the isnumeric function)
>> > > then you should convert to and assign to -> variables of a numeric[/color][/color]
> data[color=green][color=darkred]
>> > > 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[/color]
>> 'option[color=darkred]
>> > > explicit on'
>> > > vb 6.0 was much easier to learn for newbies.
>> > >
>> > >
>> > > "Dooglo" <Dooglo@discussions.microsoft.com> wrote in message
>> > > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
>> > >> I'm new VB and programming all together, but I'm getting he hang of[/color][/color]
> it.[color=green][color=darkred]
>> > >>
>> > >> 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[/color][/color]
> seperate[color=green][color=darkred]
>> > >> 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[/color][/color]
> enter[color=green]
>> it[color=darkred]
>> > >> 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[/color][/color]
> As[color=green][color=darkred]
>> > >> 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[/color][/color]
> +[color=green][color=darkred]
>> > >> (Me.WInch / 12))
>> > >>
>> > >> Me.SqrFeet = Me.txtSqrFeet.Text
>> > >>
>> > >> If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *[/color][/color]
> (Me.TInch[color=green]
>> /[color=darkred]
>> > > 12)
>> > >> / 27) Else
>> > >>
>> > >> Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /
>> > >> 12)))[/color][/color]
> /[color=green][color=darkred]
>> > >> 27
>> > >>
>> > >> End Sub
>> > >>
>> > >>
>> > >> I know that I'm using the wrong variables here, I can't quit figure[/color][/color]
> it[color=green][color=darkred]
>> > >> 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
>> > >
>> > >
>> >
>> >[/color]
>>
>>
>> ---
>> 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
>>
>>[/color]
>
>
> ---
> 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
>
>[/color] | | | | re: Selecting Proper Variables
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
[color=blue]
> 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 "."[/color]
or[color=blue]
> Backspace
>
> And of course check to allow only one "."[/color]
---
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 | | | | re: Selecting Proper Variables
Shane,
[color=blue]
>
> 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.
>[/color]
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 | | | | re: Selecting Proper Variables
Scott
[color=blue]
>124EZ[/color]
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 | | | | re: Selecting Proper Variables
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 | | | | re: Selecting Proper Variables
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:
[color=blue]
> 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" <Dooglo@discussions.microsoft.com> wrote in message
> news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=green]
> > 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.
> >
> >
> >[/color]
>
>
>[/color] | | | | re: Selecting Proper Variables
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue]
> MyString.empty
> myString = Nothing
> myString = ""
> Are all the same[/color]
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/> | | | | re: Selecting Proper Variables
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:
[color=blue]
> 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:
>[color=green]
> > 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" <Dooglo@discussions.microsoft.com> wrote in message
> > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...[color=darkred]
> > > 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.
> > >
> > >
> > >[/color]
> >
> >
> >[/color][/color] | | | | re: Selecting Proper Variables
Herfried,[color=blue][color=green]
> > MyString.empty
> > myString = Nothing
> > myString = ""
> > Are all the same[/color]
>
> They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
> are not.
>[/color]
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 | | | | re: Selecting Proper Variables
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 | | | | re: Selecting Proper Variables
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[color=blue]
> If txtWInch.Text Is Nothing[/color]
'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 | | | | re: Selecting Proper Variables
Brrrrrrrrr
[color=blue]
> Did you see that Hefried wrote that when you put on Option Strict on you
> would be warned, why you did not do that.[/color]
His name is Herfried, would give me a long message when I did not correct
that.
:-)
Cor | | | | re: Selecting Proper Variables
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green][color=darkred]
>>> MyString.empty
>>> myString = Nothing
>>> myString = ""
>>> Are all the same[/color]
>>
>> They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
>> are not.
>>[/color]
> did I write Is Nothing?
> Although = Nothing acts the same as Is nothing when there is no reference.[/color]
\\\
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/> | | | | re: Selecting Proper Variables
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Did you see that Hefried wrote that when you put on Option Strict on you
>> would be warned, why you did not do that.[/color]
>
> His name is Herfried, would give me a long message when I did not correct
> that.[/color]
LOL!
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/> | | | | re: Selecting Proper Variables
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
[color=blue][color=green][color=darkred]
> >>
> >> They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
> >> are not.
> >>[/color]
> > did I write Is Nothing?
> > Although = Nothing acts the same as Is nothing when there is no[/color][/color]
reference.[color=blue]
>
> \\\
> 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/>[/color] | | | | re: Selecting Proper Variables
When you say "It didn't work", can you be more specific? What error are you
getting?
[color=blue]
> If Me.txtLInch.Text Is Nothing Then LInch = 0 Else
> Me.LInch = CType(Me.txtLInch.Text, Integer)[/color]
Should be:
If txtLInch.Text = string.empty Then
LInch = 0
Else
Me.LInch = CType(Me.txtLInch.Text, Integer)
End If
[color=blue]
> 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[/color]
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" <Dooglo@discussions.microsoft.com> wrote in message
news:C6429833-B6E1-41DD-B813-0879E27E0560@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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:
>>[color=darkred]
>> > 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" <Dooglo@discussions.microsoft.com> wrote in message
>> > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.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.
>> > >
>> > >
>> > >
>> >
>> >
>> >[/color][/color][/color] | | | | re: Selecting Proper Variables
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" <notfirstname@planet.nl> wrote in message
news:OXcGRXZjEHA.592@TK2MSFTNGP11.phx.gbl...[color=blue]
> Scott
>[color=green]
>>124EZ[/color]
>
> 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
>
>
>[/color] | | | | re: Selecting Proper Variables
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 | | | | re: Selecting Proper Variables
On 2004-08-28, Hal Rosser <hmrosser@bellsouth.net> wrote:[color=blue]
> 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.[/color]
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.
[color=blue]
> 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.[/color]
Agreed on both wholeheartedly. I would add though, that VB.Net makes it
much easier for experienced programmers to write good programs. | | | | re: Selecting Proper Variables
On 2004-08-29, Cor Ligthert <notfirstname@planet.nl> wrote:[color=blue]
> 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
> ///[/color]
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. | | | | re: Selecting Proper Variables
* David <dfoster@woofix.local.dom> scripsit:[color=blue][color=green]
>> 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
>> ///[/color]
>
> 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.[/color]
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/> | | | | re: Selecting Proper Variables
Right, that's my point.
"David" <dfoster@woofix.local.dom> wrote in message
news:slrncj47v1.lnk.dfoster@woofix.local.dom...[color=blue]
> On 2004-08-29, Cor Ligthert <notfirstname@planet.nl> wrote:[color=green]
>> 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
>> ///[/color]
>
> 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.
>
>[/color] | | | | re: Selecting Proper Variables
Herfried,
[color=blue]
>
> That's why there will be a 'TryParse' method for the 'Int32' datatype in
> .NET 2.0.
>[/color]
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 | | | | re: Selecting Proper Variables
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> That's why there will be a 'TryParse' method for the 'Int32' datatype in
>> .NET 2.0.[/color]
>
> 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.[/color]
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/> | | | | re: Selecting Proper Variables
[color=blue]
> Sure, you can implement such a method currently too. Nevertheless, I
> prefer a speed-optimized version that comes out of the box.[/color]
ACK
:-)
Cor | | | | re: Selecting Proper Variables
SStory,[color=blue]
> Better to use string.empty instead.[/color]
Agree, I normally use String.Empty, although I use "" also.
[color=blue]
> using "" means vb creates a new string for each ""[/color]
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" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:OXl7kKRjEHA.384@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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" <wayneDONTWANTSPAM@wengert.com> wrote in message
> news:%23HsbTBRjEHA.3320@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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" <Dooglo@discussions.microsoft.com> wrote in message
> > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
> >[color=darkred]
> > > I'm new VB and programming all together, but I'm getting he hang of[/color][/color][/color]
it.[color=blue][color=green][color=darkred]
> > >
> > > My question is;
> > >
> > > I'm writting a program to figure square feet and yards when the user[/color]
> > inputs[color=darkred]
> > > "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[/color][/color]
> single[color=green][color=darkred]
> > > 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[/color][/color]
> it[color=green][color=darkred]
> > > 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[/color]
> > valid."[color=darkred]
> > > 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[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > 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 =[/color]
> > Me.LFeet[color=darkred]
> > > * Me.WFeet Else
> > >
> > > Me.txtSqrFeet.Text = (Me.LFeet + (Me.LInch / 12)) * (Me.WFeet[/color][/color][/color]
+[color=blue][color=green][color=darkred]
> > > (Me.WInch / 12))
> > >
> > > Me.SqrFeet = Me.txtSqrFeet.Text
> > >
> > > If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet * (Me.TInch[/color][/color][/color]
/[color=blue][color=green]
> > 12)[color=darkred]
> > > / 27) Else
> > >
> > > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch / 12)))[/color][/color][/color]
/[color=blue]
> 27[color=green][color=darkred]
> > >
> > > End Sub
> > >
> > >
> > > I know that I'm using the wrong variables here, I can't quit figure it[/color][/color]
> out[color=green][color=darkred]
> > > though.
> > >
> > > Thanks to Anyone Who Replies.
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>
> ---
> 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
>
>[/color] | | | | re: Selecting Proper Variables
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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:e8zBV8pjEHA.3724@TK2MSFTNGP11.phx.gbl...[color=blue]
> SStory,[color=green]
> > Better to use string.empty instead.[/color]
> Agree, I normally use String.Empty, although I use "" also.
>[color=green]
> > using "" means vb creates a new string for each ""[/color]
> 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" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
> news:OXl7kKRjEHA.384@TK2MSFTNGP10.phx.gbl...[color=green]
> > 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" <wayneDONTWANTSPAM@wengert.com> wrote in message
> > news:%23HsbTBRjEHA.3320@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > 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" <Dooglo@discussions.microsoft.com> wrote in message
> > > news:08773459-1404-4183-8D29-AF7AD9C401E5@microsoft.com...
> > >
> > > > I'm new VB and programming all together, but I'm getting he hang of[/color][/color]
> it.[color=green][color=darkred]
> > > >
> > > > 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[/color][/color][/color]
seperate[color=blue][color=green][color=darkred]
> > > > boxes). I haven't quit figured out the split function yet to use a[/color]
> > single[color=darkred]
> > > > 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[/color][/color][/color]
enter[color=blue][color=green]
> > it[color=darkred]
> > > > 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[/color][/color][/color]
not[color=blue][color=green][color=darkred]
> > > 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[/color][/color]
> As[color=green][color=darkred]
> > > > 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)) *[/color][/color][/color]
(Me.WFeet[color=blue]
> +[color=green][color=darkred]
> > > > (Me.WInch / 12))
> > > >
> > > > Me.SqrFeet = Me.txtSqrFeet.Text
> > > >
> > > > If Me.TFeet = 0 Then Me.txtYard.Text = (Me.SqrFeet *[/color][/color][/color]
(Me.TInch[color=blue]
> /[color=green][color=darkred]
> > > 12)
> > > > / 27) Else
> > > >
> > > > Me.txtYard.Text = (Me.SqrFeet * (Me.TFeet + (Me.TInch /[/color][/color][/color]
12)))[color=blue]
> /[color=green]
> > 27[color=darkred]
> > > >
> > > > End Sub
> > > >
> > > >
> > > > I know that I'm using the wrong variables here, I can't quit figure[/color][/color][/color]
it[color=blue][color=green]
> > out[color=darkred]
> > > > though.
> > > >
> > > > Thanks to Anyone Who Replies.
> > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >
> > ---
> > 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
> >
> >[/color]
>
>[/color]
---
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 | | | | re: Selecting Proper Variables
On 2004-08-29, Herfried K. Wagner [MVP] <hirf-spam-me-here@gmx.at> wrote:[color=blue]
> * David <dfoster@woofix.local.dom> scripsit:[color=green][color=darkred]
>>> 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
>>> ///[/color]
>>
>> 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.[/color]
>
> That's why there will be a 'TryParse' method for the 'Int32' datatype in
> .NET 2.0.[/color]
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 | | | | re: Selecting Proper Variables
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" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Ow6xUFqjEHA.1136@tk2msftngp13.phx.gbl...[color=blue]
> 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]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:e8zBV8pjEHA.3724@TK2MSFTNGP11.phx.gbl...[color=green]
> > SStory,[color=darkred]
> > > Better to use string.empty instead.[/color]
> > Agree, I normally use String.Empty, although I use "" also.
> >[color=darkred]
> > > using "" means vb creates a new string for each ""[/color]
> > 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[/color][/color]
string[color=blue][color=green]
> > 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" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
> > news:OXl7kKRjEHA.384@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > 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[/color][/color][/color]
<<snip>> |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|