Visual Basic 2005 is not intuitive

Speaking as someone who has used a number of different isotopes of Basic over the years, I have to say that I think Visual Basic 2005 is not particularly intuitive. No doubt there are reasons for various changes that hvae been made, probably to do with Net use, but I find that the language seems unecessarily convoluted and is missing many useful commands, features and procedures that were available in earlier versions of VB. Am I alone in feeling this way?

[474 byte] By [Captain!] at [2008-1-10]
# 1

My guess is you're more fond of structured programming languages and don't like the OOP design of .Net. I like it.

TaDa at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Although I do like structured programming, that's not my point. What I'm referring to is the rather elliptical and awkward commands that replace simple ones such as left$ or the commands for file opening. It all seems to be needlessly wordy.

Captain! at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

/boggle

For several years, its been well known fact that many of the old style VB commands were being deprecated.

I am not sure how LEFT(string,length) is more awkward or elliptical than LEFT$(string,length)

/shrug

DiverKas at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

Dear Captain,

Yes you are right! I have been programming for 30 years, I needed six books about Visual Basic 2005 and .NET, and are after 18 months still constantly consulting four of them. (And many of the VB 2005 books are not so clearly written as they should, they are not really that good at showing the best practice - you have to pick teh best solution from each book. I believe some of the writers were learning along the way. And many elementary best practice information is still not in these books.) The online documentation is not as good as the VB6 documentation was.

Yes many of the string manipulations names feels like misstakes: aInt.ToStr would have been better than aInt.ToString since it is used so much. aStr.Mid, aStr.Left and aStr.right would have been better than aStr.SubString since they are used so much. But .NET is common for all .NET languages!

Don't dispear,I think - but is not absolutly sure - that you will be able to "extend" .Net classes in VB9.

Of course VB8 has much more functionality than any previous BASIC! I have for the last 25 yeares had a g (as in general or global) module with lot of utility methods in every system I have used. Many of these methods dissappeared in VB8! And other methods are much shorter when rewritten. VB8 is powerful. VB9 and VBx will be even better!

Regards

Csaba

CsabaU at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
DiverKas wrote:

/boggle

For several years, its been well known fact that many of the old style VB commands were being deprecated.

I am not sure how LEFT(string,length) is more awkward or elliptical than LEFT$(string,length)

/shrug

Hi Captain! and DiverKas,

Left returns the left position of a container or a control from the edge of the container it is in.

Sorry, it is not used for STRING functions, it seems, not in VB.Net anyway.

LEFT or Me.Left returns the left position of a FORM from the main monitor left-hand-side ( in pixels ) for a FORM.

>>>>

Code Snippet

Public Class Form1

'The next highlighted line should be one line of code.>>>>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim num As Integer = Left

'gives the same result as.>>

num = Me.Left

MessageBox.Show(num)

End Sub

End Class

Regards,

John.

JohnOliver(UK)MSP,VSIP at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

Hi Captain! , DiverKas and everyone else,

I have rewritten the old STRING functions using VB.Net.

The first position is position 1 in my functions and NOT zero as in some of the VB.Net functions.

PASTE this lot into a FORM window.

Please also read my code comments.

>>

Code Snippet

Module stringFunctions

Public Function leftString(ByVal aString As String, ByVal numOfChars As Integer)

aString = aString.Substring(0, numOfChars)

Return aString

End Function

Public Function rightString(ByVal aString As String, ByVal numOfChars As Integer)

aString = aString.Substring(aString.Length - numOfChars)

Return aString

End Function

Public Function Mid(ByVal aString As String, ByVal startPosition As Integer, ByVal numOfChars As Integer)

aString = aString.Substring(startPosition - 1, numOfChars)

Return aString

End Function

Public Function Replace(ByVal aString As String, ByVal startPosition As Integer, ByVal newString As String)

Dim tempString As String = aString

aString = leftString(tempString, startPosition - 1)

aString &= newString

aString &= tempString.Substring(startPosition - 1 + newString.Length)

Return aString

End Function

End Module

Public Class Form1

'The next highlighted line should be one line of code in the code window.>>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim str As String = "The quick brown fox jumps over the lazy dog."

Dim str2 As String = str

Dim result As String

result = leftString(str, 19)

MsgBox(result)

'or

MessageBox.Show(result) 'MessageBox has 21 overloads.

result = rightString(str, 4)

MessageBox.Show(result)

result = Mid(str, 5, 15)

MessageBox.Show(result)

