Dim Noob as object If noob.idiot = true then MsgBox("HELP!", MsgBoxStyle.Critical)
First a little about me, I have been a programmer for 15 years, started in MS Access & Macros and soon discovered VBA. Eventually that led to VB6 with Access Backend. I am completely self taught which is probally the issue here I finally need to take the plunge and learn a programming language Joke! (well kind of!). I’m making the transition to VB.NET and SQL Server and having a hard time.
First off, in VB6 it was perfectly ok to say me.backcolor = “red”, now in VB.NET it is not. We have to think in objects! Me.BackColor = Color.Red. While I understand the concept, I can’t help but ask why? I read somewhere that the eventual goal of programming languages was to be indistinguishable from the human language..Wait a minute! Not in VB.net it’s not, in my opinion it’s going backwards! You would never desribe your car color as color.red, would would say it’s red. Like I said, I understand the concept but it seems redundant. Also, I was told I would write less code in .NET, cough cough, errrm, no sorry that’s not right either. The lines of code are longer and the code overall is more complex.
The second problem I have is with the New keyword. Again, I understand the concept, or thought I did, until I had to write the following VB code that called a stored procedure.
Dim MyConn As SqlConnection
MyConn = New SqlConnection("Data Source=crysis;Initial Catalog=Phantom;Persist Security Info=True;User ID=sa;Password=*********;Pooling=False")
Dim SQLComm As SqlCommand
SQLComm = New SqlCommand("UserLoginSP", MyConn)
SQLComm.CommandType = CommandType.StoredProcedure
SQLComm.Parameters.Add(New SqlParameter("@userID", UserIDEdit.Text))
SQLComm.Parameters.Add(New SqlParameter("@UserPassword", PasswordEdit.Text))
SQLComm.Parameters.Add("@return", SqlDbType.Int)
There are 2 issues here.
If I declare MyConn as a SqlConnection why do I have to set it to a New SqlConnection
Shouldn’t it go something like
Dim MyConn As SqlConnection
MyConn.ConnectionString = "Data Source=crysis;Initial Catalog=Phantom;Persist Security Info=True;User ID=sa;Password=*********;Pooling=False")
That would make more sense to me. The second issue is defining the parameters. This one blows me away! First there is:
SQLComm.Parameters.Add(New SqlParameter("@userID", UserIDEdit.Text))
Why? Could I not just use
SQLComm.Parameters.Add("@userID", UserIDEdit.Text)
Second of all, you do not have to use New when defining the return parameter. Why?
I want to learn VB.NET and be able to write applications. However, with the inconsistencies, I am left wondering how I will ever write my own code without plagurizing everyone elses. It’s hard to learn something if it doesn’t make sense. So if there’s any hints or information you can give me where I might be going wrong, please help me.
Thanks
First a little about me, I have been a programmer for 15 years, started in MS Access & Macros and soon discovered VBA. Eventually that led to VB6 with Access Backend. I am completely self taught which is probally the issue here I finally need to take the plunge and learn a programming language Joke! (well kind of!). I’m making the transition to VB.NET and SQL Server and having a hard time.
First off, in VB6 it was perfectly ok to say me.backcolor = “red”, now in VB.NET it is not. We have to think in objects! Me.BackColor = Color.Red. While I understand the concept, I can’t help but ask why? I read somewhere that the eventual goal of programming languages was to be indistinguishable from the human language..Wait a minute! Not in VB.net it’s not, in my opinion it’s going backwards! You would never desribe your car color as color.red, would would say it’s red. Like I said, I understand the concept but it seems redundant. Also, I was told I would write less code in .NET, cough cough, errrm, no sorry that’s not right either. The lines of code are longer and the code overall is more complex.
The second problem I have is with the New keyword. Again, I understand the concept, or thought I did, until I had to write the following VB code that called a stored procedure.
Dim MyConn As SqlConnection
MyConn = New SqlConnection("Data Source=crysis;Initial Catalog=Phantom;Persist Security Info=True;User ID=sa;Password=*********;Pooling=False")
Dim SQLComm As SqlCommand
SQLComm = New SqlCommand("UserLoginSP", MyConn)
SQLComm.CommandType = CommandType.StoredProcedure
SQLComm.Parameters.Add(New SqlParameter("@userID", UserIDEdit.Text))
SQLComm.Parameters.Add(New SqlParameter("@UserPassword", PasswordEdit.Text))
SQLComm.Parameters.Add("@return", SqlDbType.Int)
There are 2 issues here.
If I declare MyConn as a SqlConnection why do I have to set it to a New SqlConnection
Shouldn’t it go something like
Dim MyConn As SqlConnection
MyConn.ConnectionString = "Data Source=crysis;Initial Catalog=Phantom;Persist Security Info=True;User ID=sa;Password=*********;Pooling=False")
That would make more sense to me. The second issue is defining the parameters. This one blows me away! First there is:
SQLComm.Parameters.Add(New SqlParameter("@userID", UserIDEdit.Text))
Why? Could I not just use
SQLComm.Parameters.Add("@userID", UserIDEdit.Text)
Second of all, you do not have to use New when defining the return parameter. Why?
I want to learn VB.NET and be able to write applications. However, with the inconsistencies, I am left wondering how I will ever write my own code without plagurizing everyone elses. It’s hard to learn something if it doesn’t make sense. So if there’s any hints or information you can give me where I might be going wrong, please help me.
Thanks