Monday, August 29, 2011

[Research] Visual Basic - String Manipulation

StrComp-
Overloads: 0
Parameters: String1:String, String2:String, Compare:CompareMethod
Return type: Integer
Exceptions: ArgumentException
Details:
StrComp compares String2 to String1, based on the (optional) Compare parameter. If String1 comes BEFORE String2 (in order), the return will be a -1, if they are the same, it will return a 0, if it comes AFTER String 2, it will return a -1.


StrConv-
Overloads: 11
Parameters: str:String, Conversion:VbStrConv, LocaleID:Integer
Return type: String
Exceptions: ArgumentException
Details:
StrConv converts str using the VbStrConv function. for example. VbStrConv.LowerCase will return a string with all lower case letters.


StrReverse-
Overloads: 0
Parameters: Expression:String
Return type: String
Exceptions: N/A
Details:
StrReverse just reverses the order of the entire string.



StrTrim-
Overloads: 0
Parameters: str:String
Return type: String
Exceptions: N/A
Details:
StrTrim removes all leading and trailing spaces. ie, no spaces at the start, or at the end of the string.


Strings.Join-
Overloads: 0
Parameters: SourceArray:String, Delimiter:String
Return type: String
Exceptions: ArgumentException
Details:
Strings.Join will get all the values, or the specific value, from an array or string, and add them together. The Delimiter will add a certain characters (default a space) between each item that is joined. If an array has the numbers 1 to 10, and the delimiter was a colon ":", the output would be 1:2:3:4:5 etc.

Strings.Replace-
Overloads: 0
Parameters: Expression:String, Find:String, Replacement:String, Start:Integer, Count:Integer, Compare:CompareMethod
Return: String
Exceptions: ArgumentException
Details: This function replaces certain strings or characters with others, within a source string. Count counts how many have been replaced. Start is the integer location of the start of the string to search to replace.

Monday, August 22, 2011

[Research] Visual Basic - Try/Catch Block

In Exception Handling, the Try/Catch block is a large nested If loop that checks for Exceptions, and if they are found, how to deal with them.

[Research] Visual Basic - Exception Heirarchy

There are two types of Exceptions. The first are exceptions generated while the program is being run, and the other is from bad syntax in the code writing or the coding environment. This basically means that Exceptions are either caused from the program creating undesirable inputs(eg accessing outside of an existing array location), or the programmer's misuse of syntax or improper coding language, causing an error before the program is even compiled.

[Research] Visual Basic - Exception Classes

The purpose of the Exception Class is to throw Exceptions (with specific error message) so that the user can understand what is going in. It also prevents code from executing if it is not suitable or otherwise unusable. It inherits directly from System.Object class.

The Exception class has 4 constructors, Exception(), Exception(String), Exception(SerializationInfo, StreamingContext), and Exception(String, Exception).

[Research] Visual Basic - Exceptions

An exception is an event that happens when a program is told to perform an operation with unsuitable inputs. Eg, Overload Exceptions, when you try to place a number greater than the maximum in an integer, it overflows. It is, basically, an error that the program cannot recover from by itself and continue to run regardless.

Sunday, August 14, 2011

[Code] Visual Basic - Stripping Strings

In this example, I will show you how to strip a substring from a source string. The string I will be using is "Leftstring : Rightstring". In this case we will be getting Rightstring.


First, (optionally), you get the full string length using Len. This returns an integer.


Len(myString)


Then, you would use InStr to find the location of the colon. This ALSO returns an integer.


InStr(1, myString, ":")


Now we will run the Mid function with simple maths to return the RightString. We use colonPosition+2 to return the string AFTER the space, not including it.


Mid(myStr, (colonPosition+2), Len(myString))


Similarly, to return Leftstring, we would just use Mid slightly differently.


Mid(myStr, 1, (colonPosition-2))

[Research] Visual Basic Functions - HashTables

A HashTable is similar to an Array. It is a table consisting of 2 columns, Key and Value. Every item you put in to the HashTable will have a unique Key and a Value associated with it. Each Key/Value is an 'element', and are stored as DictionaryEntry object types.

To read more about HashTables, check out the MSDN article here.