result = Mid(str, 1, 30)

MessageBox.Show(result)

'Mid$ in some old version of BASIC could replace a word in a string.

'E.G. Mid$(str,41,3)="cat" would replace dog with cat.

'The string.Replace is okay for a single instance of a word.>>

str = str.Replace("dog", "cat")

MessageBox.Show(str)

'It is NOT okay where two of the same word exist.>>

str = str.Replace("cat", "the")

'Now we have two of the word "the"

'Watch this.>>

str = str.Replace("the", "very")

MessageBox.Show(str)

'Reset original string "str" to the original string.

str = str2

MessageBox.Show(str)

'Same as Mid$(str,5,5)="smart"

'The 2nd "5" is not needed as the FUNCTION uses the String.Length

str = Replace(str, 5, "smart")

MessageBox.Show(str)

End Sub

End Class

Regards,

John.

JohnOliver(UK)MSP,VSIP at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7
DiverKas wrote:

/boggle

For several years, its been well known fact that many of the old style VB commands were being deprecated.

I am not sure how LEFT(string,length) is more awkward or elliptical than LEFT$(string,length)

/shrug

Except you can't do that in Visual Basic 2005. You have to use:

Microsoft.VisualBasic.Left(string, length)

I would call that a wee bit awkward, no?

Captain! at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8

"I think Visual Basic 2005 is not particularly intuitive."

Neither is brain surgery, but no one complains about that. Why is VB supposed to be intiutive and to whom?

"Microsoft.VisualBasic.Left(string, length)

I would call that a wee bit awkward, no?"

I think that what is awkward is not knowing that an Imports statement at the beginning of a class like:

Imports Microsoft.VisualBasic

enables one to use

Left(String,length)

Just fine.

The world has not stood still since Darmouth basic. Computers do much more than they used to. VB .Net is not VB6, we've graduated from high school now as a professional and need languages that deal with the complex tasks we confront. I'm sorry if that inconveniences you.

ReneeC at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 9
ReneeC wrote:

"I think Visual Basic 2005 is not particularly intuitive."

Neither is brain surgery, but no one complains about that. Why is VB supposed to be intiutive and to whom?

"Microsoft.VisualBasic.Left(string, length)

I would call that a wee bit awkward, no?"

I think that what is awkward is not knowing that an Imports statement at the beginning of a class like:

Imports Microsoft.VisualBasic

enables one to use

Left(String,length)

Just fine.

The world has not stood still since Darmouth basic. Computers do much more than they used to. VB .Net is not VB6, we've graduated from high school now as a professional and need languages that deal with the complex tasks we confront. I'm sorry if that inconveniences you.

Well, the pointer is helpful, so thanks.

On the other hand, being polite is more important and valuable than being a (self-proclaimed) professional. Nevertheless, thanks for dropping by and enlightening me, as that will be very useful data.

And thanks to all who have added tips and help here, most of it done in a courteous fashion.

Kind regards,

The Captain!

PS - Actually, it didn't work. I put the line

Imports Microsoft.VisualBasic

At the beginning of the code, but when I deleted the words 'Microsoft.VisualBasic' from 'Microsoft.VisualBasic.left' statement, it highlighted 'left' as an error. Not sure why...

Captain! at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 10

Dear ReneeC,

Do you really claim that that, for instance

Dim deviceNameArray As String() = { AlmemoClass.deviceTypeShared, "Büchi H2"}

is intuitive? It should at least have been

Dim deviceNameArray As String[] = [ AlmemoClass.deviceTypeShared, "Büchi H2"]

or even better

String: deviceNameArray[] = [ AlmemoClass.deviceTypeShared, "Büchi H2"]

Alternatively

String: deviceNameArray= [ AlmemoClass.deviceTypeShared, "Büchi H2"]

And there are numerous other examples that seem to be late night solutions! But most languages have these kind of faults. Please read also the Boo manifest, http://boo.codehaus.org/BooManifesto.pdf for more eamples for a well though-out language.

Captain, struggle on, there isn't so much else to do!

Have a nice day!

Regards

Csaba

CsabaU at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 11

I am not sure how your environment is set up, but it works like a champ for me. Both for Windows Forms projects as well as web applications.

I have it neither referenced in the project, nor as an Import. In VS2005 at least. As long as the project is a VB project, it is assumed, not necessary to explicitly reference it. However, if it is a C# project and the VB code itself is in the App_Code folder, that may not be the case.

DiverKas at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...