943,824 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4313
  • VB.NET RSS
Aug 13th, 2008
0

Variable declaration!!!

Expand Post »
I have a class named Account so I have a question. In the declarations of a new instance

Dim Newaccount as Account -----but I can declare this like..
Dim Newaccount As Account = New Account

which are the differences between both declarations?? are the same or not?


excuse me english...

besides I have another question

I have 3 functions in mi clasee

writename()
writeaccount()
writesave()

the first 2 functinos are string..so i have this.

IF name = "" then
Console.writeline("name is empty")

is the same with account and save
but the problem with save is DOUBLE so if is ="" ..I have this error.....saying....Conversion string "" in TYPE DOUBLE is invalid.............

what I can do??? because I want textmessage saying "save is empty" IF is empty
Last edited by gouki2005; Aug 13th, 2008 at 4:37 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gouki2005 is offline Offline
36 posts
since Jun 2008
Aug 13th, 2008
0

Re: Variable declaration!!!

The first just declares a variable as the class. The second creates an instance of it.
Without seeing your code I would say you need to put in "Exit Sub" after your If statement.
If it is a subroutine:
VB.NET Syntax (Toggle Plain Text)
  1. IF name = "" then Console.writeline("name is empty") : Exit Sub
If it is a function:
VB.NET Syntax (Toggle Plain Text)
  1. IF name = "" then Console.writeline("name is empty") : Return Nothing
Last edited by waynespangler; Aug 13th, 2008 at 5:50 am.
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Aug 13th, 2008
0

Re: Variable declaration!!!

Sorry..the 3 are not function the 3 are SUb.....so how can I fix the error with double type..string is not a problem....but when is double...a exception..appears..

beside the diffrences between

use a instance of the class with using a variable.to use the class...like my first post
Last edited by gouki2005; Aug 13th, 2008 at 1:42 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
gouki2005 is offline Offline
36 posts
since Jun 2008
Aug 13th, 2008
0

Re: Variable declaration!!!

hi,
Quote ...
Dim Newaccount as Account -----but I can declare this like..
Dim Newaccount As Account = New Account
First one is just a Reference not Referring any object. With out referring any object using reference (Like first one) is an exception (NullPointerException)

Second one is a reference and referring an Account object.

And then

Are you mean how to check when double valued field is left out? I think so

when no value given to double (that is default value ) is 0.0

So

VB.NET Syntax (Toggle Plain Text)
  1. Dim Save As Double
  2. .....
  3. If Save = 0.0 Then
  4. MessageBox.Show ("Empty Double")
  5. End If
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Aug 13th, 2008
0

Re: Variable declaration!!!

hi,

First one is just a Reference not Referring any object. With out referring any object using reference (Like first one) is an exception (NullPointerException)

Second one is a reference and referring an Account object.

And then

Are you mean how to check when double valued field is left out? I think so

when no value given to double (that is default value ) is 0.0

So

VB.NET Syntax (Toggle Plain Text)
  1. Dim Save As Double
  2. .....
  3. If Save = 0.0 Then
  4. MessageBox.Show ("Empty Double")
  5. End If
yeah but I am creating the error message in the sub..beside..is not working.neither...if the user doesnt write nothing and the field is empty like this = "" a exception appears I try the 0.0 but nothing the same.. string "" cant convert to double

Public Sub save(ByVal sav As Double)
If sav= 0.0 Then
Console.WriteLine("Is not valid")

Else

mainsave = sav
End If
Reputation Points: 10
Solved Threads: 0
Light Poster
gouki2005 is offline Offline
36 posts
since Jun 2008
Aug 14th, 2008
0

VB.NET Project

i need sample project using vb.net if u know anything please send me
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uma123 is offline Offline
2 posts
since Aug 2008
Aug 14th, 2008
0

Re: Variable declaration!!!

i need vb.net sample projects
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uma123 is offline Offline
2 posts
since Aug 2008
Aug 14th, 2008
0

Re: Variable declaration!!!

Quote ...
VB.NET Syntax (Toggle Plain Text)
  1. Public Sub save(ByVal sav As Double)
  2. If sav= 0.0 Then
  3. Console.WriteLine("Is not valid")
  4.  
  5. Else
  6.  
  7. mainsave = sav
  8. End If
what I understand that the user will enter the value in textbox , after you check that user did not leave it empty you can use it .
VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Dim save As Double
  3. If TextBox1.Text = "" Then ' check if the textbox is empty
  4. save = 0.0
  5. MessageBox.Show("Empty Double")
  6. Else
  7. save = Convert.ToDouble(TextBox1.Text) 'if it is not empty convert the string to double and store it in save variable
  8.  
  9. End If
also you can validate the user's input before you store it in save variable.
I hope that help you
Quote ...
i need sample project using vb.net if u know anything please send me
it is better you open new thread, and i suggest to search here since many ask same thing , Good Luck
Last edited by manal; Aug 14th, 2008 at 11:24 am.
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Project idea ! !
Next Thread in VB.NET Forum Timeline: VB.Net for AutoCAD





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC