• Welcome to Valhalla Legends Archive.
 

Visual Basic . NET

Started by bRoKeN, February 21, 2004, 07:49 PM

Previous topic - Next topic

Grok

#15
VB.NET makes such prettier code than VB6.


               'see if document has correct properties
               Dim kfDoc As AKO32.CDocument = New AKO32.CDocument
               kfDoc.hKGI = KGI
               kfDoc.OpenDocument(Doc.docid)
               Dim result As Integer = 0
               result = IIf(Len(Doc.title) = 0, 0, Math.Abs([String].Compare(Doc.title, kfDoc.Title)))
               result += IIf(Len(Doc.person) = 0, 0, Math.Abs([String].Compare(Doc.person, kfDoc.Person)))
               result += IIf(Len(Doc.type) = 0, 0, Math.Abs([String].Compare(Doc.type, kfDoc.UserType)))
               result += IIf(Len(Doc.kfdate) = 0, 0, Math.Abs([String].Compare(Doc.kfdate, kfDoc.DateCreated)))
               result += IIf(Len(Doc.description) = 0, 0, Math.Abs([String].Compare(Doc.description, kfDoc.Description)))
               result += IIf(Len(Doc.kfgroup) = 0, 0, Math.Abs([String].Compare(Doc.kfgroup, kfDoc.Group)))
               result += IIf(Len(Doc.subclass) = 0, 0, Math.Abs([String].Compare(Doc.subclass, kfDoc.Subclass)))
               If result = 0 Then      'so far so good, check keywords
                   Dim kw() As String = Split(kfDoc.UserKeywords, vbCrLf)
                   Dim lPos As Integer
                   For lPos = 1 To UBound(kw) + 1
                       Select Case lPos
                           Case 1 : result += IIf(Len(Doc.keywords1) = 0, 0, Math.Abs([String].Compare(Doc.keywords1, kw(lPos - 1))))
                           Case 2 : result += IIf(Len(Doc.keywords2) = 0, 0, Math.Abs([String].Compare(Doc.keywords2, kw(lPos - 1))))
                           Case 3 : result += IIf(Len(Doc.keywords3) = 0, 0, Math.Abs([String].Compare(Doc.keywords3, kw(lPos - 1))))
                           Case 4 : result += IIf(Len(Doc.keywords4) = 0, 0, Math.Abs([String].Compare(Doc.keywords4, kw(lPos - 1))))
                           Case 5 : result += IIf(Len(Doc.keywords5) = 0, 0, Math.Abs([String].Compare(Doc.keywords5, kw(lPos - 1))))
                           Case 6 : result += IIf(Len(Doc.keywords6) = 0, 0, Math.Abs([String].Compare(Doc.keywords6, kw(lPos - 1))))
                           Case 7 : result += IIf(Len(Doc.keywords7) = 0, 0, Math.Abs([String].Compare(Doc.keywords7, kw(lPos - 1))))
                           Case 8 : result += IIf(Len(Doc.keywords8) = 0, 0, Math.Abs([String].Compare(Doc.keywords8, kw(lPos - 1))))
                           Case 9 : result += IIf(Len(Doc.keywords9) = 0, 0, Math.Abs([String].Compare(Doc.keywords9, kw(lPos - 1))))
                       End Select
                   Next lPos
               End If

               'see if docid is contained in destination container id
               result += IIf(KGI.IsContainedIn(Doc.docid, Doc.destid), 0, 1)

               If result = 0 Then
                   'all is well, update status ...

quasi-modo

Quote from: Grok on March 02, 2004, 05:04 PM
VB.NET makes such prettier code than VB6.
I aggree. Its the little things that have evolved in the syntax that make the codeing so much easier.
WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle

Adron

Did they fix the IIf operator to only evaluate one of the expressions, and did they fix boolean logic to be short-circuited?

Banana fanna fo fanna

Quote from: peofeoknight on March 04, 2004, 04:58 PM
Quote from: Grok on March 02, 2004, 05:04 PM
VB.NET makes such prettier code than VB6.
I aggree. Its the little things that have evolved in the syntax that make the codeing so much easier.
I think he was being sarcastic.

Grok

Still ewwy.

QuoteAs part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression.

Adron

And what about boolean logic?

quasi-modo

#21
Quote from: St0rm.iD on March 04, 2004, 06:02 PM
Quote from: peofeoknight on March 04, 2004, 04:58 PM
Quote from: Grok on March 02, 2004, 05:04 PM
VB.NET makes such prettier code than VB6.
I aggree. Its the little things that have evolved in the syntax that make the codeing so much easier.
I think he was being sarcastic.
But I wasn't  :P
WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle

Grok

Quote from: Adron on March 04, 2004, 08:12 PM
And what about boolean logic?

I don't know of an obvious way to test that.  Maybe

x = 0 and (side_effect_function(z))

and see if the side effect happens?

Adron

Quote from: Grok on March 05, 2004, 06:00 AM
I don't know of an obvious way to test that.  Maybe

x = 0 and (side_effect_function(z))

and see if the side effect happens?

A typical example of when I'd want it to be short-circuited is for testing fields of a recordset like this:


If Not IsNull(rs!field) And rs!field = "something" Then


If it is short-circuited, rs!field = "something" won't be evaluated, and you won't get a run-time error.

Another example is:


If y <> 0 And x/y > 12 Then


MyndFyre

Looks like Adron's been left hanging here...

.NET evaluates boolean expressions the same way across all languages.

Your example



If x = 0 And SideEffectFunction(z)



would not call SideEffectFunction() if x was not 0.

The example


If Not IsNull(rs!field) And rs!field = "something" Then


would not use the comparison of rs!field to "something" if the first condition failed.

Cheers.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Adron

Ah, neat!

That's something that has annoyed me for a long time in VB.

quasi-modo

its just like any other language in any other scripting I mean if the first part of an and is false the comp just stops right there. Its the same in c++, the same in c, the same in java.
WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle

Adron

Quote from: peofeoknight on March 22, 2004, 04:13 PM
its just like any other language in any other scripting I mean if the first part of an and is false the comp just stops right there. Its the same in c++, the same in c, the same in java.

But different in VB.

quasi-modo

I dont know about vb6... but vb.net is just like the other scripting languages.
WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle

MyndFyre

Quote from: peofeoknight on March 22, 2004, 04:19 PM
I dont know about vb6... but vb.net is just like the other scripting languages.

uhh, no.  VB .NET is not even a scripting language!  You might be thinking of VBA (Visual Basic for Applications) or VBScript, but Visual Basic .NET is not a scripting language.

Its late binding features allow it to be used in a scripting environment, such as the dead-and-nearly-forgotten Visual Studio for Applications (Microsoft.Vsa namespace), but even that code is compiled, not interpreted.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

|