Home All Groups Group Topic Archive Search About

Am I delusional or is it VB?

Author
11 May 2007 6:15 PM
Dave
Getting deeper into VB & Scanners...

This code creates only a 2 in the debugger window,
not a    1
           2
as it should:

Private Sub MSComm1_OnComm()
    Dim strScan As String
    Dim intTest As Integer
    Static strBuffer As String

    strBuffer = strBuffer + MSComm1.Input      'Creates Buffer
    If InStr(strBuffer, vbCr) Then
            strAllScans = strBuffer
            strBuffer = ""
    End If       'Buffer code courtesy of Dick Grier, MSP-Thanks Dick!
    strScan = Mid$(strScan, 5, 4)

    Select Case strScan
        Case strScan = "0040"
            intTest = 1
            Debug.Print intTest
    End Select
    If strScan = "0040" Then
        intTest = 2
        Debug.Print intTest
    End If

End Sub

I wanted to use a Select Case but it doesn't work.  It's not a project
stopper but I am "very" curious.

Any explanation will be appreciated.  (Even if it's me and not my
trustedVB).

Thanks for your help, as always.

Dave
dsm

Author
11 May 2007 6:31 PM
Lorin
It's you.
         Case strScan = "0040"   ' boolean result
s/b
         Case "0040"  ' a string

Show quoteHide quote
"Dave" wrote:

> Getting deeper into VB & Scanners...
>
> This code creates only a 2 in the debugger window,
> not a    1
>            2
> as it should:
>
> Private Sub MSComm1_OnComm()
>     Dim strScan As String
>     Dim intTest As Integer
>     Static strBuffer As String
>
>     strBuffer = strBuffer + MSComm1.Input      'Creates Buffer
>     If InStr(strBuffer, vbCr) Then
>             strAllScans = strBuffer
>             strBuffer = ""
>     End If       'Buffer code courtesy of Dick Grier, MSP-Thanks Dick!
>     strScan = Mid$(strScan, 5, 4)
>
>     Select Case strScan
>         Case strScan = "0040"
>             intTest = 1
>             Debug.Print intTest
>     End Select
>     If strScan = "0040" Then
>         intTest = 2
>         Debug.Print intTest
>     End If
>
> End Sub
>
> I wanted to use a Select Case but it doesn't work.  It's not a project
> stopper but I am "very" curious.
>
> Any explanation will be appreciated.  (Even if it's me and not my
> trustedVB).
>
> Thanks for your help, as always.
>
> Dave
> dsm
>
>
Author
11 May 2007 6:51 PM
Dave
Thanks Lorin.
Author
11 May 2007 7:03 PM
Larry__Weiss
Lorin wrote:
> It's you.
>          Case strScan = "0040"   ' boolean result
> s/b
>          Case "0040"  ' a string
>

I hadn't realized that dynamic Case evaluation was even allowed!

When used, you have to take into account what's called
"short-circuiting" when the expressionlist has more than
one expression.

http://msdn2.microsoft.com/en-us/library/cy37t14y(VS.80).aspx

   - Larry
Author
11 May 2007 7:19 PM
Robert Morley
Careful.  The link you provided is for VB2005, not VB6.  I wasn't able to
find any documentation on it in the help files, but a simple test reveals
that VB6 also exhibits the short-circuiting behaviour.


Rob

Show quoteHide quote
"Larry__Weiss" <l**@airmail.net> wrote in message
news:OMcmP8$kHHA.568@TK2MSFTNGP02.phx.gbl...
> Lorin wrote:
>> It's you.
>>          Case strScan = "0040"   ' boolean result
>> s/b
>>          Case "0040"  ' a string
>>
>
> I hadn't realized that dynamic Case evaluation was even allowed!
>
> When used, you have to take into account what's called "short-circuiting"
> when the expressionlist has more than
> one expression.
>
> http://msdn2.microsoft.com/en-us/library/cy37t14y(VS.80).aspx
>
>   - Larry
Author
11 May 2007 7:31 PM
Larry__Weiss
Good catch!   And thanks for the testing.

  - Larry

Robert Morley wrote:
Show quoteHide quote
> Careful.  The link you provided is for VB2005, not VB6.  I wasn't able to
> find any documentation on it in the help files, but a simple test reveals
> that VB6 also exhibits the short-circuiting behaviour.
>
>
> Rob
>
> "Larry__Weiss" <l**@airmail.net> wrote in message
> news:OMcmP8$kHHA.568@TK2MSFTNGP02.phx.gbl...
>> Lorin wrote:
>>> It's you.
>>>          Case strScan = "0040"   ' boolean result
>>> s/b
>>>          Case "0040"  ' a string
>>>
>>
>> I hadn't realized that dynamic Case evaluation was even allowed!
>>
>> When used, you have to take into account what's called "short-circuiting"
>> when the expressionlist has more than
>> one expression.
>>
>> http://msdn2.microsoft.com/en-us/library/cy37t14y(VS.80).aspx
>>
>>   - Larry
>
>
>
Author
11 May 2007 6:49 PM
Saga
Actually it is doing exactly what it should.

Lorin explained it well.

Saga
--



Show quoteHide quote
"Dave" <davegp2NON@SPAMMEmsn.com> wrote in message
news:1178907354.929168.258100@u30g2000hsc.googlegroups.com...
> Getting deeper into VB & Scanners...
>
> This code creates only a 2 in the debugger window,
> not a    1
>           2
> as it should:
>
> Private Sub MSComm1_OnComm()
>    Dim strScan As String
>    Dim intTest As Integer
>    Static strBuffer As String
>
>    strBuffer = strBuffer + MSComm1.Input      'Creates Buffer
>    If InStr(strBuffer, vbCr) Then
>            strAllScans = strBuffer
>            strBuffer = ""
>    End If       'Buffer code courtesy of Dick Grier, MSP-Thanks Dick!
>    strScan = Mid$(strScan, 5, 4)
>
>    Select Case strScan
>        Case strScan = "0040"
>            intTest = 1
>            Debug.Print intTest
>    End Select
>    If strScan = "0040" Then
>        intTest = 2
>        Debug.Print intTest
>    End If
>
> End Sub
>
> I wanted to use a Select Case but it doesn't work.  It's not a project
> stopper but I am "very" curious.
>
> Any explanation will be appreciated.  (Even if it's me and not my
> trustedVB).
>
> Thanks for your help, as always.
>
> Dave
> dsm
>