[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

VS 2002 + bitshift the number by 8 bits

I am trying a FTP class from Microsoft website, and am using VS 2002, there is one section as seen below.  It doesn't work.

I have tried this code on a different machine with VS 2003 and it works fine, so it looks like the code to muliple the number by 2 ot the power of 8 is working.

        ' Make this call in Visual Basic .NET 2002. You want to
        ' bitshift the number by 8 bits. In Visual Basic .NET 2002 you must
        ' multiply the number by 2 to the power of 8.
        Dim port As Int32 = port = parts(4) * (2 ^ 8)

        ' Make this call and then comment out the previous line for Visual Basic .NET 2003.
        'Dim port As Int32 = port = parts(4) << 8

Can i do this some other way.
0
dkilby
Asked:
dkilby
  • 5
  • 3
1 Solution
 
S-TwilleyCommented:
I might be missing something but couldn't you use this instead

Dim port As Int32 = parts(4) * (2 ^ 8)

That should be a valid line assuming the value in "parts(4)" is a number.

0
 
Bob LearnedCommented:
What other way are you looking for?

Bob
0
 
dkilbyAuthor Commented:
I tried using Dim port As Int32 = parts(4) * (2 ^ 8) in VS 2002 and it comes back with a value of 0, it doesn't seem to work, because it doesnt return a valid port to connect to.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
dkilbyAuthor Commented:
just stepped through and this is the value

parts(4) = 249

port = 249 * (2 ^ 8)

after the calculation port = 0
0
 
S-TwilleyCommented:
If it's returning 0 (i.e. assigning 0 to port)... then your problem is in the parts(4) as far as i know... because that is a legit assignment.

So if this code works in VS 2003 and not in 2002.. there is something not working with the assignment to the parts array in the different versions of VS (that sounds confusing)
0
 
S-TwilleyCommented:
ok... will double check with mine
0
 
S-TwilleyCommented:
Im running VB.NET 2002... and this works alright for me:

        Dim port As Int32
        Dim parts(5) As Int32
        parts(4) = 249

        port = parts(4) * (2 ^ 8)
        Debug.WriteLine(port)

========

What is the parts array declared as in your code
0
 
dkilbyAuthor Commented:
very strange, when i use the code above it works, but if i use the one line it doesnt

oh well however it works is all i need.

Thanks
0
 
S-TwilleyCommented:
No problem...  maybe the second pair of eyes helped :P
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now