Variable declaration!!!

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 27
Reputation: gouki2005 is an unknown quantity at this point 
Solved Threads: 0
gouki2005 gouki2005 is offline Offline
Light Poster

Variable declaration!!!

 
0
  #1
Aug 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Variable declaration!!!

 
0
  #2
Aug 13th, 2008
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:
  1. IF name = "" then Console.writeline("name is empty") : Exit Sub
If it is a function:
  1. IF name = "" then Console.writeline("name is empty") : Return Nothing
Last edited by waynespangler; Aug 13th, 2008 at 5:50 am.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 27
Reputation: gouki2005 is an unknown quantity at this point 
Solved Threads: 0
gouki2005 gouki2005 is offline Offline
Light Poster

Re: Variable declaration!!!

 
0
  #3
Aug 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: Variable declaration!!!

 
0
  #4
Aug 13th, 2008
hi,
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

  1. Dim Save As Double
  2. .....
  3. If Save = 0.0 Then
  4. MessageBox.Show ("Empty Double")
  5. End If
KSG
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 27
Reputation: gouki2005 is an unknown quantity at this point 
Solved Threads: 0
gouki2005 gouki2005 is offline Offline
Light Poster

Re: Variable declaration!!!

 
0
  #5
Aug 13th, 2008
Originally Posted by selvaganapathy View Post
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

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: uma123 is an unknown quantity at this point 
Solved Threads: 0
uma123 uma123 is offline Offline
Newbie Poster

VB.NET Project

 
0
  #6
Aug 14th, 2008
i need sample project using vb.net if u know anything please send me
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: uma123 is an unknown quantity at this point 
Solved Threads: 0
uma123 uma123 is offline Offline
Newbie Poster

Re: Variable declaration!!!

 
0
  #7
Aug 14th, 2008
i need vb.net sample projects
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Variable declaration!!!

 
0
  #8
Aug 14th, 2008
  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 .
  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
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.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC