

#Vb6 format string code
In your defense, constant expressions like 2 ^ 8 should be computed by the compiler at compile-time, so that your code never actually has to do an exponentiation operation. You are using floating-point operations in your byte-extraction code. Slooooow! To optimize the code, it will be critical that we find a way to keep these calls to a minimum.
#Vb6 format string plus
( Mat's Mug says Hex does have a variant version, so looks like this is sage advice after all!)īut the major problem here is that you're calling six different string-manipulation functions, plus concatenating those three intermediate strings. And I don't want to have to worry about it when I write or review code, so I always use the $ type suffix when I am working with strings. Personally, I have no idea whether it is actually necessary or not-is there a variant-based version of Hex? Maybe, I don't know. Now, I notice that you did correctly force the use of the string-based Right function by using the $ type suffix, which is a standard trick to ensure as optimal code as possible. String operations are extremely slow in VB since they all require multiple BSTR allocations and deallocations, not to mention the fact that the calls to the string-manipulation functions themselves cannot be inlined. Why? Well, there are a couple of reasons: Otherwise, the primary issue with your code is that it is slow! Therefore, I would rewrite your function's prototype to look like the following: Function RgbToHex(ByVal color As Long) As String Aside from that, the only prefixes you should be using are meaningful semantic ones, in the Apps Hungarian vein. The only type prefixes I allow myself are for names of controls (mostly because it makes finding them in IntelliSense significantly easier I always remember the type of control much more readily than I remember its name) and "member" prefixes ( e.g., m_). Unless you're using variants (and you probably shouldn't be) the language is sufficiently strongly-typed that embedding type information in the name of the variable serves little point. I know this used to be all the rage in VB programming, but that was mostly cargo-cult. My major issue with it is that it looks like a lame attempt at Systems Hungarian notation.

I'd say that's more a reflection on your choice of a font for your editor, but this is still a valid concern. Roland says one problem with it is that it can be difficult to distinguish from the digit 1 or a capital I. in a COM server.)Īs others have pointed out, l is a rather poor choice for a parameter name. (But it probably is what you want for strings, unless passing them out-of-process, e.g. It is certainly not what you want for primitive types like Long. ByRef is actually a perverse choice for the default, since it is almost never what you want. This should have been the default, but it wasn't in classic COM-based VB, so you need to write it out. There are only two things I would change, stylistically speaking:Įxplicitly pass input parameters by value. 'Start Loop to read data one by one from Table while ( myDBreader.The code you have works, and is very nicely-formatted. 'ExecuteReader is used to read data from table MyDBcmd = new SqlCommand( "Select * From MyDBTableName ", mySqlCnn ) 'SqlCommand Syntax: SqlCommand(Query, Conection) MySqlCnn = new SqlConnection( "Data Source= Initial Catalog= MYDBName User ID= MYDBUSERID Password= MYDBPassword ") 'SqlDataReader is used for Read data from database 'SqlCommand is used for write Query Statement
