Posts Tagged ‘Programming’

VB.NET: PHP Time() Equivalent

Tuesday, February 23rd, 2010

This piece of code will calculate seconds since the Unix Epoch (January 1 1978 00:00:00 GMT).

Private Function time() As Long
    Return time(DateTime.UtcNow)
End Function
 
Private Function time(ByVal time As DateTime) As Long
    Dim unixEpoch As New DateTime(1978, 1, 1, 0, 0, 0)
    Dim span As TimeSpan = time.Subtract(unixEpoch)
    
    Return CLng(span.TotalSeconds)
End Function
 
Private Function fromPHPTime(ByVal ticks As Long) As DateTime
    Dim unixEpoch As New DateTime(1970, 1, 1, 0, 0, 0)
    Return unixEpoch.Add(New TimeSpan(0, 0, CInt(ticks)))
End Function
VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)

Post to Twitter Post to Delicious Post to Facebook

Programmers’ Day

Friday, February 5th, 2010

The number 256 (28) was chosen because it is the number of distinct values that can be represented with an eight-bit byte—a number that is typically very well known to programmers. Also, ‘256′ in hexadecimal is ‘100′ (‘0×100′), and it’s the highest power of two that is lower than 365 (the number of days in a year). [Wikipedia]

VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)

Post to Twitter Post to Delicious Post to Facebook

VB: Opens Office Documents in Web Browser Control

Wednesday, December 2nd, 2009

Use the following steps to create a Visual Basic application that opens Office documents:

  1. Start Visual Basic and create a new Standard project. Form1 is created by default.
  2. From the Project menu, select Components to open the Components dialog box.
  3. In the Components dialog box, add references to the Microsoft Common Dialog Control and the Microsoft Internet Controls.
  4. Click OK to add the items to the toolbox.
  5. Add an instance of the WebBrowser control, CommonDialog control, and a CommandButton to Form1.
  6. Next, add the following code into the Code window for Form1:
    Option Explicit
     
    Dim oDocument As Object
     
    Private Sub Command1_Click()
       Dim sFileName As String
     
     ' Find an Office file...
       With CommonDialog1
          .FileName = ""
          .ShowOpen
          sFileName = .FileName
       End With
     
     ' If the user didn't cancel, open the file...
       If Len(sFileName) Then
          Set oDocument = Nothing
          WebBrowser1.Navigate sFileName
       End If
    End Sub
     
    Private Sub Form_Load()
       Command1.Caption = "Browse"
       ' For the 2007 Microsoft Office documents, change the .Filter parameter of the
       ' With CommonDialog1 statement to:
       ' .Filter = "Office Documents " & _
       '      "(*.docx, *.xlsx, *.pptx)|*.docx;*.xlsx;*.pptx"
       With CommonDialog1
          .Filter = "Office Documents " & _
          "(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt"
          .FilterIndex = 1
          .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
       End With
    End Sub
     
    Private Sub Form_Unload(Cancel As Integer)
       Set oDocument = Nothing
    End Sub
     
    Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, _
    URL As Variant)
       On Error Resume Next
       Set oDocument = pDisp.Document
     
       MsgBox "File opened by: " & oDocument.Application.Name
    End Sub
  7. Press F5 to run the project. When you select the Browse button, the Open dialog box appears allowing you to navigate to a Word, Excel or PowerPoint file.
  8. Choose Open and the document should open inside the WebBrowser control.
  9. A message box then appears that displays the name of the Office application that opened the file.
VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)

Post to Twitter Post to Delicious Post to Facebook

Using regular expressions in mysql

Tuesday, November 17th, 2009

Using the keyword LIKE in a SELECT query is nice and easy but sometimes very limited. For more complex searches, use the keyword REGEXP.

It allows you to enter a Regular Expression search.

$query="SELECT * FROM `db`.`tbl` WHERE `NAME` REGEXP '^Ha+([a-zA-Z]*)'";

Will return ok for Hani, Hamed, Hazem, etc…

VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)

Post to Twitter Post to Delicious Post to Facebook

Arabization Controls for Windows CE

Monday, October 20th, 2008

http://www.codeproject.com/KB/mobile/ArabizationControls.aspx

VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)

Post to Twitter Post to Delicious Post to Facebook

Get Adobe Flash playerPlugin by wpburn.com wordpress themes