|
I've got a C# article that's ready to publish, but I'm also wanting to include a full VB version of the code and I'm struggling with this bit (I'm not a native VBer!)
In the C# code I have an Enum, and a member of it is declared like this...
LOCL = ('L' << 24) + ('O' << 16) + ('C' << 8) + 'L' ...by using the chars as values and bit shifting to get a UInteger.
Can this be replicated in VB?
[Edit] This appears to work but it feels a bit 'hacky'. Is this the best way in VB?
LOCL = (Asc("L") << 24) + (Asc("O") << 16) + (Asc("C") << 8) + Asc("L") [/Edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Saturday, July 18, 2009 7:04 AM
|
|
|
|
|
Hi Dave,
two comments:
- in the C# snippet you are using characters, and just assuming they are ASCII; if they were not, their higher byte wouldn't be zero, and clash with the surrounding characters.
- in the VB snippet the intention is clear, however this time you are using strings, not characters. A VB character literal is written as "L"c , however it works as is since ASC takes the first char of a string! I don't know how ASC would react on chars that aren't ASCII though.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: assuming they are ASCII
Hi Luc,
Yeah, I'm aware of that - but in this particular sitauation they are guaranteed to be between 0 and 255 so ASCII is a safe assumption.
Would the VB be better as
LOCL = (Asc("L"c) << 24) + (Asc("O"c) << 16) + (Asc("C"c) << 8) + Asc("L"c) ?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Yes, that is what I would write, but then I don't do VB either.
Anyway, I am not sure what your intentions are, maybe it should become a little method, with a for loop, and all. And maybe all you need is an irreversible hash as in String.GetHashCode()?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks
It's actually an enum that represents the standard reference identifiers for a stratum 1 NTP server in a NTP/SNTP packet.
This part of the packet is 4 bytes, with each byte representing a character of an abreviation (zero padded if all four characters aren't required).
I have a method that does byte[34] to string conversion, but I only want to use that if it's a non standard one. The standard ones use the enum value as a key to get a more verbose string out of a dictionary value, the non standard ones just return the 4 character string.
I could just hardcode the UInt32 value into the enum directly as a number, but it's a little more descriptive in code to use the characters and bit shift, and of course there's no overhead either.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: there's no overhead either
I would expect an optimizing compiler to reduce your C# expression to a single value; not sure if a VB compiler would see through the ASC function calls though.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Well enums are evaluated at compile time, so the VB compiler must or it wouldn't compile!
I'm only doing a VB version to be 'community friendly' and to revive a few of my very rusty VB skills.
(Once it's done, I think I'll ask Dave Kreskowiak to give it a look over!)
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: Well enums are evaluated at compile time, so the VB compiler must or it wouldn't compile!
Maybe, maybe not. I am not sure. I do know they have to be constant expressions, however that might still defer evaluation till run-time. As an enum value, that would still be fine, since it needs to be done only once.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You need to use "L"c etc if you have Option Strict on.
If you don't VB seems to cheerfully accept "L" as a char.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I'm extremely new to the programming scene. I have spent the past hour looking for code to programs just so I can get into the practice of trying to type BASIC code and then run-down errors I make. Been trying to follow the help files included with my version, and---it just doesn't seem to be clicking. In the process, I found out that perhaps maybe the version I downloaded isn't really Visual Basic at all, but perhaps some cheap-o Microsoft knock-off designed to look like real Visual BASIC. I dunno if I should've put this in the .NET framework section or this one. So don't bash me for that, because if that is the case (I have microsoft express Visual Basic 2008 version) then if you could provide a link to the real deal, that would be muchly appreciated. In addition, if anyone happens to know where I could just find code to type, of any kind, of any program that does anything, I would be even more grateful. Thank ya' kindly.
|
|
|
|
|
If you have got VB 2008 Express it's a real 'cheapo' edition since it costs nothing.
However if you want 'the real deal' you have to fork out for Visual Studio.
The Express editions are cut down versions of VS - the VB (or C#) languages in them are 'the real deal' it's just some of the bells and whistles in the IDE that are missing.
I suggest getting a book and working through it. Plenty of beginners books around good ones are usually those published by Apress and Wrox, but you could try the Sams 'VB in 24 Hours' (sorry don't have the exact details but you can find them on Amazon).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
The Express tools are fine, I use them all the time.
If you want to spend a little time and money, go read this[^]. That would be a good investment.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Heh. Well, what I meant by cheap-o knock-off isn't the price-tag (or lack thereof) it was more based on something I read during my search for code that it was just repackaged rehashed stuff. That was after I attempted to wade through the techno-jargon without getting lost. As for the books---I live in a rural part of Virginia, about 75 miles from bookstores that don't really carry anything besides how to grow tobacco and creating your first moonshine operation. Hence the appeal of just trying to find code on teh trusty intrawebz and typing it in myself, and seeing if that didn't shake a rusty bolt or two loose in the old noggin'. But failing this---there might be a way to persuade the local book-store to order something. He'll probably just see dollar signs the moment I mention "special order". Thank you all for your friendly tips and suggestions.
|
|
|
|
|
if you can't make it to a decent book store, there is always a virtual one. Try Amazon, it doesn't browse well, but it sure offers a wide choice of great books.
You are aware CodeProject hosts over 20,000 articles, and a reasonable fraction of those are interesting and good?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You should also try to google for free vb.net books. There are a surprising amount of free (and perfectly legal) books that you can download, especially for beginners.
Another way to get you started, is to type "walkthrough" in the help/search section of your visual studio. It will provide a lot of step-by-step instructions on how to do all kinds of different things, and will give you some example code that you can copy and paste. That will give you something to start with, analyze and build upon.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I need a nested GridView ctrl in vb or c#
not asp.net
bet i cant found it.
these ctrls are in asp.
please help me.
thanks
|
|
|
|
|
How to enable/disable network adapter in WinXP and Vista with VB.net code
|
|
|
|
|
Give it a new IPnumber?
Rozis
|
|
|
|
|
Without a damn good explanation to why you want to do this nobody will help you with this.
And even then it's very likely they won't.
Why? Because you should NEVER disable hardware on a pc. That's called a virus / malware and nobody here will help you with that.
|
|
|
|
|
I have friends that use NET in PPPoE protocol and sometimes they disable theire network adapter and call me with answer how to enable their network adapter. I understand how to enable and disable network adapter, I use devcon.exe download from here http://support.microsoft.com/kb/311272[^]
Thanks
|
|
|
|
|
|
No way is anyone going to do that. You can buy converteres, or you can put the code in a dll and just use it from there.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
For free; I don't think anyone would do that.
|
|
|
|
|