How to implement IsNumeric() VB.NET function in C#
This article describes how to implement the useful “IsNumeric” function in Microsoft Visual Basic .NET in Visual C#. The IsNumeric() function returns a Boolean value indicating whether an expression can be evaluated as a number. The IsNumeric() function returns True when the data type of the expression is Short, Integer, Long, Decimal, Single or Double. Returns True if the expression is a string that can be converted to a Double.
Add the following code to your project:
// IsNumeric Function
static bool IsNumeric(object Expression)
{
// Variable to collect the Return value of the TryParse method.
bool isNum;
// Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
double retNum;
// The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
// The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
return isNum;
}
Have a nice day!
Max
Multilingual applications with VB.NET
In this simple tutorial you’ll learn how to manage different languages for a vb.NET application and the simplest way to access programmatically to the string values in the resource compiled files (*.resx) created by Visual Studio;
Adding resource files:
First of all, add a folder named “resources/” in your project.
Inside this folder, right click then from the context menu choose “add an element” -> “new element” -> select “Resource File (resx)” -> create a file named “Resources.en-US.resx”
In the “Resources.en-US.resx” file, You have to write all the strings used by your application.
It’s important that your language resource file is named as “Resources.{Language Code Name}.resx”, so VS can reach automatically this file.
The rsx file is just a list of Key-Value items, then You have to give a key-name for each string value; don’t use spaces in key-names, otherwise it’s best using “_” symbol.
Insert only two test lines in your new rsx file as the following…
KEY – VALUE:
TEST_STRING1 us1
TEST_STRING2 us2
Then, compile your project and if it’s all right, You will find a new folder in “bin\Release\” named “en-US” created by VS, with a file “{your project name}.resources.dll”; this file contains all the strings for the english-US language (“en-US”) and right now You can access them programmatically.
If You want add a new language to your application, just copy the rsx file and rename it in “Resources.{Language Code Name}.resx” where the language code name is one of those listed at http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx.
Step 2, how to programmatically select the language and strings:
Add a vb class “Resources.vb” in the “resources\” folder with the following code
Public Class Resources
Public Shared Function GetValue(ByVal name As ResourceName) As String
Return My.Resources.ResourceManager.GetObject(name.ToString)
End Function
Public Shared Property Language() As CultureCodeName
Get
Dim c As CultureCodeName = Nothing
Dim cs As String = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString().Replace(New Char() {"-"c}, New Char() {"_"c})
For Each cc As CultureCodeName In [Enum].GetValues(GetType(CultureCodeName))
If cs = cc.ToString Then
c = cc
Exit For
End If
Next
Return c
End Get
Set(ByVal cultureCodeName As CultureCodeName)
Dim c As String = cultureCodeName.ToString.Replace(New Char() {"_"c}, New Char() {"-"c})
System.Threading.Thread.CurrentThread.CurrentUICulture = _
System.Globalization.CultureInfo.GetCultureInfo(c)
End Set
End Property
End Class
then, add a vb “code file” named “CultureCodeNames.vb” in “resources\” folder with the following code
Public Enum CultureCodeName
en_US
'if You want add a new language, after creating the rsx file,
'also add here the code name, with "-" replaced in "_"
End Enum
Finally, add the last vb codefile “ResourceNames.vb” in “resources\” folder with this code
Public Enum ResourceName
'add here all the key names in the RSX file
TEST_STRING1
TEST_STRING2
End Enum
The configuration is finished.
In your project, add a button to a form, then add the following vb code in the codebehind to learn how to access to different language RSX files and their strings inside.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Select a language for your app
Resources.Language = CultureCodeName.en_US
'show test string 1
MessageBox.Show(Resources.GetValue(ResourceName.TEST_STRING1))
'show test string 2
MessageBox.Show(Resources.GetValue(ResourceName.TEST_STRING2))
'show the current language code
MessageBox.Show(Resources.Language.ToString)
End Sub
It’s very useful because when you will be writing the code, VS automatically suggests the strings that you can use, saving a lot of time and by selecting a language with “Resources.Language”, You can translate your application strings on the fly.
Have a nice day!
Max
New version of JQUERY BUBBLE POPUP!
Hi to All,
I’ll be back soon with an updated version of JQUERY BUBBLE POPUP that supports the new jQuery library v1.7.1;
I’m already testing the final plugin however You are always able to download the older version from the following link:
https://sourceforge.net/projects/jqbubblepopup/files/latest/download
stay connected!
Max
How to configure a Yahoo! email account on your Android, BlackBerry or iPhone
Pop3/Smtp protocol is disabled as default and you need to upgrade to Yahoo! Mail Plus to download your Yahoo! Mail in an email client, such as Outlook or mobile phone, with this upgrade you are able to forward your Yahoo! Mail to a different address too;
So you need to set up a new Imap email account on your phone, for all mobile devices, supply the following information if prompted:
Incoming Server - imap.mail.yahoo.com
Outgoing Server - smtp.mail.yahoo.com
Incoming Port - 993 (requires SSL)
Outgoing Port - 465 (requires SSL)
Username: full email address (bill@yahoo.com)
Password: is the password you login to Yahoo! with
Smart Android Apps
androidVNC: http://market.android.com/details?id=android.androidVNC – get a remote desktop! control a pc everywhere from ur mobile
Chrome to Phone: http://market.android.com/details?id=com.google.android.apps.chrometophone – send urls or texts from ur browser to ur mobile
ES File Manager http://market.android.com/details?id=com.estrongs.android.pop – look for local files, over LAN or FTP
Goggles: http://market.android.com/details?id=com.google.android.apps.unveil – make a picture of what u want search on google
Google Reader: http://market.android.com/details?id=com.google.android.apps.reader – smart feed reader
Google Sky Map: http://market.android.com/details?id=com.google.android.stardroid – move ur mobile and look the stars around
Google Translate: http://market.android.com/details?id=com.google.android.apps.translate – record ur voice and translate it!
2010 in review
The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

