borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Typed Dataset)Next Topic (what is the differences between ado and ado.net ?) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Can somebody help me convert this VB.NET code to VB6
Poster Message
c0zee
Level: Guest


icon Can somebody help me convert this VB.NET code to VB6

hi all!
i found this piece of code that helps to strip extra header information when accessing an image file from SQL Server. The problem is im only using VB 6 and i need help to convert this code to VB6.
Anyone there that can help me?
Thanks in advance!

This is the code :

Private Sub LoadEmployeePhoto( _
   ByVal employeeID As Integer)

    Dim da As SqlDataAdapter
    Dim dt As New DataTable()

    BreakIfChecked(chkDebug)

    Try
      Dim strCnn As String = Constants.SQLConnectionString
      Dim strSQL As String = _
       Constants.SQLPhoto & _
       " WHERE EmployeeID = " & employeeID.ToString

      Dim msPic As MemoryStream
      Dim abytPic() As Byte

      ' Signature bytes of an
      '  OLE container header.
      Const OLEbyte0 As Byte = 21
      Const OLEbyte1 As Byte = 28

      ' Number of bytes in OLE container header.
      Const OLEheaderLength As Integer = 78

      da = New SqlDataAdapter(strSQL, strCnn)
      da.Fill(dt)
      If dt.Rows.Count > 0 Then
        ' Move binary picture data into the byte array.
        abytPic = CType(dt.Rows(0)("Photo"), Byte())

        ' Test for an OLE container header.
        If (abytPic(0) = OLEbyte0) And _
         (abytPic(1) = OLEbyte1) Then

          ' Use a second array to strip off the header.
          ' Make it big enough to hold the bytes after
          ' the header.
          Dim abytStripped( _
           abytPic.Length - OLEheaderLength - 1) As Byte

          ' Strip off the header by copying the bytes
          ' after the header.
          System.Buffer.BlockCopy( _
           src:=abytPic, srcOffset:=OLEheaderLength, _
           dst:=abytStripped, dstOffset:=0, _
           count:=abytPic.Length - OLEheaderLength)

          ' Load the new byte array into a MemoryStream.
          msPic = New MemoryStream(abytStripped)

        Else
          ' Load the original byte array into a MemoryStream.
          msPic = New MemoryStream(abytPic)
        End If

        ' Set the picture box image, using the stream.
        picEmployee.Image = Image.FromStream(msPic)
      End If
    Catch exp As Exception
      MessageBox.Show(exp.Message)
    End Try
  End Sub

04-01-2004 at 03:43 AM
| Quote Reply
thirumalaicb
Level: Sage

Registered: 09-09-2003
Posts: 51
icon Re: Can somebody help me convert this VB.NET code to VB6

Hi

In VB 6 u use ADODB.Stream. This is available only from Activex Data Objects library file 2.5 or above.

Dim strmPost As New ADODB.Stream

To read from SQL Server and to store it in a different recordset field use this code. rs and rs1 are two different recordsets.

            If rs("Photo").ActualSize > 0 Then
               strmPost.Open
               strmPost.Type = adTypeBinary
               strmPost.Write rs("Photo").Value
               rs1.Fields("Photo") = strmPost.Read
               strmPost.Close
            End If

To save it and show it in a picture holder use this code

               Dim strmPV As New ADODB.Stream
               strmPV.Type = adTypeBinary
               strmPV.Open
               strmPV.Write fld.Value
               strmPV.SaveToFile "temp.jpg"
               imgPersPhoto.Picture = LoadPicture("temp.jpg")
               Kill ("temp.jpg")
               strmPV.Close
               Set strmPV = Nothing

hope this code solve ur purpose.



____________________________
Life is at Stake; Make the most out of it!

07-01-2004 at 01:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Can somebody help me convert this VB.NET code to VB6
Previous Topic (Typed Dataset)Next Topic (what is the differences between ado and ado.net ?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder