Friday, December 17, 2010

Container Transparency in HTML

As a beginner in web design, I’ve recently found out two ways to apply transparency to a container. First one makes the container and all its contents like image or text transparent.
<div style="filter:alpha(opacity=0.8); opacity:0.8;">
<p>Some contents here!</p>
</div>
The filter:alpha(opacity=0.8) enables Internet Explorer 8 and Opera 9.x to make transparency.

While this certainly should work across well known browsers, there are times when you only need the actual container transparent but not its content. Accomplishing such requirement is easy. You only need to use a CSS property rgba which stands for RED-GREEN-BLUE-ALPHA spectrum. ALPHA value is where you would put your transparency value.


To use:


< div style="background-color: rgba ( 255, 0, 0, 0.5 )" >
<p>Some contents here!</p>
</div>


Notice the text in this demo does not appear transparent but rather opaque against it's background.

Friday, December 10, 2010

How Do You Extract Image from a Flash File Library?

Even with the Adobe Flash CS3 Professional, a tool to extract images into image files is not provided. But, this is how you can do just that – so easy!

  • Open the flash project file aka the .fla source file in Adobe Flash editor.
  • Press "CTRL+L" to access a flash library window
  • Locate the desired image and select.
  • Create a new flash document (File>>New)
  • Drag'N'drop the bitmap symbol to the new flash library
  • Drag'n'drop the chosen symbol from the new library window to the stage (The white canvas area).
  • Export the flash file as image. Go to "File>>Export Image" and save the picture as a JPG or PNG file.

There is no way you can export multiple selections. Whatever is placed inside the stage will be exported. This should work for you without problem.

Thursday, December 9, 2010

Error When Trying to Attach an Existing Database

When trying to attach a SQL 2008 database today, I encountered this error:

CREATE FILE encountered operating system error 5 (error not found) while attempting to open or create the physical file 'D:\Databases\<filename>.mdf'. (.Net SqlClient Data Provider)

I’ve come across this issue every once in a while but somehow there’s this habit of forgetting the work around. So here, I post this bagger so I wouldn’t have to Google every time.

The error has something to do with SQL Server’s improved security for permissions.

Because I was logged in via SQL Server Authentication, it did not allow me to attach the database that way so that, I had to disconnect from the server and re-logon my Enterprise Manager thru Windows Authentication. Then, retried attaching my existing SQL database. And it worked!

Monday, December 15, 2008

Fill Listview Control Dynamically

Code to fill the listview control in vb.net dynamically

Dim rdGetData As SqlClient.SqlDataReader
Try
   If ListView1.Items.Count > 0 Then ListView1.Items.Clear()
   SQLCmd.CommandType = CommandType.Text
   SQLCmd.CommandText = "SELECT * from table"
   rdGetData = SQLCmd.ExecuteReader

   Dim intCount As Decimal = 0
   While rdGetData.Read
      ListView1.Items.Add(Trim("FieldName")) 'col no. 1
      ListView1.Items(CInt(intCount)).SubItems.Add(Trim
                     (rdGetContactsInfo("FieldName"))) 'col no. 2
      ListView1.Items(CInt(intCount)).SubItems.Add(Trim
                     (rdGetContactsInfo("FieldName"))) 'col no. 3
      intCount = intCount + 1
   End While
  
   rdGetData.Close()
   rdGetData = Nothing
  
   Catch Exp As Exception
      intNumError = Err.Number()
      MsgBox("[ " & CStr(intNumError) + " ] " + Err.Description,
      MsgBoxStyle.Critical, " (Program Error)")
   End Try

Code to get selected item in the textbox control into the button's click event or according to your requirment.

TextBox1.Text = ListView1.SelectedItems(0).Text
TextBox2.Text = ListView1.SelectedItems(0).SubItems(2).Text

This will copy the selected item's first value and 2nd value into the textboxes.

To display the selected text in the textbox.

Private Sub ListView1_ItemDrag(ByVal sender AsObject, 
          ByVal e As System.Windows.Forms.ItemDragEventArgs)
          Handles ListView1.ItemDrag
   TextBox1.Text = e.Item.ToString
End Sub

Sunday, December 14, 2008

Handy Code for Executing SQL Queries

Public Function ExecuteNonQuery(ByVal sSQLCmd As String, _
                        Optional ByRef sErrMsg As String = "")
                        As Boolean
   Try
   Dim strConn As String = GetConnectionString()
   Dim cConn As SqlConnection = New SqlConnection(strConn)
   cConn.Open()
   If cConn.State = ConnectionState.Open Then
         Dim cCmd As SqlCommand = New SqlCommand(sSQLCmd, cConn)
         cCmd.ExecuteNonQuery()
   End If
   If cConn.State = ConnectionState.Open Then cConn.Close()
   Return True
Catch ex As Exception
      sErrMsg = ex.Message
   End Try
End Function

Handy Code for Executing SQL Queries - Gives Table

Public Function ExecuteQuery(ByVal strQuery As String, _
                        Optional ByRef sErrMsg As String = "")
                        As Data.DataSet 
Dim oDs As New DataSet
Try
Dim strConn As String = GetConnectionString()
Dim cConn As SqlConnection = New SqlConnection(strConn)
cConn.Open()

If (cConn.State = ConnectionState.Open) Then
           Dim oDa As New SqlDataAdapter(strQuery, cConn)
           oDa.Fill(oDs)
           Return oDs
End If
If (cConn.State = ConnectionState.Open) Then cConn.Close()
Catch ex As Exception
            sErrMsg = ex.Message
        End Try
Return oDs
End Function

Creating a TextBox Control During Runtime

Public Class Form1 Inherits System.Windows.Forms.Form

   Private Sub Form1_Load(ByVal sender As System.Object, _
                          ByValue As System.EventArgs) _
                          Handles MyBase.Load 
   Dim TextBox1 as New TextBox()
   With TextBox1
     .Text = "Hello World..." 
     .Location = New Point(100,50)
     .Size = New Size(75,23)
   End With

   Me.Controls.Add(TextBox1)
End Sub

End Class