Friday, 13 August 2010

Being my first entry for over a week and also my first since returning from holiday, I'd though I would do a nice and easy one on this Friday afternoon and demonstrate the switch and case statement in VB.Net and C#....

Firstly, it is important to remember that the case identities correspond to the value's given from the drop down menu or listbox etc....

Ok the code for use in VB.Net is....

Select Case ListBox1.SelectedValue

Case 1
Case 2
Case 3
End Select

and for C# it's...

switch (DropDownList1.SelectedValue)

{ case "1":
case "2":

case "3":


Tuesday, 3 August 2010

How to Capitalize the First Letter of Every Word in a String

Neat little bit of coding to help anyone capitalize or make upper case the first letter of every word in a string. Quite handy this little script as first it will make sure that all letters in the string are formatted correctly...

So in VB.Net we have :

in the page load

Dim objconvertText As convertText
objconvertText = New convertText
MsgBox(objconvertText.convert("CAPITALIZE THIS!"))

and for the class

Public Function convert(ByVal theWord As String)
Dim capitalWord
capitalWord = LCase(theWord)
capitalWord = StrConv(capitalWord, VbStrConv.ProperCase)
Return capitalWord.ToString
End Function

and the same in C# is in the page load:

MessageBox.Show(convertTextFirst.capitalText("CAPITALIZE THIS!"));

and then in a class :

public static string capitalText(string theWord)
{string capitalWord;
capitalWord= theWord.ToLower();
capitalWord = char.ToUpper(capitalWord[0]) + capitalWord.Substring(1);
return capitalWord.ToString(); }

Calculating the Length of a String

Simple little one again for a Tuesday afternoon. A quick little demonstration on how to calculate the length of a string :

in c#

string test_string;
int value;
test_string = "George";
value = test_string.Length;
length.Text = value.ToString();

and also in

Dim test_string As String
Dim value As Integer
test_string = "George"
value = Len(test_string)
length.Text = value

and finally in PHP:

$howlong="how long is my string including spaces";
echo "The length of the string is : ".strlen($howlong);

Wednesday, 14 July 2010

Appointment in Outlook Express in c# and VB.NET

Something a little more challenging from a Wednesday lunchtime. Here is a little script that you can copy and paste into your page load to create an outlook appointment.

In C# enter the following code :

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Runtime.InteropServices;using Microsoft.Office.Interop.Outlook;using Outlook = Microsoft.Office.Interop.Outlook;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
Outlook.ApplicationClass myOutlookApplication = null;
myOutlookApplication = new Outlook.ApplicationClass ();
Outlook.NameSpace myNameSpace = myOutlookApplication.GetNamespace("MAPI");
object myMissing = System.Reflection.Missing.Value ;
myNameSpace.Logon(myMissing, myMissing, myMissing, myMissing);
Outlook.ContactItem myNewContact = (Outlook.ContactItem) myOutlookApplication.CreateItem (Outlook.OlItemType.olContactItem );
myNewContact.FullName = "Helmut Obertanner";System.DateTime myBirthDate = DateTime.Parse ("1.6.1968");myNewContact.Birthday = myBirthDate;myNewContact.CompanyName = "DATALOG Software AG";myNewContact.HomeTelephoneNumber = "49-89-888888888";myNewContact.Email1Address = "";myNewContact.JobTitle = "Developer";myNewContact.HomeAddress = "Frundsbergstr. 60\n80637 Munich";
Marshal.ReleaseComObject (myNewContact);Outlook.AppointmentItem myNewAppointment = (Outlook.AppointmentItem)myOutlookApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);
DateTime myAppointmentDate = DateTime.Now.AddMinutes (2.0);myNewAppointment.Start = myAppointmentDate;
myNewAppointment.Duration = 60;myNewAppointment.Subject = "Meeting to discuss plans...";
myNewAppointment.Body = "Meeting with Helmut to discuss plans.";myNewAppointment.Location = "Home Office";myNewAppointment.ReminderMinutesBeforeStart = 1;myNewAppointment.ReminderSet = true;
Marshal.ReleaseComObject (myNewAppointment);
Outlook.MailItem myNewMail = (Outlook.MailItem)myOutlookApplication.CreateItem(Outlook.OlItemType.olMailItem);
myNewMail.To = "
AN EMAIL ADDRESS TO SEND TO";myNewMail.Subject = "About our meeting...";myNewMail.Body = "Hi James,\n\n" + "\tI'll see you in two minutes for our meeting!\n\n" + "Btw: I've added you to my contact list!";
Marshal.ReleaseComObject (myNewMail);
myNameSpace.Logoff ();Marshal.ReleaseComObject (myNameSpace);Marshal.ReleaseComObject (myOutlookApplication);

And the code in VB.NET is :

Sub calendar_date(ByVal theDate As Date)
Dim objcalendarDate As outlook_appt
objcalendarDate = New outlook_appt
Response.ContentType = "text/calendar"
Response.AddHeader("content-disposition", "attachment; filename=outlook_calendar_appointment.vcs")
End Sub

