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

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:

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

If it is a function:

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

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

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

Dim Save As Double
.....
  If Save = 0.0 Then
        MessageBox.Show ("Empty Double")
  End If

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

Dim Save As Double
.....
  If Save = 0.0 Then
        MessageBox.Show ("Empty Double")
  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

i need sample project using vb.net if u know anything please send me

i need vb.net sample projects

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

Else

mainsave = sav
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 .

Dim save As Double
        If TextBox1.Text = "" Then  ' check if the textbox is empty
            save = 0.0
            MessageBox.Show("Empty Double")
        Else
            save = Convert.ToDouble(TextBox1.Text) 'if it is not empty convert the string to double and store it in save variable 
            
        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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.