The Blog-Health-o-Meter™ reads Wow.
Crunchy numbers
About 3 million people visit the Taj Mahal every year. This blog was viewed about 52,000 times in 2010. If it were the Taj Mahal, it would take about 6 days for that many people to see it.
In 2010, there were 23 new posts, growing the total archive of this blog to 32 posts. There were 15 pictures uploaded, taking up a total of 627kb. That’s about a picture per month.
The busiest day of the year was November 26th with 764 views. The most popular post that day was JQUERY BUBBLE POPUP v.2.0.
Where did they come from?
The top referring sites in 2010 were plugins.jquery.com, vegabit.com, webdesignish.com, dvq.co.nz, and coliss.com.
Some visitors came searching, mostly for jquery scrolling text, scrolling text jquery, jquery scroll text, jquery text scroller, and facebook for omnia i900.
Attractions in 2010
These are the posts and pages that got the most views in 2010.
JQUERY BUBBLE POPUP v.2.0 October 2010
74 comments
Linear scrolling text with jQuery February 2010
5 comments and 1 Like on WordPress.com,
How to create smart Bubble Popups with jQuery! February 2010
25 comments
jQuery Bubble Popup plugin February 2010
59 comments
jQuery Scroller Plugin – scrolling made easy September 2010
5 comments
Encrypt/Decrypt strings in .NET and get Hash codes
after reaching the 40,000 visits, thanks to all software developers who have visited my dev blog then I make them a special gift: “Cryptography” and “CryptographyHelper”, two vb. NET classes which will help you in the management of cryptographic services. Both the classes are licensed under the MIT license; You are free to use it in commercial projects as long as the copyright header is left intact.
The “CryptographyHelper” is a wrapper class of mine “Cryptography” core .net class, and it lets you to easly encrypt/decrypt strings in .NET framework using a robust symmetric Rijndael algorithm or you can get also MD5 or SHA1/SHA256 hash codes of a string.
What happens during the encryption: The CryptographyHelper encrypts a clear text and saves it in a binary stream, then converts the binary output in Hexadecimal or Base64 encoding type for a string rapresentation. The opposite job during the decryption…
A simple usage example:
Dim cryptoHelper As New CryptographyHelper
'select your favorite encoding type of the output (note that hexadecimal result is longer then base64 compression)
cryptoHelper.EncodingType = CryptographyHelper.EncodingBaseTypes.Hex 'CryptographyHelper.EncodingBaseTypes.Base64
Dim password As String = "my secret password to encrypt or decrypt strings"
Dim encryptedText As String = cryptoHelper.Encrypt("plain text to encrypt...", password)
Dim decryptedText As String = cryptoHelper.Decrypt(encryptedText, password)
'if you want get an hash of a string try out one of the following...
Dim MD5hash As String = cryptoHelper.GetHash("string to hash", CryptographyHelper.HashTypes.MD5)
Dim SHA1hash As String = cryptoHelper.GetHash("string to hash", CryptographyHelper.HashTypes.SHA1)
Dim SHA256hash As String = cryptoHelper.GetHash("string to hash", CryptographyHelper.HashTypes.SHA256)
This is the source code of the classes…
' CryptographyHelper & Cryptography .NET classes
' http://maxvergelli.wordpress.com/
' Copyright (c) 2010 Max Vergelli
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
' THE SOFTWARE.
Imports System
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Public Class CryptographyHelper
Private m_encoding As Integer
Public Enum EncodingBaseTypes As Integer
Hex = 1
Base64 = 2
End Enum
Public Enum HashTypes As Integer
MD5 = 1
SHA1 = 2
SHA256 = 3
SHA512 = 4
End Enum
Public Sub New(Optional ByVal encoding_type As Integer = EncodingBaseTypes.Hex)
'by default encryption/hashing outputs hexadecimal strings and decryption get hexstrings as input
If encoding_type <> EncodingBaseTypes.Hex And encoding_type <> EncodingBaseTypes.Base64 Then
encoding_type = EncodingBaseTypes.Hex
End If
EncodingType = encoding_type
End Sub
Public Property EncodingType() As Integer
Get
Return m_encoding
End Get
Set(ByVal value As Integer)
m_encoding = value
End Set
End Property
Public Function GetHash(ByVal input As String, _
Optional ByVal hash_type As Integer = HashTypes.MD5) As String
Dim objCrypto As New Cryptography
Dim bytes() As Byte = Nothing
Select Case hash_type
Case HashTypes.MD5
bytes = objCrypto.CreateMD5Hash(input)
Case HashTypes.SHA1
bytes = objCrypto.CreateSHA1Hash(input)
Case HashTypes.SHA256
bytes = objCrypto.CreateSHA256Hash(input)
Case HashTypes.SHA512
bytes = objCrypto.CreateSHA512Hash(input)
Case Else
bytes = objCrypto.CreateMD5Hash(input)
End Select
Dim hash As String = ""
Select Case m_encoding
Case EncodingBaseTypes.Hex
hash = objCrypto.BytesToHexString(bytes)
Case EncodingBaseTypes.Base64
hash = objCrypto.BytesToBase64(bytes)
Case Else
hash = objCrypto.BytesToHexString(bytes)
End Select
objCrypto = Nothing
Return hash
End Function
Public Function Encrypt(ByVal input As String, _
ByVal password As String) As String
Dim objCrypto As New Cryptography(password)
Dim bytes() As Byte = objCrypto.Encrypt(input)
Dim encrypted As String = ""
If bytes IsNot Nothing Then
Select Case m_encoding
Case EncodingBaseTypes.Hex
encrypted = objCrypto.BytesToHexString(bytes)
Case EncodingBaseTypes.Base64
encrypted = objCrypto.BytesToBase64(bytes)
Case Else
encrypted = objCrypto.BytesToHexString(bytes)
End Select
End If
objCrypto = Nothing
Return encrypted
End Function
Public Function Decrypt(ByVal input As String, _
ByVal password As String) As String
Dim decrypted As String = ""
If input.Length > 0 Then
Dim objCrypto As New Cryptography(password)
Dim enc_bytes() As Byte = Nothing
Select Case m_encoding
Case EncodingBaseTypes.Hex
enc_bytes = objCrypto.HexStringToBytes(input)
Case EncodingBaseTypes.Base64
enc_bytes = objCrypto.Base64ToBytes(input)
Case Else
enc_bytes = objCrypto.HexStringToBytes(input)
End Select
decrypted = objCrypto.Decrypt(enc_bytes)
objCrypto = Nothing
End If
Return decrypted
End Function
End Class
Public Class Cryptography
Private m_strKey As String = Nothing
Private m_bytKey() As Byte = Nothing
Private objTextConverter As New UnicodeEncoding
Private objRijndael As New RijndaelManaged '"rèin-daal" :)
Public Sub New(Optional ByVal encryption_key As String = "")
If encryption_key <> "" Then EncryptionKey = encryption_key
End Sub
Protected Overrides Sub Finalize()
If objTextConverter IsNot Nothing Then
objTextConverter = Nothing
End If
If objRijndael IsNot Nothing Then
objRijndael = Nothing
End If
m_strKey = Nothing
m_bytKey = Nothing
End Sub
Public Property EncryptionKey() As String
Get
Return m_strKey
End Get
Set(ByVal Value As String)
Try
'Set the key string
m_strKey = Value
'Set hash in bytes of the key string
Dim objHash256 As New SHA256Managed
m_bytKey = objHash256.ComputeHash(objTextConverter.GetBytes(m_strKey))
objHash256 = Nothing
If UBound(m_bytKey) < 0 Then Exit Property
'Set Rijndael Key and IV vector for 256 bit encryption
Dim MainKey(31) As Byte
Dim MainIV(15) As Byte
Dim iDiffBlock As Integer = 5
objRijndael.KeySize = 256 'bit
Dim n As Integer = 0
Dim x As Integer = 0
Dim y As Integer = 0
For n = 0 To UBound(MainKey)
MainKey(n) = m_bytKey(x)
If n > iDiffBlock And n <= UBound(MainIV) + iDiffBlock Then
MainIV(y) = m_bytKey(x)
y = y + 1
End If
x = x + 1
If x > UBound(m_bytKey) Then x = 0
Next
objRijndael.Key = MainKey
objRijndael.IV = MainIV
Catch
'set a blank encryption key then we cannot encrypt/decrypt
m_strKey = Nothing
End Try
End Set
End Property
Public Function Encrypt(ByVal clear_text As String) As Byte()
Dim enc_bytes() As Byte = Nothing
Try
If m_strKey IsNot Nothing Then
'get byte array from text
Dim bytes() As Byte = objTextConverter.GetBytes(clear_text)
'encrypt data
Dim encryptor As ICryptoTransform = objRijndael.CreateEncryptor()
Dim msEncrypt As New MemoryStream
Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
'write all data to the crypto stream and flush it
csEncrypt.Write(bytes, 0, bytes.Length)
csEncrypt.FlushFinalBlock()
'get encrypted byte array
enc_bytes = msEncrypt.ToArray()
msEncrypt = Nothing
csEncrypt = Nothing
End If
Catch
End Try
Return enc_bytes
End Function
Public Function Decrypt(ByVal encrypted_text() As Byte) As String
Dim dec_text As String = Nothing
Try
If m_strKey IsNot Nothing Then
Dim decryptor As ICryptoTransform = objRijndael.CreateDecryptor()
Dim msDecrypt As New MemoryStream(encrypted_text)
Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)
'prepare buffer
Dim bytes() As Byte = New Byte(encrypted_text.Length - 1) {}
'read the data out of the crypto stream
csDecrypt.Read(bytes, 0, bytes.Length)
'convert the byte array back into a string
dec_text = objTextConverter.GetString(bytes)
'strip null end chars
StripEndNull(dec_text)
msDecrypt = Nothing
csDecrypt = Nothing
End If
Catch
End Try
Return dec_text
End Function
Public Function BytesToBase64(ByVal input_bytes() As Byte) As String
Dim s As String = Nothing
Try
s = Convert.ToBase64String(input_bytes)
Catch
End Try
Return s
End Function
Public Function Base64ToBytes(ByVal input_base64 As String) As Byte()
Dim b() As Byte = Nothing
Try
b = Convert.FromBase64String(input_base64)
Catch
End Try
Return b
End Function
Public Function BytesToHexString(ByVal input_bytes() As Byte) As String
Dim s As String = Nothing
Try
'Dim s As String = BitConverter.ToString(input_bytes).Replace("-", String.Empty)
Dim builder As New StringBuilder()
For i As Integer = 0 To input_bytes.Length - 1
builder.AppendFormat("{0:x2}", input_bytes(i))
Next
s = builder.ToString()
builder = Nothing
Catch
End Try
Return s
End Function
Public Function HexStringToBytes(ByVal input_hex_string As String) As Byte()
Dim bytes As Byte() = Nothing
Try
'i variable used to hold position in string
Dim i As Integer = 0
'x variable used to hold byte array element position
Dim x As Integer = 0
'allocate byte array based on half of string length
bytes = New Byte((input_hex_string.Length) \ 2 - 1) {}
'loop through the string - 2 bytes at a time converting
'it to decimal equivalent and store in byte array
While input_hex_string.Length > i + 1
Dim lngDecimal As Long = Convert.ToInt32(input_hex_string.Substring(i, 2), 16)
bytes(x) = Convert.ToByte(lngDecimal)
i = i + 2
x += 1
End While
'return the finished byte array of decimal values
Catch
End Try
Return bytes
End Function
Public Function CreateMD5Hash(ByVal input As String) As Byte()
Dim hash As Byte() = Nothing
Try
Dim bytes() As Byte = objTextConverter.GetBytes(input)
Dim objMD5 As New MD5CryptoServiceProvider
hash = objMD5.ComputeHash(bytes)
objMD5 = Nothing
Catch
End Try
Return hash
End Function
Public Function CreateSHA1Hash(ByVal input As String) As Byte()
Dim hash As Byte() = Nothing
Try
Dim bytes() As Byte = objTextConverter.GetBytes(input)
Dim objSHA As New SHA1CryptoServiceProvider
hash = objSHA.ComputeHash(bytes)
objSHA = Nothing
Catch
End Try
Return hash
End Function
Public Function CreateSHA256Hash(ByVal input As String) As Byte()
Dim hash As Byte() = Nothing
Try
Dim bytes() As Byte = objTextConverter.GetBytes(input)
Dim objSHA As New SHA256CryptoServiceProvider
hash = objSHA.ComputeHash(bytes)
objSHA = Nothing
Catch
End Try
Return hash
End Function
Public Function CreateSHA512Hash(ByVal input As String) As Byte()
Dim hash As Byte() = Nothing
Try
Dim bytes() As Byte = objTextConverter.GetBytes(input)
Dim objSHA As New SHA512CryptoServiceProvider
hash = objSHA.ComputeHash(bytes)
objSHA = Nothing
Catch
End Try
Return hash
End Function
Private Sub StripEndNull(ByRef input_string As String)
Dim nullchar As Char = Convert.ToChar(0) '&H0
If input_string.Length > 0 And input_string.EndsWith(nullchar.ToString) Then
Dim n As Long
For n = input_string.Length - 1 To 0 Step -1
If input_string.Chars(n) <> nullchar Then
input_string = input_string.Substring(0, n + 1)
Exit For
End If
Next
End If
Convert.ToString(input_string)
End Sub
End Class
Happy Encryption/Decryption!
Max
How to remove accent marks and german umlauts from URLs and Strings in .NET
I wrote two functions in .NET to remove easly any accent and umlaut marks from a string and to get the equivalent non-accented string, this is very useful to normalize URLs; for example, with the StripAccentMarks() method, from “àbcdèéfghìlmnòpqrstùvzäöüÄÖÜ” u’ll get “abcdeefghilmnopqrstuvzaouAOU”;
besides, if u’ll need to convert each german umlaut to the corresponding two-letter chars, u can also use the ReplaceGermanUmlauts() method…
Public Shared Function StripAccentMarks(ByVal input_string As String) As String
Dim n_s As String = input_string.Normalize(NormalizationForm.FormD)
Dim s As New StringBuilder()
Dim c As Char
For i As Integer = 0 To n_s.Length - 1
c = n_s(i)
If System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) <> System.Globalization.UnicodeCategory.NonSpacingMark Then
s.Append(c)
End If
Next
Return s.ToString
End Function
Public Shared Function ReplaceGermanUmlauts(ByVal input_string As String) As String
Dim s As String = input_string</pre>
s = s.Replace("ä", "ae")
s = s.Replace("ö", "oe")
s = s.Replace("ü", "ue")
s = s.Replace("Ä", "Ae")
s = s.Replace("Ö", "Oe")
s = s.Replace("Ü", "Ue")
s = s.Replace("ß", "ss")
Return s
End Function
Have a nice day!
Max
The best plugin to ride carousels with jQuery and jCarousel
jCarousel is a jQuery plugin by Jan Sorgalla for controlling a list of items (text or images…) in horizontal or vertical order. The items, which can be static HTML content or loaded with (or without) AJAX, can be scrolled back and forth (with or without animation).
Besides, I ‘ve appreciated many features as the “circular” implementation without a “rewind effect” of the pictures, the easly styles customization and implementation with other plugins and many callback functions.
You can find a rich documentation or try out a demo at
http://sorgalla.com/projects/jcarousel/
Max
How to add a tooltip/bubble popup for each area inside an HTML image map!
Take a look at http://www.vegabit.com/Examples/image-map.html on how to add a tooltip/bubble popup for each area inside an HTML image map!


