Copy a file in the file system
Supply a source file name and the destination file name
Function Copyfile(ByVal sSource As String, ByVal sDest As String) As Boolean
If Err.Number = 0 Then Copyfile = True
When the sql contains the single quotes then they have to be properly escaped otherwise it will give errors
just pass the field value which you want to check and the following function will return you the properly escaped string.
eg. o’brien will be returned as o”brien and this will not cause your sql to break.
Function FixSql(ByVal sStr As String) As String
FixSql = Replace(sStr, “‘”, “””)
The following function returns the file extension only.
eg. using the following function
GetFileExtension(“c:\test\file.aspx”) will return “.aspx”
Here is the complete function, copy and paste it in your form or a module
Function GetFileExtension(ByVal sFilePath As String) As String
' Dim fullPath As String = "c:\MyDirectory\MYFile.txt"
Dim sExtension As String = IO.Path.GetExtension(sFilePath)
Here is an example of a stand alone page which can help you to move your traffic to your new page.
Just copy the following lines into a note pad , remember to change the url to the actual page where you want to redirect.
Save the page with a .aspx extension.
eg. If you save this page as “OLD.ASPX” then every time someone types in this url eg. “http://vbnet.redirect.com.au/old.aspx”
it will redirect to the new page
<%@ Page Language="VB" Debug="true" %>
Here is the funtion in vb.net to find the first Sunday of each month
Function GetFirstSunday(ByVal dt As Date) As String
Dim inputDate As DateTime
Dim outputDate As DateTime
inputDate = Convert.ToDateTime(dt)
‘ Start at the day 1
outputDate = New DateTime(inputDate.Year, inputDate.Month, 1)
‘Loop through the month looking for the first Sunday
For i As Int32 = 0 To Date.DaysInMonth(outputDate.Year, outputDate.Month)
If outputDate.AddDays(i).DayOfWeek = DayOfWeek.Sunday Then
outputDate = outputDate.AddDays(i)
Exit For ‘We’re done.. get out of the loop
GetFirstSunday = FormatDateTime(outputDate, DateFormat.LongDate)
How to generate a random number in vb.net
Function GenerateRandomNumber(iLowerRange As Integer, iUpperRange As Integer)
Dim RandomGenerator As Random
Dim intRandomNumber As Integer
RandomGenerator = New Random()
'Get the next random number
intRandomNumber = RandomGenerator.Next(iLowerRange, iUpperRange+ 1)
'Return the random # as the function's return value
In Visual Studio Go to Tools > Library Package Manager > Manage Nuget Packages for Solution.
How to add Nuget Packages
You would get the following screen, you can check the packages which you have already available in your solution, you can search for new packages and install them to your solution.
Remember: These packages need to be downloaded , each time you create a new Visual Studio solution
Packages in NUGET
This is how you would open a second window in WPF.
private void btnAppointmentPage_Click(object sender, RoutedEventArgs e)
//In this example we have already created a WPF Window and called
AppointmentsMain AppointmentWindow = newAppointmentsMain();