Professional Documents
Culture Documents
'No Declarations
'Simple VB code to know the date and time when a file was created
'or last modified.
Sub FileCreatedDateTime()
errHandler:
End Sub
Open the form, add one label as lbltime for time to show the other lable2 as lbldate, add
tow buttons to control each. You may add one more Command button to end the program.
Command1
lbldate.text =datestring
end sub
Command2
lbltime.text =timestring
end sub
Command3
End
end sub
end class
Me.Cursor = Cursors.WaitCursor
Me.Cursor = Cursors.Default
End Sub
Determines whether the input number is a perfect square or not
Will need:
1 x text box
1 x command button
Lay out - however you like.
String:02:245:4254-25
String I have to clip is 4254 using 'instrrev'method
copy the following code and paste it in V.B 6 it will work.
Private Sub Form_Load()
a = InStrRev("02:245:4254-253", ":", Len("02:245:4254-253"))
b = InStr(1, "02:245:4254-253", "-", vbTextCompare)
MsgBox Mid("02:245:4254-253", (a + 1), ((b - a) - 1))
End Sub
No declarations
private static void exportToExcel( DataGridView dg, string fileName)
{
System.IO.StreamWriter excelDoc;
excelDoc = new System.IO.StreamWriter(fileName);
const string startExcelXML = "<xml version>\r\n<Workbook " +
"xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" +
" xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " +
"xmlns:x=\"urn:schemas- microsoft-com:office:" +
"excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" +
"office:spreadsheet\">\r\n <Styles>\r\n " +
"<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n </Style>\r\n " +
"<Style ss:ID=\"BoldColumn\">\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"Decimal\">\r\n <NumberFormat " +
"ss:Format=\"0.0000\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"Integer\">\r\n <NumberFormat " +
"ss:Format=\"0\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"DateLiteral\">\r\n <NumberFormat " +
"ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n " +
"</Styles>\r\n ";
const string endExcelXML = "</Workbook>";
int rowCount = 0;
int sheetCount = 1;
excelDoc.Write(startExcelXML);
excelDoc.Write("<Worksheet ss:Name=\"Sheet" + sheetCount + "\">");
excelDoc.Write("<Table>");
excelDoc.Write("<Row>");
for(int x = 0; x <= dg.Columns.Count -1 ; x++)
{
excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data
ss:Type=\"String\">");
excelDoc.Write(dg.Columns[x].HeaderText);
excelDoc.Write("</Data></Cell>");
}
excelDoc.Write("</Row>");
for (int i = 0; i <= dg.Rows.Count - 1; i++)
{
rowCount++;
//if the number of rows is > 64000 create a new page to continue output
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");
excelDoc.Write("<Worksheet ss:Name=\"Sheet" + sheetCount + "\">");
excelDoc.Write("<Table>");
}
excelDoc.Write("<Row>"); //ID=" + rowCount + "
for (int y = 0; y <= dg.Columns.Count - 1; y++)
{
if (dg.Rows[i].Cells[y].Value != null)
{
string XMLstring = dg.Rows[i].Cells[y].Value.ToString();
XMLstring = XMLstring.Trim();
XMLstring = XMLstring.Replace("&", "&");
XMLstring = XMLstring.Replace(">", ">");
XMLstring = XMLstring.Replace("<", "<");
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write(XMLstring);
excelDoc.Write("</Data></Cell>");
}
else
{
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write("");
excelDoc.Write("</Data></Cell>");
}
}
excelDoc.Write("</Row>");
}
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");
excelDoc.Write(endExcelXML);
excelDoc.Close();
}
'<%%>
'START OF CODE
close #1
'If you liked this peice of code please visit my website
'END OF CODE
Task: ShutsDown, Logs Off and Restarts Windows Xp - tested and works
fine. Isnt the one line of code that clames to work. Just copy and paste.
Option Explicit
Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_REBOOT As Long = 2
Private Const EWX_FORCE As Long = 4
Private Const EWX_POWEROFF As Long = 8
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, _
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
tkp.PrivilegeCount = 1
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, _
False, _
tkp, _
Len(tkpNewButIgnored), _
tkpNewButIgnored, _
lBufferNeeded
End Sub
End Sub
'All you have to do is call this sub to open a .exe using Visual Basic
Public Sub Application_Caller(pathname as String)
Shell pathname, vbNormalFocus
End Sub
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal
dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal dest
As Any, ByVal src As Any, ByVal length As Long)
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Const GMEM_MOVEABLE = &H2
outbuffer = Text1.Text
End Sub
Text2.Text = inbuffer
GlobalUnlock (hMemoryPointer)
GlobalFree (hMemory)
End Sub
Dim b As Long
For i = 1 To 3
e = e / 1024
Next
r = Round(e, 2)
Label1.Caption = "Free space on drive " & Text1.Text & " = " & r & " GB"
Rem Coloumns
Rem Employee_ID [ INT ]
Rem Employee_FName [ VARCHAR 50 ]
Rem Employee_LName [ VARCHAR 50 ]
Rem Employee_Age [ SmallInt ]
Rem Employee_Country [ VARCHAR 50 ]
Rem Remember Datatable Coloumn Names And Stored Proc Field Names Must Be
Equal.
Rem --------------------------
Code:----
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions
Imports System.Configuration
Me.BackColor = My.Settings.BackColour()
Me.Font = My.Settings.FontUse()
Me.Text = My.Settings.SystemHeader.ToString()
End Sub
Try
Me.Cursor = Cursors.WaitCursor
Dim St, Ed As DateTime
Label2.Text = ""
St = DateTime.Now.ToLongTimeString()
CryView.ReportSource = Nothing
Button1.Enabled = False
Button1.Refresh()
DSet.Tables("DTable_Employees").BeginLoadData()
Adap.Fill(DSet.Tables("DTable_Employees"))
DSet.Tables("DTable_Employees").EndLoadData()
DSet.Tables("DTable_Employees").AcceptChanges()
DSet.AcceptChanges()
PField.Name = "@LName"
DisValue.Value = TextBox1.Text
PField.CurrentValues.Add(DisValue)
PFields.Add(PField)
CryView.ParameterFieldInfo = PFields
Rpt.SetDataSource(DSet.Tables("DTable_Employees"))
CryView.ReportSource = Rpt
Ed = DateTime.Now.ToLongTimeString()
Dim IntVal As Int16 = 0
Adap.Dispose()
DSet.Dispose()
Com.Dispose()
Con.Dispose()
Button1.Enabled = True
Button1.Refresh()
Me.Cursor = Cursors.Default
Catch ex As Exception
MessageBox.Show(ex.Message, "Error ...", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Button1.Enabled = True
Button1.Refresh()
Me.Cursor = Cursors.Default
End Try
End Sub
CryView.ReportSource = Nothing
Label2.Text = ""
End Sub
End Class