Private Function str_outlooktime(ByVal dat_time As Date) As String
str_outlooktime = Format(dat_time, "HHmmss")
End Function
Private Function str_outlookdate(ByVal dat_date As Date) As String
str_outlookdate = Format(dat_date, "yyyyMMdd")
End Function
Function outlookAppt(byval theDate As DateTime)
Dim outlookvcs As New System.Text.StringBuilder
Dim subject As String
Dim content As String
Dim startdate As DateTime
Dim enddate As DateTime
subject = "TESTING"
Dim getcode As String
getcode = "=12"
content = "http://localhost:3104/deviant/review_period.aspx?code" & getcode
Dim month As Integer
month = theDate.Month
Dim day As Integer
day = theDate.Day
Dim year As Integer
year = theDate.Year
startdate = New DateTime(year, month, day, 12, 0, 0)
enddate = New DateTime(year, month, day, 19, 30, 0)
With outlookvcs
.Append("BEGIN:VCALENDAR" & vbLf)
.Append("PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN" & vbLf)
.Append("VERSION:1.0" & vbLf)
.Append("BEGIN:VEVENT" & vbLf)
.Append("DTSTART:" & str_outlookdate(startdate) & "T" & str_outlooktime(startdate) & "Z" & vbLf)
.Append("DTEND:" & str_outlookdate(enddate) & "T" & str_outlooktime(enddate) & "Z" & vbLf)
.Append("UID:1" & vbLf)
.Append("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & content & "=0A" & vbLf)
.Append("PRIORITY:3" & vbLf)
.Append("END:VEVENT" & vbLf)
.Append("END:VCALENDAR" & vbLf)
End With
Return outlookvcs
End Function
Sub outlook_appointment(ByVal code As String, ByVal thedate As DateTime, ByVal startTime As DateTime, ByVal endTime As DateTime)
Dim outlookvcs As New System.Text.StringBuilder
Dim subject As String
Dim content As String
' SET CONTENT [use '=0D' to make outlook perform a line break]
content = "Please click on the link to review the agenda for the meeting : http://localhost:2446/PM_2/prm_agenda.aspx?code" & "=" & getCode
Dim varStart_hour As String
Dim varStart_minute As String
Dim varStart_minute_st1 As String
varStart_hour = Left(startTime, 2)
varStart_minute_st1 = Left(startTime, 5)
varStart_minute = Right(varStart_minute_st1, 2)
varStart_hour = varStart_hour - 1
Dim varEnd_hour As String
Dim varEnd_minute As String
Dim varEnd_minute_st1 As String
varEnd_hour = Left(endTime, 2)
varEnd_minute_st1 = Left(startTime, 5)
varEnd_minute = Right(varEnd_minute_st1, 2)
varEnd_hour = varEnd_hour - 1

Dim varDate_month As String
Dim varDate_day As String
varDate_month = thedate.Month
varDate_day = thedate.Day
If Len(varDate_day) = 1 Then
varDate_day = "0" & varDate_day
End If
If Len(varDate_month) = 1 Then
varDate_month = "0" & varDate_month
End If
If Len(varEnd_hour) = 1 Then
varEnd_hour = "0" & varEnd_hour
End If
If Len(varStart_hour) = 1 Then
varStart_hour = "0" & varStart_hour
End If
Dim startString As String
Dim endString As String
startString = "DTSTART:" & thedate.Year & varDate_month & varDate_day & "T" & varStart_hour & varStart_minute & "00Z"
endString = "DTEND:" & thedate.Year & varDate_month & varDate_day & "T" & varEnd_hour & varEnd_minute & "00Z"
With outlookvcs
.Append("BEGIN:VCALENDAR" & vbLf)
.Append("PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" & vbLf)
.Append("VERSION:1.0" & vbLf)
.Append("BEGIN:VEVENT" & vbLf)
.Append(startString & vbLf)
.Append(endString & vbLf)
.Append("UID:1" & vbLf)
.Append("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & content & "=0A" & vbLf)
.Append("PRIORITY:3" & vbLf)
.Append("END:VEVENT" & vbLf)
.Append("END:VCALENDAR" & vbLf)
End With
Response.ContentType = "text/calendar"
Response.AddHeader("content-disposition", "attachment; filename=outlook_calendar_appointment.vcs")
End Sub

For the VB.NET code you will need to call the functions from within your page...

Convert string to integer for both C# and VB.NET

Simple one to start, how to convert a string to an integer...

in C# use the following code:

string stringOne;
int integerOne;

integerOne = Convert.ToInt32(stringOne);

and in VB.NET :

Dim stringOne as string = nothing
Dim integerOne as integer = nothing

stringOne = "10"
integerOne = Convert.ToInt32(

and a little update today to include PHP :

$aString = "10";
$aNumber= (int)$aString ;

Hope this helps someone out there...keep tuned for more coming soon.
Just a quick hello. Being straight to the point, I want to use my blog to display all the need to know scripts and codes in both C# and VB.NET. Hopefully in time I will be able to show the comparisons with PHP and maybe other languages in the future. Keep watching this space. Thank you.