Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all 1321 articles
Browse latest View live

monster list codes 2

$
0
0
Capturing audio Events

Code:

Dim WithEvents Encoder As WMEncoder

Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)
    ' Wait until the encoding process stops before
    ' exiting the application.
    If enumState = WMENC_ENCODER_RUNNING Then
        ' TODO: Handle running state.
    ElseIf enumState = WMENC_ENCODER_PAUSED Then
        ' TODO: Handle paused state.
    ElseIf enumState = WMENC_ENCODER_STOPPED Then
        ' End the application.
        End
    Else
        ' TODO: Handle other encoder states.
    End If
End Sub

Private Sub Form_Load()
    ' Create a WMEncoder object.
    Set Encoder = New WMEncoder
 
    ' Retrieve the source group collection and add a source group.
    Dim SrcGrpColl As IWMEncSourceGroupCollection
    Set SrcGrpColl = Encoder.SourceGroupCollection
    Dim SrcGrp As IWMEncSourceGroup2
    Set SrcGrp = SrcGrpColl.Add("SG_1")
   
    ' Add a video and audio source to the source group.
    Dim SrcVid As IWMEncVideoSource2
    Dim SrcAud As IWMEncAudioSource
    Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
    Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
   
    ' Identify the source files to encode.
    SrcVid.SetInput "C:\\InputFile.mpg"
    SrcAud.SetInput "C:\\InputFile.mpg"
   
    ' Choose a profile from the collection.
    Dim ProColl As IWMEncProfileCollection
    Dim Pro As IWMEncProfile
    Dim i As Integer
    Dim lLength As Long
   
    Set ProColl = Encoder.ProfileCollection
    lLength = ProColl.Count
   
    For i = 0 To lLength - 1
        Set Pro = ProColl.Item(i)
        If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
            SrcGrp.Profile = Pro
            Exit For
        End If
    Next
   
    ' Fill in the description object members.
    Dim Descr As IWMEncDisplayInfo
    Set Descr = Encoder.DisplayInfo
    Descr.Author = "Author name"
    Descr.Copyright = "Copyright information"
    Descr.Description = "Text description of encoded content"
    Descr.Rating = "Rating information"
    Descr.Title = "Title of encoded content"
     
    ' Specify a file object in which to save encoded content.
    Dim File As IWMEncFile
    Set File = Encoder.File
    File.LocalFileName = "C:\\OutputFile.wmv"
     
    ' Start the encoding process.
    Encoder.Start
End Sub


Broadcasting a Live Stream Using the Predefined UI
Code:

The following example shows how to create the predefined user interface and broadcast live multimedia content from the local computer. The audio and video sources are configured to use the default sound card and capture card. Use a blank form for this example.

' Create WMEncoderApp and WMEncoder objects.
  Dim Encoder As WMEncoder
  Dim EncoderApp As WMEncoderApp

Private Sub Form_Load()
  Set EncoderApp = New WMEncoderApp
  Set Encoder = EncoderApp.Encoder

' Display the predefined Encoder UI.
  EncoderApp.Visible = True

' Specify the source for the input stream.
  Dim SrcGrpColl As IWMEncSourceGroupCollection
  Dim SrcGrp As IWMEncSourceGroup
  Dim SrcVid As IWMEncSource
  Dim SrcAud As IWMEncSource

  Set SrcGrpColl = Encoder.SourceGroupCollection
  Set SrcGrp = SrcGrpColl.Add("SG_1")
  Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
  Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)

  SrcVid.SetInput "DEVICE://Default_Video_Device"
  SrcAud.SetInput "DEVICE://Default_Audio_Device"

' Specify a profile.
  Dim ProColl As IWMEncProfileCollection
  Dim Pro As IWMEncProfile
  Dim i As Integer

  Set ProColl = Encoder.ProfileCollection

  For i = 0 To ProColl.Count - 1
    Set Pro = ProColl.Item(i)
    If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
        SrcGrp.Profile = Pro
        Exit For
    End If
  Next

' Create a broadcast.
  Dim BrdCst As IWMEncBroadcast
  Set BrdCst = Encoder.Broadcast
  BrdCst.PortNumber(WMENC_PROTOCOL_HTTP) = 8080

' Start the encoding process.
  Encoder.Start

End Sub


Configuring Multiple Source Groups
Code:

The following example shows how you can set up two source groups with audio and video content. The first source group uses a file (C:\InputFile.mpg), and the second source group uses the default sound card and capture card. The result is broadcasted from the local computer (http://computer_name:8080).

For information about enumerating the audio and video devices on your system, see the Listing All Devices (Visual Basic) example.

Sub Main()
' Create a Windows Media Encoder object.
  Dim Encoder As WMEncoder
  Set Encoder = New WMEncoder
 
' Create a source group collection object from the WMEncoder object.
  Dim SrcGrpColl As IWMEncSourceGroupCollection
  Set SrcGrpColl = Encoder.SourceGroupCollection
 
' Create a profile collection object from the WMEncoder object.
  Dim ProColl As IWMEncProfileCollection
  Set ProColl = Encoder.ProfileCollection
 
' Add a source group named SG1 to the collection.
' Create a source object for each type of multimedia content
' in the source group.
  Dim SrcGrp1 As IWMEncSourceGroup2
  Dim SrcAud1 As IWMEncAudioSource
  Dim SrcVid1 As IWMEncVideoSource2
  Set SrcGrp1 = SrcGrpColl.Add("SG1")
  Set SrcAud1 = SrcGrp1.AddSource(WMENC_AUDIO)
  Set SrcVid1 = SrcGrp1.AddSource(WMENC_VIDEO)
 
' Create a second source group named SG2, and two source objects.
  Dim SrcGrp2 As IWMEncSourceGroup2
  Dim SrcAud2 As IWMEncAudioSource
  Dim SrcVid2 As IWMEncVideoSource2
  Set SrcGrp2 = SrcGrpColl.Add("SG2")
  Set SrcAud2 = SrcGrp2.AddSource(WMENC_AUDIO)
  Set SrcVid2 = SrcGrp2.AddSource(WMENC_VIDEO)
 
' Create an IWMEncBroadcast object and specify a port and a protocol.
  Dim Brdcst As IWMEncBroadcast
  Set Brdcst = Encoder.Broadcast
  Brdcst.PortNumber(WMENC_PROTOCOL_HTTP) = 8080
 
' Specify the input for the sources in the first source group.
' For this example, source group 1 uses file sources.
  SrcAud1.SetInput "C:\InputFile.mpg"
  SrcVid1.SetInput "C:\InputFile.mpg"
 
' Create a profile object. For brevity, this example uses the first
' profile in the collection. Then specify this profile object as
' the profile to use in source group 1.
  Dim Pro As IWMEncProfile
  Set Pro = ProColl.Item(0)
  SrcGrp1.Profile = Pro
 
' Specify the input sources for source group 2. In this example,
' the sources are the default audio and video devices.
' Set the profile for source group 2 to the same profile object.
  SrcAud2.SetInput "DEVICE://Default_Audio_Device"
  SrcVid2.SetInput "DEVICE://Default_Video_Device"
  SrcGrp2.Profile = Pro
 
' Set source group 1 to roll over automatically to source group 2.
' -1 indicates that the rollover happens when source group 1
' has been encoded.
  SrcGrp1.SetAutoRollover -1, "SG2"
 
' Start encoding.
  Encoder.Start

' For this example, use a message box to stop the application when you
' have finished encoding.
  MsgBox "Click OK to stop encoding."

End Sub


Controlling a Digital Device (Visual Basic)

Code:

Controlling a Digital Device (Visual Basic)
This example shows how to:

Use a digital device as a source.
Use VCR-style buttons to forward, rewind, play, and stop the tape.
View the device output as you cue the tape before encoding.
Use events to monitor changes in state.
This example uses a pre-preview to display the stream before encoding begins, and a preview of the stream during encoding.

To use this example, you need:

A form (Form1).
A frame (PreviewFrame).
Four VCR-style buttons (btnREW, btnPLAY, btnFF, and btnSTOP).
A button to start the encoding process (btnEncode).
A label (Label1) for displaying the state of the device.
In addition to the Windows Media Encoder reference, you must also add the Windows Media Encoder Device Control and the Windows Media Encoder Preview Control references to your project.

It is also assumed that you have a digital device connected to the computer. The Windows Media Encoder SDK supports digital video (DV) devices connected to an IEEE 1394 digital video port, and video tape recorder (VTR) devices connected through a COM port using the Sony RS422 protocol.

Option Explicit

'Declare variables.
Dim WithEvents Encoder As WMEncoder
Dim SrcGrpColl As IWMEncSourceGroupCollection
Dim SrcGrp As IWMEncSourceGroup2
Dim SrcAud As IWMEncSource
Dim SrcVid As IWMEncVideoSource
Dim ProColl As IWMEncProfileCollection
Dim Pro As IWMEncProfile
Dim File As IWMEncFile
Dim DCPlugMgr As IWMEncDeviceControlPluginInfoManager
Dim PlugInfo As IWMEncPluginInfo
Dim DCColl As IWMEncDeviceControlCollection
Dim DControl As IWMEncDeviceControl
Dim DCPlugin As IWMEncDeviceControlPlugin
Dim DVColl_Preview As IWMEncDataViewCollection
Dim Preview As WMEncDataView
Dim PrePreview As WMEncPrepreview
Dim lPreviewStream As Integer
Dim sDeviceString As String
Dim i As Integer, j As Integer

Private Sub Form_Load()
' Create a WMEncoder object.
  Set Encoder = New WMEncoder

' Retrieve a device control plug-in info manager object from WMEncoder.
  Set DCPlugMgr = Encoder.DeviceControlPluginInfoManager

' Loop through the connected digital devices on the system such as DV cameras and VTRs.
  For i = 0 To DCPlugMgr.Count - 1

  ' Set the IWMEncPluginInfo object to the current plug-in.
    Set PlugInfo = DCPlugMgr.Item(i)
   
  ' Find the first device plug-in that supports resources.
    If PlugInfo.SchemeType = "DeviceControl" And PlugInfo.Resources = True Then
        sDeviceString = PlugInfo.Item(0)
        Exit For
    End If

  Next i
 
' Add the device as the audio source and video source.
  Set SrcGrpColl = Encoder.SourceGroupCollection
  Set SrcGrp = SrcGrpColl.Add("SG_1")
  Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
  Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
  SrcAud.SetInput ("Device://" & sDeviceString)
  SrcVid.SetInput ("Device://" & sDeviceString)

' Encode to a file.
  Set File = Encoder.File
  File.LocalFileName = "C:\DeviceOutput.wmv"
   
' Select a profile from the collection and set it into the source group.
  Set ProColl = Encoder.ProfileCollection
  For i = 0 To ProColl.Count - 1
    Set Pro = ProColl.Item(i)
    If (Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)") Then
        SrcGrp.Profile = Pro
    End If
  Next i
   
' Retrieve the device control collection, then add a device to it.
  Set DCColl = SrcGrp.DeviceControlCollection
  Set DControl = DCColl.Add
  DControl.SetInput ("DeviceControl://" & sDeviceString)

  ' Initialize the encoding session.
  Encoder.PrepareToEncode True

  ' Get the plug-in from the device.
  Set DCPlugin = DControl.GetDeviceControlPlugin

  ' Get the source plug-in for the pre-preview and then display it in the frame.
  Set PrePreview = SrcVid.GetSourcePlugin
  PrePreview.SetCaptureParent PreviewFrame.hWnd

  ' Retrieve the preview collection and create a preview object.
  Set DVColl_Preview = SrcVid.PreviewCollection
  Set Preview = New WMEncDataView

End Sub
Private Sub btnEncode_Click()
  ' Specify the stream to preview.
  lPreviewStream = DVColl_Preview.Add(Preview)
 
  ' Disable the VCR buttons.
  btnREW.Enabled = False
  btnPLAY.Enabled = False
  btnFF.Enabled = False
  btnSTOP.Enabled = False
   
  ' Start encoding.
  Encoder.Start

  ' Display the preview in PreviewFrame.
  Preview.SetViewProperties lPreviewStream, PreviewFrame.hWnd
  Preview.StartView (lPreviewStream)
   
End Sub
Private Sub btnREW_Click()
  ' Rewind.
  DCPlugin.SetOperation (WMENC_DEVICE_REW)
End Sub
Private Sub btnPLAY_Click()
  ' Play.
  DCPlugin.SetOperation (WMENC_DEVICE_PLAY)
End Sub
Private Sub btnFF_Click()
  ' Forward.
  DCPlugin.SetOperation (WMENC_DEVICE_FF)
End Sub
Private Sub btnSTOP_Click()
  ' Stop.
  DCPlugin.SetOperation (WMENC_DEVICE_STOP)
End Sub

Private Sub Encoder_OnDeviceControlStateChange(ByVal EnumState As WMEncoderLib.WMENC_DEVICECONTROL_STATE, ByVal sName As String, ByVal sScheme As String)
' When the device state changes, display the state in Label1.
  Select Case EnumState:
        Case WMENC_DEVICECONTROL_PLAYING
        Label1.Caption = "Playing"
       
        Case WMENC_DEVICECONTROL_STOPPED
        Label1.Caption = "Stopped"
       
        Case WMENC_DEVICECONTROL_FASTFORWARDING
        Label1.Caption = "Forwarding"
       
        Case WMENC_DEVICECONTROL_REWINDING
        Label1.Caption = "Rewinding"
       
        Case WMENC_DEVICECONTROL_UNSTABLE
        Label1.Caption = "Unstable"
       
        Case WMENC_DEVICECONTROL_EJECT
        Label1.Caption = "Eject"
       
        Case WMENC_DEVICECONTROL_ENDOFTAPE
        Label1.Caption = "End of tape"
        bDone = True
       
    End Select
   
 End Sub


How to read last two records in .txt file in VB?

$
0
0
Hi ,

I am very new to VB. Actually i am Mainframe resouce and i got an oppertunity to write hummingbird programming scrip which is equal to VB.

As i have tight deadlines, i am not able to spend much time on learning VB. Hence i am looking for quick help.

I got a situation to read the last two records in .TXT file for some comparision logic. So,

Can you please help on how to read the last two records in .TXT file?
How to read specific record in .TXT file?
how to write the record in beginning of the .txt file every time that we write (Append at first line)

Thanks a lot in advance for your in-time help. Look fwd for your valuable response. Thanks!

Regards
Agasthya

VB6 - BmpGen Helper Class for WIA 2.0

$
0
0
Problem

While WIA 2.0 provides a lot of handy image capture and manipulation tools for VB, VBA, and VBScript one thing it isn't good at is creating a blank image.

There is a standard way to do this and it is even described in the code samples within the WIA 2.0 documentation. The bad news is that for anything but tiny images this can be impractically slow because of the way the WIA.Vector's .Add() method works for creating ARGB bitmaps.


Solution

You can load an image into a WIA.ImageFile object from a disk file in any of several image file formats. This works well for some applications, especially if you need a fairly complex background image to stamp other things onto. The downsides are that (a.) you need to carry along this extra image file with your program, and (b.) it doesn't address cases where you need to deal with images of sizes unknown until runtime.

However you do have the option of loading an image file "image" from a Byte array into a WIA.Vector through its .BinaryData property, and from there you can create an ImageFile object or a StdPicture object. This means you could store such a serialized "image file" as a resource and use it, or you might build one on the fly.

This is what the BmpGen object does with its single .MakeMono() method: create and return a monochrome BMP file image as a Byte array, with the dimensions and background color you specify. This addresses the dynamic dimensions issue.


Demo

The BmpGen class is packaged along with a demo Project in the attached archive.

The purpose of the demo is to show how you might make use of BmpGen.MakeMono() along with WIA to create "blank" solid color backdrop images to manipulate further. It also helps compare the performance of this technique with the standard wa of making a blank image with WIA, which gets much slower as the image dimensions increase.

Each of the three test cases creates a background and then stamps two transparent GIF "screen beans" characters onto it and displays the result in a VB6 Image control.

Name:  sshot.png
Views: 122
Size:  14.7 KB

The "fancy" test case loads an included PNG file from disk as the background. This works well enough and might be better for cases where you don't want a simple solid color backdrop, but has the limitations already described above.

The timings cover just the creation of the backdrop image prior to the stamping steps. They're rough timings based on Timer() but this should be accurate enough to illustrate the difference in performance.


Requirements

BmpGen has no dependencies that aren't included in Windows 95 or later. The demo itself requires WIA 2.0 which is part of Windows Vista and subsequent versions of Windows, and can also be installed into Windows XP SP1 or later if you grabbed the download before Microsoft removed it in preparation for XP's impending retirement.

To use the demo as-is you need VB6, but you could also do the same kind of thing in VBA applications making use of BmpGen which has no VB6-specific features in it.

VBScript is not supported, but you could create an VB6 ActiveX DLL containing BmpGen and make use of that in VBScript.
Attached Images
 
Attached Files

VB6 - Print StdPicture Objects

$
0
0
I'm sure this has been covered lots of times already, but here's another take.

The basic idea is to use the Printer object's PaintPicture method to crop and scale a StdPicture as you print it. The only wrinkle here is making a few API calls to the spooler to get lists of paper sizes and printer resolutions. The user picks those things and thenwe have the metrics we need to calculate our cropping and scaling.

This demo uses a fixed StdPicture that it loads from a sample image file included in the attached archive. You could just as easily use StdPictures from a PictureBox, a WIA object, or from somewhere else. It scales the picture to fit centered within the bounds of some fixed-size margins within a chosen paper size and orientation:

Name:  Illustration.png
Views: 64
Size:  131.0 KB

You could add cropping, you could use user-chosen margins, you could fit the image into some smaller region of the paper, etc. Here I just show how you'd go about it. To make those changes you'd just modify the calculations to fit your needs.

Code:

Private Sub cmdPrint_Click()
    'Print the StdPicture Pic centered on the selected rrinter (Pr)
    'with the selected paper (lstPapers) at the selected quality
    '(lngResolutions) within set margins.
    Dim MarginsLR As Single
    Dim MarginsTB As Single
    Dim PrintableWidth As Single
    Dim PrintableHeight As Single
    Dim ScaleFactor As Double
    Dim ScaledWidth As Double
    Dim ScaledHeight As Double

    Set Printer = Pr
    With Printer
        'Set up paper:
        .PaperSize = intPaperIds(lstPapers.ListIndex)
        .PrintQuality = lngResolutions(2 * lstResolutions.ListIndex) 'We can only set one
                                                                    'value DPI value, just
                                                                    'use X here.
        If optOrientation(1).Value Then
            .Orientation = vbPRORLandscape
        Else
            .Orientation = vbPRORPortrait
        End If

        'Scale to paper, using 0.5" margins all around.  Could also crop
        'the image here:
        MarginsLR = .ScaleX(0.5, vbInches, .ScaleMode)
        MarginsTB = .ScaleY(0.5, vbInches, .ScaleMode)
        PrintableWidth = .Width - 2 * MarginsLR
        PrintableHeight = .Height - 2 * MarginsTB

        ScaleFactor = PrintableWidth / .ScaleX(Pic.Width, vbHimetric, .ScaleMode)
        If ScaleFactor * .ScaleY(Pic.Height, vbHimetric, .ScaleMode) > PrintableHeight Then
            ScaleFactor = PrintableHeight / .ScaleY(Pic.Height, vbHimetric, .ScaleMode)
        End If

        ScaledWidth = ScaleFactor * .ScaleX(Pic.Width, vbHimetric, .ScaleMode)
        ScaledHeight = ScaleFactor * .ScaleY(Pic.Height, vbHimetric, .ScaleMode)

        'Paint (print) the image, scaled.  Could also do the actual cropping
        'here if any were desired by specifying additional arguments:
        .PaintPicture Pic, _
                      (.Width - ScaledWidth) / 2, _
                      (.Height - ScaledHeight) / 2, _
                      ScaledWidth, _
                      ScaledHeight
        .NewPage
        .EndDoc
    End With
End Sub

The demo application looks like this:

Name:  sshot.png
Views: 66
Size:  29.4 KB

You could show the paper sizes in mm or inches instead of 1/10 mm by doing the calculations. Those are just the units returned by the print spooler so to keep code complexity down I used them as is.

The code involved is fairly brief and the Project files are small. The attached archive is only so large because of the included sample image.
Attached Images
  
Attached Files

VB6 MiniMP3 (Standalone)

$
0
0
Hi,

I have converted my Mini MP3 Player which was using Window Media Player available here to a standalone version. Any comments and suggests welcome.

Nightwalker
Attached Files

WAV Player with Simulated Real-Time Sine Wave Display

$
0
0
Plays .wav files and displays the sine wave. The sine wave appears to be created in real time but it is not. The sound is captured first in a buffer then converted to it's sine wave. A Picturebox holds the graphics of the sine wave while a 2nd Picture which sits on top of the this Picturebox moves horizontally across the graphical Picturebox thus revealing the sine wave as though it was being displayed in real time
Attached Images
 
Attached Files

VB6 Tools: VB6 Rapihken Kabeh (Code Formatter)

$
0
0
This VB6 Add-Ins tools will format your code easy, based on Bobo Code Formatter.

How to use:

  1. Compile
  2. Double click install.bat
  3. Open your project click Add-Ins >> Rapikan Kode.
  4. Simply click Button Rapihken Wawarehan for formatting single (current) Code Module or check Rapihken Kabehanana for formatting all Code Module, please wait while VB6 Rapihken Kabeh working.


Warning!
Please backup your code before use this tools.
Attached Files

VB6 - SQL Parameters Example

$
0
0
Background

I'll start with a quote:

Why Parameters are a Best Practice
Quote:

Perhaps the single most important SQL Server application development Best Practice is the consistent use of parameters in application code. Parameterized database calls are more secure, easier to program and promote query plan reuse. Yet I continue to see code with SQL statements constructed by concatenating literal strings with variable values. I think this is largely out of ignorance rather than design so I decided to show how easy it is for .NET application developers to use parameters and peek into the internals to show why parameters are so important.
The same applies to VB6 just as well. However Dan's examples don't help us much since we're using ADO rather than any of the .Net data connector technologies.

So here is a simplified demo showing how to do similar things in VB6 with ADO.


The Demo

This is a simple demo showing the use of named ADO Command objects to perform parameter queries. It also shows how to store photos in the database as BLOB fields, retrieve them, display them, and update them.

While the demo uses Jet 4.0 to make it quick and easy to "unzip and play" the demo, these same concepts apply to other databases that you can use ADO with.


What It Does

When the program runs it begins by looking for an existing database. If found, it asks whether to delete it and create a new one or not.

If it creates a new database it then:

  • Removes any existing database.
  • Creates an empty database with one table [PicTable] with three fields:
    • [ID] an autonumber "identity" field set as the primary key.
    • [Description] a variable length (0-255 character) text field.
    • [Picture] a variable length (0-20000 byte)) long binary (BLOB) field.
  • Closes the empty database.
  • Reopens the database defining commands InsertPic and UpdatePic on the Connection.
  • Populates the table with three sample records based on information in a provided text file and JPEG images in a subfolder.


Else it then:

  • Opens the existing database defining the command UpdatePic (since it won't need InsertPic).


Finally, it:

  • Displays the first record, showing all three fields.


The user interface has three buttons:

  • "Back" and "Next" to step through records and display them.
  • "Replace Photo" to replace the photo of the current record by a provided fixed replacement JPEG and redisplay the updated record.


The Command objects are used to do a SQL INSERT and a SQL UPDATE. They are invoked as dynamic methods of the open Connection object.


Running the Demo

Just unzip into a folder and open the Project in the VB6 IDE. Then go ahead and run it.

Step through the records. When you see the "wrong" picture you can click Replace Photo to update with a hard-coded replacement photo.

Name:  sshot1.jpg
Views: 99
Size:  16.9 KB

Name:  sshot2.jpg
Views: 85
Size:  16.2 KB


Close the program. Run it again and when prompted to create a new empty database click the "No" button.

Step through the records to see that the update was permanent.


Defining Named ADO Command Objects

By creating named Command objects you can use them dynamic methods of the Connection object until they are destroyed or disconnected. Here is what the demo does when connecting to the database after it has been created:

Code:

Public Sub OpenDbDefineCommands(ByVal NewDb As Boolean)
    Set conDB = New ADODB.Connection
    conDB.Open strConn

    If NewDb Then
        Set cmndInsert = New ADODB.Command
        With cmndInsert
            .Name = "InsertPic"
            .CommandType = adCmdText
            .CommandText = "INSERT INTO [PicTable] " _
                        & "([Description], [Picture]) " _
                        & "VALUES (?, ?)"
            .Parameters.Append .CreateParameter(, adVarWChar, adParamInput, 255)
            .Parameters.Append .CreateParameter(, adLongVarBinary, adParamInput, MAX_PHOTO_BYTES)
            .Prepared = True
            Set .ActiveConnection = conDB
        End With
    End If

    Set cmndUpdate = New ADODB.Command
    With cmndUpdate
        .Name = "UpdatePic"
        .CommandType = adCmdText
        .CommandText = "UPDATE [PicTable] " _
                    & "SET [Picture] = ? " _
                    & "WHERE [ID] = ?"
        .Parameters.Append .CreateParameter(, adLongVarBinary, adParamInput, MAX_PHOTO_BYTES)
        .Parameters.Append .CreateParameter(, adInteger, adParamInput)
        .Prepared = True
        Set .ActiveConnection = conDB
    End With
End Sub

ADO will actually create entries in the Parameters collection itself on first use of a Command if you do not Create/Append them yourself. However it has to "guess" at things like the data type and length 9for variable length types).

In the cases here, those "guesses" are fine... until they aren't.

Let's say when you populate the new, empty database your first image is 4000 bytes. This will cause ADO to set the maximum length of the 2nd Parameter to 4000. And if you use the Command again passing an image larger than 4000 bytes you will get a runtime error!


Calling Named ADO Command Objects

You can call the Execute method on these Command objects, or you can also use them as dynamic methods of the Connection:

Code:

Public Function UpdatePic(ByVal PicFileName As String, ByVal ID As Long) As Boolean
    'Returns True if the operation fails.

    On Error Resume Next
    conDB.UpdatePic LoadPicBlob(PicFileName), ID
    If Err Then
        conDB.Errors.Clear
        Err.Clear
        UpdatePic = True
    End If
End Function

Private Function LoadPicBlob(ByVal PicFileName As String) As Byte()
    Dim PicFile As Integer
    Dim PicBlob() As Byte

    PicFile = FreeFile(0)
    Open PHOTOS_FOLDER & PicFileName For Binary Access Read As #PicFile
    ReDim PicBlob(LOF(PicFile) - 1)
    Get #PicFile, , PicBlob
    Close #PicFile
    LoadPicBlob = PicBlob
End Function

Attached Images
  
Attached Files

VB6 SQLite DB-Demos (based on the RichClient-Framework)

$
0
0
SQLite (http://sqlite.org/)

...is the worlds most widely deployed DB-engine (running on nearly every mobile-device or tablet - but it is also "strong on the Desktop",
being the Default-App-DB for Firefox or WebKit or Thunderbird - and many other vendors/applications.

The (SingleFile-DB-) Format is unicode-capable and interchangeable among operating-systems (no matter if little-endian or big-endian-based).
Means, if you copy an SQLite-DB from your iPhone (or Linux-Server) onto your Win-Desktop, you will have no problem accessing it there (and vice versa).

It still has a pretty small footprint, but other than the name may suggest, it is by no means "Lite" in the technical sense anymore...
So, if there is a strong competitor for the very often used JET-engine, VB5/6-users so far prefer as their "typical App-DB", SQLite is it...

Features (not found in JET-*.mdbs)
- Triggers
- FullText-Search (FTS4)
- true InMemory-DBs (for "LINQ-like" query-scenarios in your VB6-App, using cMemDB and cRecordset)
- strong (and compared with JET "unhackable") encryption on the whole DB (only 10-15% performance-decrease)
- userdefinable Collations (String-Comparisons for Sorts)
- userdefinable SQL-Functions (calling back into easy codable, native compilable VB6-code)
- UTF8-String-storage by default (resulting in typically smaller DBs, compared with JET, which preferrably stores in UTF-16)

Performance (compared with JET)
- typically 2-3 times as fast in read-direction (Rs-retrieval, complex Selects)
- typically 10 times as fast in write-direction (Bulk-Inserts/Updates/Deletes wrapped in transactions, import-scenarios with typically 200000 new inserted Records per second)

VB6-access per DAO/ADO...
Over ODBC ... a well-written SQLite-ODBC-driver can be found here:
http://www.ch-werner.de/sqliteodbc/

VB6-access without any MS-(DAO/ADO) dependencies...
per builtin (ADO-like) cConnection/cRecordset/cCommand-Classes in vbRichClient5:
http://www.vbRichClient.com/#/en/Downloads.htm

These wrapper-classes work faster than the above mentioned ADO/ODBC-combination.

Ok, Demo-Apps:

First a simple one, still using the normal GUI-controls of VB6, to not "alienate" anybody ...(as said, the usage of the DB-related classes is pretty much comparable to ADO)... ;-)

Thanks to dilettante for the nice Original, which can be found (as an ADO/JET-version) here:
http://www.vbforums.com/showthread.p...meters-Example

The version below is not that much different (aside from the AddNew and Delete-Buttons - and the SQLite-engine of course).
http://www.vbRichClient.com/Download...DemoSQLite.zip




Finally an SQLite-Demo, which does not only replace ADO/JET, but also the VB6-GUI-controls ...
There isn't any Common-Controls involved, only the Widget-engine of the RichClient-library comes into play here
(in conjunction with the vbWidgets.dll, which is hosted on GitHub: https://github.com/vbRichClient/vbWidgets).

The Original to this still simple Demo is also based on ADO/JET, and can be found on PSC:
http://www.planet-source-code.com/vb...35601&lngWId=1

There's one thing "special" (aside from the vbWidgets) in this demo - and that's the regfree-deployment-feature,
which is supported (without manifests and SxS-services) by the Frameworks smallest lib, the DirectCOM.dll.

So the archive below comes as "a RealWorld-DeployPackage", and is therefore a bit larger (it contains,
beside the VB6-source, also the 3 Base-Dlls of the RC5-Framework in a SubFolder \RC5Bin\).

This way the Application is directly startable from e.g. an USB-Stick, without the need to register anything -
the deploymentsize for such a RC5-based "regfree Package" starts from about 1.6MB (when LZMA-compressed,
e.g. with InnoSetup ... or, as the download here, in a 7z-archive):
http://www.vbRichClient.com/Downloads/SQLiteTree.7z (about 1.7MB)

Another thing which is different from the first demo above (which provides its new generated DB, directly from imported Text-file-snippets),
is the fact, that this Demo is using the exact same ADO-JET-*.mdb as the original on PSC as its Import-Source for the new created SQLite-DB.
So this example also covers a simple "Convert-From-JET-DB-to-SQLite"-scenario - and shows, how to use the builtin cCOnvert-Class for that task...





Well, have fun with it.

Olaf

BSpline-based "Bezier-Art"

$
0
0
A small Graphics-Demo for VB6, which shows the nice effects one can produce, when Anti-Aliasing in conjunction with Color-Alpha-settings is combined with "curved Line-Output".

Here's the ~90 lines of code, to put into a single VB-Form:
Code:

'needs a reference to the free vbRichClient5-lib, which is located and available on:
'http://www.vbRichClient.com/#/en/Downloads.htm
Option Explicit
 
Private Srf As cCairoSurface, NumPoints As Single
Private pntX() As Single, pntY() As Single, sgnX() As Single, sgnY() As Single
Private WithEvents tmrRefresh As cTimer

Private Sub Form_Load()
Dim i As Long
'    Rnd -1 'uncomment, if you want to always start from the same "randomness"

    Me.ScaleMode = vbPixels
    Me.Caption = "Left-Click for Start/Stop, Right-Click to clear"
   
    NumPoints = 7
    ReDim pntX(1 To NumPoints): ReDim pntY(1 To NumPoints)
    ReDim sgnX(1 To NumPoints): ReDim sgnY(1 To NumPoints)
 
    For i = 1 To NumPoints
      pntX(i) = ScaleWidth * Rnd
      pntY(i) = ScaleHeight * Rnd
      sgnX(i) = IIf(i Mod 2, 1, -1)
      sgnY(i) = IIf(i Mod 2, -1, 1)
    Next i
   
    Set tmrRefresh = New_c.Timer(10, True)
End Sub
 
Private Sub Form_DblClick()
  tmrRefresh.Enabled = Not tmrRefresh.Enabled
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  If Button = 1 Then tmrRefresh.Enabled = Not tmrRefresh.Enabled
  If Button = 2 Then Set Srf = Cairo.CreateSurface(ScaleWidth, ScaleHeight) 'reset the surface
End Sub

Private Sub Form_Resize()
  Set Srf = Cairo.CreateSurface(ScaleWidth, ScaleHeight)
End Sub

Private Sub Form_Terminate()
  If Forms.Count = 0 Then New_c.CleanupRichClientDll
End Sub

Private Sub tmrRefresh_Timer()
Dim i As Integer, cc As Long

  For cc = 1 To 100 'just to perform some more operations within a single timer-event

    For i = 1 To NumPoints 'the next two lines influence the erratic point-movement (just play around)
      pntX(i) = pntX(i) + sgnX(i) * 0.0004 * Abs(pntY(i) - pntX(i))
      pntY(i) = pntY(i) + sgnY(i) * 0.1 / Abs((33 - pntY(i)) / (77 + pntX(i)))
     
      If pntX(i) < ScaleLeft Then pntX(i) = ScaleLeft: sgnX(i) = 1
      If pntX(i) > ScaleLeft + ScaleWidth Then pntX(i) = ScaleLeft + ScaleWidth: sgnX(i) = -1
      If pntY(i) < ScaleTop Then pntY(i) = ScaleTop: sgnY(i) = 1
      If pntY(i) > ScaleHeight + ScaleTop Then pntY(i) = ScaleHeight + ScaleTop: sgnY(i) = -1
    Next i
 
    Static j As Long, k As Single
    k = k + 0.34: If k > 255 Then k = 0: j = j + 1: If j > 5 Then j = 0
    Select Case j
      Case 0: draw RGB(k, 255 - k, 255)
      Case 1: draw RGB(255, k, 255 - k)
      Case 2: draw RGB(255 - k, 255, k)
      Case 3: draw RGB(0, 255 - k, k)
      Case 4: draw RGB(0, 0, 255 - k)
      Case 5: draw RGB(255 - k, k, 0)
    End Select
   
    If cc Mod 10 = 0 Then Srf.DrawToDC hDC
 
  Next cc
End Sub
 
Private Sub draw(ByVal Color As Long)
Dim i As Long, PolyArr() As Single
  ReDim PolyArr(0 To (NumPoints + 3) * 2 - 1)
  For i = 0 To NumPoints - 1 'this is just a normal copy-over
    PolyArr(2 * i) = pntX(i + 1) 'the dst-array has x at even indexes...
    PolyArr(2 * i + 1) = pntY(i + 1) 'and the y-coord at the uneven ones
  Next i
  For i = 0 To 2 'now we add 3 additional points, to "close the circle" (so to say)
    PolyArr(2 * (NumPoints + i)) = PolyArr(2 * i) 'those extra-points are copies ...
    PolyArr(2 * (NumPoints + i) + 1) = PolyArr(2 * i + 1) '...of the first 3 points
  Next i
 
  With Srf.CreateContext 'once we have filled our PolyArr, the rest is pretty simple
    .SetSourceColor Color, 0.05
    .SetLineWidth 0.5
      .PolygonSingle PolyArr, False, splNormal '... using the powerful Poly-call
    .Stroke
  End With
End Sub

The example starts out producing something like that (all Screenshots were reduced in their Pixel-dimensions for smaller upload/download-size - they look even a bit better when directly rendered):



Then, as long as not resetted continues adding more and more alpha-curves (still the same "set" as above, just some more rendered lines on it):



But one can reset the whole thing with the right Mouse and start with a fresh image, ending up with something like this:



Just play around with it (and maybe manipulate the PolyArray-xy-Coords with your own random move-formulas or parameters) ...
Have fun... :-)

Olaf

VB6-TLS1 Simulation

$
0
0
This program was written to simulate a TLS1 handshake connection, with the long term goal being to implement TLS with email. TLS1 (Transport Layer Security) is only slightly different from SSL3 (Secure Sockets Layer) developed by Netscape. TLS was what the IETF adopted based upon SSL3. This evident in the version number used within the actual protocols. SSL3 is version 3.0 and TLS1 is version 3.1. If you examine the Wikipedia Page on the subject (http://en.wikipedia.org/wiki/Transport_Layer_Security), you will see that virtually all major servers and browsers support TLS 1.0. The same cannot be said for SSL, and the IETF has been strongly recommending that support for fallback to SSL2 be dropped as insecure.

To understand how it all works, you should understand a little bit about Cryptography in general. Cryptography is not really that difficult, but it is very convoluted. There are many competing implementations, and not all of them work together. And the standards don't help that much, as they deal with the issues at the lowest level. Working at that level with VB would be a difficult undertaking and probably not work that well. We could purchase a library/control with all the built-in functions for all or most of the standards, and that would have made life simpler. But then we would have been tied to that control for any fixes or updates. The newer Microsoft Operating Systems come complete with several Crypto Libraries built in, called Cryptographic Service Providers (or CSP's). The one we are interested in is the RSA/Schannel Cryptographic Provider, which provides support for TLS. Microsoft discourages applications from using this CSP directly, choosing instead to limit their support to CSP developers and vendors. But that does not mean it cannot be done. It simply means that information on most of the calls is limited.

J.A. Coutts
Attached Files

Simple Proxy-Server (multiple Winsock-Connections per Controls.Add)

$
0
0
Ok, needed a simple one myself for debugging- and some filter-purposes, so here is what I came up with.

It currently already understands https-tunneling - but the whole Proxy-Application is not thoroughly tested yet -
and could need some love from people who would use it for a bit more than just "playing around with things".

Just post back here, in case you add something nice and useful - or fix the one or other bug... ;-)

I surfed with it for a while (in fact more than a few days without noticing or remembering that the small thingy was "On" the whole time) -
so it's not *that* bad a starting-point I'd say (although the sites I visit are not in a broad spectrum... YMMV).

Here's the usual ScreenShot and Code-Zip-Archive.

Have fun with it...

Olaf
Attached Images
 
Attached Files

AnalogClock-Widget-Class (Png-based-Clock-faces + antialiased, ownerdrawn ClockHands)

$
0
0
The Demo-Source needs a reference to the free vbRichClient5-lib, which is located and available on:
http://www.vbRichClient.com/#/en/Downloads.htm

It's currently only the drawing which is solved - so this Control-Class has no Extra-features yet (as e.g. settable Alarm-Times or other "bells and whistles")
But the drawing is done nicely as I think - and the amount of code needed is still pretty small.

Here's the Class-Code (cwClock.cls)
Code:

Option Explicit
 
Private WithEvents W As cWidgetBase, WithEvents tmrTick As cTimer

Private ClockSrf As cCairoSurface
Private PatHour As cCairoPattern, PatMinute As cCairoPattern, PatSecond As cCairoPattern

Private Sub Class_Initialize()
  Set W = Cairo.WidgetBase '<- this is required in each cwImplementation...
      W.Moveable = True
  Set tmrTick = New_c.Timer(490, True)
End Sub
 
Public Property Get Widget() As cWidgetBase
  Set Widget = W
End Property
Public Property Get Widgets() As cWidgets
  Set Widgets = W.Widgets
End Property
 
Private Sub tmrTick_Timer()
  W.Refresh
End Sub

Private Sub W_Paint(CC As vbRichClient5.cCairoContext, ByVal xAbs As Single, ByVal yAbs As Single, ByVal dx_Aligned As Single, ByVal dy_Aligned As Single, UserObj As Object)
Dim CCclk As cCairoContext, D As Date
  If Not Cairo.ImageList.Exists(W.ImageKey) Then Exit Sub
  W.ToolTip = W.Key & vbCrLf & "You can drag me around..."
 
  If ClockSrf Is Nothing Then InitClockSurfaceAndClockHandPatterns
 
  Set CCclk = ClockSrf.CreateContext
  CCclk.Operator = CAIRO_OPERATOR_SOURCE
    CCclk.RenderSurfaceContent W.ImageKey, 0, 0 'clear the last contents with a fresh copy from the Imagelist-Key
  CCclk.Operator = CAIRO_OPERATOR_OVER
 
  CCclk.TranslateDrawings ClockSrf.Width / 2, ClockSrf.Height / 2  'shift the coord-system from the TopLeft-Default to the center
 
  D = Now()
  DrawPat CCclk, PatHour, ((Hour(D) Mod 12) + Minute(D) / 60) * 5 * 6, 1.5
  DrawPat CCclk, PatMinute, (Minute(D) + Second(D) / 60) * 6, 2.75
  DrawPat CCclk, PatSecond, Second(D) * 6, 3.75

  With Cairo.CreateRadialPattern(0, 0, 7, 2.2, -2.2, 0)
    .AddGaussianStops_TwoColors &HAA, vbWhite, , 0.6
    CCclk.ARC 0, 0, 7
    CCclk.Fill , .This
  End With
 
  CC.RenderSurfaceContent ClockSrf, 0, 0, dx_Aligned, dy_Aligned, , W.Alpha
End Sub

Private Sub InitClockSurfaceAndClockHandPatterns()
Set ClockSrf = Cairo.ImageList(W.ImageKey).CreateSimilar(CAIRO_CONTENT_COLOR_ALPHA)
   
    Set PatHour = Cairo.CreateSurfacePattern(Cairo.CreateSurface(15, ClockSrf.Height))
    DrawLineHands PatHour.Surface.CreateContext, ClockSrf.Height, vbBlack, 9, 0.066, 0.22
 
    Set PatMinute = Cairo.CreateSurfacePattern(Cairo.CreateSurface(15, ClockSrf.Height))
    DrawLineHands PatMinute.Surface.CreateContext, ClockSrf.Height, vbBlack, 6, 0.1, 0.29
   
    Set PatSecond = Cairo.CreateSurfacePattern(Cairo.CreateSurface(15, ClockSrf.Height))
    DrawLineHands PatSecond.Surface.CreateContext, ClockSrf.Height, &HAA, 2, 0.044, 0.34
    DrawLineHands PatSecond.Surface.CreateContext, ClockSrf.Height, &HAA, 4, 0.044, -0.17
End Sub

Private Sub DrawLineHands(CC As cCairoContext, SrfHeight, Color, LineWidth, DownFac, TopFac)
  CC.TranslateDrawings CC.Surface.Width / 2, SrfHeight / 2
  CC.DrawLine 0, SrfHeight * DownFac, 0, -SrfHeight * TopFac, , LineWidth + 2, Color, W.Alpha * 0.33 'a thin outer-border with more alpha
  CC.DrawLine 0, SrfHeight * DownFac, 0, -SrfHeight * TopFac, , LineWidth, Color, W.Alpha
End Sub
 
Private Sub DrawPat(CC As cCairoContext, Pat As cCairoPattern, ByVal Deg As Double, Optional ByVal ShadowOffs As Single)
Dim M As cCairoMatrix
  Set M = Cairo.CreateIdentityMatrix
      M.TranslateCoords Pat.Surface.Width / 2, Pat.Surface.Height / 2
      M.RotateCoordsDeg -Deg
  Set Pat.Matrix = M 'we do not rotate the Coord-System of the CC, but instead we rotate that of the pattern
 
  If ShadowOffs Then
    CC.Save
      CC.TranslateDrawings -ShadowOffs, ShadowOffs
      CC.Paint W.Alpha * 0.25, Pat
    CC.Restore
  End If
 
  CC.Paint W.Alpha, Pat 'so what we do in this line, is only "a Blit" (using the already rotated Pattern-Matrix)
End Sub

And here the Form-Code (fTest.frm)
Code:

Option Explicit

Private WithEvents Panel As cWidgetForm 'a cWidgetForm-based Panel-area (followed by 4 clock-Widget-Vars)
Private LaCrosse As cWidgetBase, Flower As cWidgetBase, Square As cWidgetBase, System As cWidgetBase
 
Private Sub Form_Load()
  ScaleMode = vbPixels
  Caption = "Resize Me... (the four Clock-Widgets are individually moveable too)"
  LoadImgResources
 
  Set Panel = Cairo.WidgetForms.CreateChild(Me.hWnd)
      Panel.WidgetRoot.ImageKey = "BackGround"
 
  Set LaCrosse = Panel.Widgets.Add(New cwClock, "LaCrosse", 0.015 * ScaleWidth, 0.16 * ScaleHeight, 501, 501).Widget
      LaCrosse.ImageKey = "ClockLaCrosse" 'same as with the Background of the Panel above - just specify an ImageKey
 
  Set Flower = Panel.Widgets.Add(New cwClock, "Flower", 0.73 * ScaleWidth, 0.01 * ScaleHeight, 501, 501).Widget
      Flower.ImageKey = "ClockFlower" 'same as with the Background of the Panel above - just specify an ImageKey
 
  Set Square = Panel.Widgets.Add(New cwClock, "Square", 0.528 * ScaleWidth, 0.65 * ScaleHeight, 501, 501).Widget
      Square.ImageKey = "ClockSquare" 'same as with the Background of the Panel above - just specify an ImageKey
 
  Set System = Panel.Widgets.Add(New cwClock, "System", 0.3405 * ScaleWidth, 0.726 * ScaleHeight, 501, 501).Widget
      System.ImageKey = "ClockSystem" 'same as with the Background of the Panel above - just specify an ImageKey
      System.Alpha = 0.75 '<- just to show, that this would work too of course
     
  Move Left, Top, Screen.Width / 2, Screen.Width / 2 * 0.66
End Sub

Private Sub Panel_BubblingEvent(Sender As Object, EventName As String, P1 As Variant, P2 As Variant, P3 As Variant, P4 As Variant, P5 As Variant, P6 As Variant, P7 As Variant)
  If TypeOf Sender Is cwClock And EventName = "W_Moving" Or EventName = "W_AddedToHierarchy" Then
    Sender.Widget.Tag = Array(Sender.Widget.Left / ScaleWidth, Sender.Widget.Top / ScaleHeight) 'the Widgets Tag-Prop is a Variant - and can store anything
  End If
End Sub

Private Sub Form_Resize()
  Panel.Move 0, 0, ScaleWidth, ScaleHeight
End Sub

Private Sub Panel_ResizeWithDimensions(ByVal NewWidth As Long, ByVal NewHeight As Long)
  'that doesn't really have anything to do with the analog-clock-widgets, it's just normal "percentual positioning-tricks"
  LaCrosse.Move LaCrosse.Tag(0) * NewWidth, LaCrosse.Tag(1) * NewHeight, NewWidth * 0.25, NewHeight * 0.4
  Flower.Move Flower.Tag(0) * NewWidth, Flower.Tag(1) * NewHeight, NewWidth * 0.16, NewHeight * 0.25
  Square.Move Square.Tag(0) * NewWidth, Square.Tag(1) * NewHeight, NewWidth * 0.18, NewHeight * 0.29
  System.Move System.Tag(0) * NewWidth, System.Tag(1) * NewHeight, NewWidth * 0.032, NewHeight * 0.058
End Sub

Private Sub LoadImgResources() 'just plain image-loading from disk (into the global ImageList, from where it is accessible by Key)
  Cairo.ImageList.AddImage "BackGround", App.Path & "\BackGround.jpg"
 
  Cairo.ImageList.AddImage "ClockLaCrosse", App.Path & "\ClockLaCrosse.png"
  Cairo.ImageList.AddImage "ClockFlower", App.Path & "\ClockFlower.png", 251, 251
  Cairo.ImageList.AddImage "ClockSquare", App.Path & "\ClockSquare.png", 401, 401
  Cairo.ImageList.AddImage "ClockSystem", App.Path & "\ClockSystem.png", 401, 401
End Sub

Private Sub Form_Terminate()
  If Forms.Count = 0 Then New_c.CleanupRichClientDll
End Sub

Attached is the usual ScreenShot and a Zip-File which contains the above Code again (together with a set of Image-ResourceFiles the small Example is based on).
Attached Images
 
Attached Files

Typing Text Directly Into A Picturebox

$
0
0
This VB6 Project allows you to type text directly on a picture much like you do using MS Paint
Attached Files

Tapi Telephone Answering System

$
0
0
Download from the link below. It is too big to upload here.

I wrote this about 12 - 13 years ago when I was on Dial-Up and I had a phone modem (with voice) installed. I wrote it using VB 5 (I think) and on Windows 98

When I had it installed it did incoming and outgoing calls. On incoming it did voice greetings and other voice things. It detects dial tones. Caller could leave message. If I wasn't home this app would call me on my cell phone and inform me of a call I missed giving me the number. I also used this to activate my home security camera system. I would call home and this would answer my call and I would enter a special code which would cause this app to load and run the security software. I built this application as I was learning TAPI and it took me over 6-months to complete. It was my biggest challenge at that time.

Download from below:

http://www.codeavenue.com/downloads/...ringSystem.zip


NOTE: www.codeavenue.com is my own web site

[VB6] Force Foreground Window Demo

$
0
0
The attached project demonstrates how to utilize various APIs to force a window to the foreground. Keep in mind though, that these techniques would probably annoy your users if your window forcibly stealed the focus from whatever they're currently doing. ;)


Name:  ForceForeground.png
Views: 37
Size:  7.0 KB
Attached Images
 
Attached Files

[VB6] clsStrToIntArray.cls - Cast String To Integer Array

$
0
0
This simple class makes it very easy to typecast a String into an Integer array. Treating a String as an array enables some kinds of String processing to be done much quicker than is possible with VB's intrinsic String functions.


clsStrToIntArray.cls
Code:


Option Explicit

Private Const
FADF_AUTO      As Integer = &H1  'An array that is allocated on the stack.
Private Const FADF_FIXEDSIZE As Integer = &H10  'An array that may not be resized or reallocated.

Private Type SAFEARRAY1D    'Represents a safe array. (One Dimensional)
    cDims      As Integer  'The count of dimensions.
    fFeatures  As Integer  'Flags used by the SafeArray.
    cbElements As Long      'The size of an array element.
    cLocks    As Long      'The number of times the array has been locked without a corresponding unlock.
    pvData    As Long      'Pointer to the data.
    cElements  As Long      'The number of elements in the dimension.
    lLbound    As Long      'The lower bound of the dimension.
End Type                    'http://msdn.microsoft.com/en-us/library/ms221482(v=vs.85).aspx

Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef ArrayVar() As Any) As Long
Private Declare Sub
PutMem4 Lib "msvbvm60.dll" (ByVal Addr As Long, ByVal NewVal As Long)

Private Ptr  As Long
Private
SA1D As SAFEARRAY1D

Private Sub Class_Initialize()
    With SA1D
        .cDims = 1
        .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE
        .cbElements = 2&
        .cLocks = 1&
        .lLbound = 1&
    End With
End Sub


'This should be the first method called right after instantiating
'the class and should be invoked only once per class instance.
'Pass the Integer array that will substitute for the String.


Public Sub InitArray(ByRef IntArray_OUT() As Integer)
    Erase IntArray_OUT
    Ptr = VarPtrArray(IntArray_OUT())
    PutMem4 Ptr, VarPtr(SA1D)
End Sub

'This function typecasts the passed String into an Integer array.
'That is, the characters of the String can be treated as elements
'of the Integer array. Any number of Strings can be typecast to
'the Integer array by calling this function repeatedly. However,
'the array should not be Erased when assigning another String.
'This function fails (returns False) if passed an empty string.


Public Function CastString(ByRef String_IN As String) As Boolean
    Dim
StrLen As Long

    If
Ptr Then
        StrLen = Len(String_IN)
        If StrLen Then
            With
SA1D
              .pvData = StrPtr(String_IN)
              .cElements = StrLen
                CastString = .pvData <> 0&
            End With
        End If
    End If
End Function

Private Sub
Class_Terminate()
    If Ptr Then PutMem4 Ptr, 0&
End Sub


modMain.bas
Code:


Option Explicit

Private Sub
Main()
    Dim aintChars() As Integer, i As Long
    Dim
sControlChars As String, sPrintableChars As String

    sControlChars = Space$(31&)
    sPrintableChars = String$(224&, 0)

    With New clsStrToIntArray
      .InitArray aintChars()

        If .CastString(sPrintableChars) Then
            For
i = LBound(aintChars) To UBound(aintChars)
                aintChars(i) = i + 31&
            Next
            Debug
.Print """" & sPrintableChars & """"
        End If

        If
.CastString(sControlChars) Then
            For
i = LBound(aintChars) To UBound(aintChars)
                aintChars(i) = i
            Next
            Debug
.Print """" & sControlChars & """"
        End If
    End With
End Sub



Attached Files

Vb6 - Word Search App (Scrabble Solver?) *includes Wildcard usage

$
0
0
Name:  Word Search.jpg
Views: 70
Size:  41.2 KB

First off...My apologies if "Word Search" is the incorrect term for this, I have no clue what the official name for this type of app is. people usually relate it to Scrabble.

Here is my take/idea on making a word search/"Scrabble solver" app that can handle wildcards. I created this a while back, and updated it a bit since then. It is not rapid fast sometimes when looking for 10 or more letters, or when using a lot of wildcards, but i find it pretty fast if using it as you would in any scrabble combination.

If you have a link to one you've created or seen, let me know; i'd like to view the source.


:eek2:Note: This includes a dictionary. The program is built around the current dictionary words in relation to the amount of duplicate letters in a word(maximum 7) and word length(maximum 15).
Attached Images
 
Attached Files

Word extractor program.

$
0
0
Hi all
This is my vague program to extract the words that are used in a text with no repetition.
It does the purpose for me at this level. I liked to share with you hoping someone have the time to add some more functions.
thank you.
Attached Files

AutoComplete (Using the IAutoComplete interface)

$
0
0
This project is intended to demonstrate how to implement the IAutoComplete interface to VB6.

It provides more features than the "SHAutoComplete" API.

For example to determine whether the drop-down list is dropped down or not.
But the most important feature is that you can define custom sources. (by a simple string array)

At design time (IDE) there is only one dependency. (AutoCompleteGuids.tlb)
But for the compiled .exe there are no dependencies, because the .tlb gets then compiled into the executable.

Notes:
- There is no way to uninitialize the autocomplete object. You can only disable it. Setting the autocomplete object to nothing has therefore no effect and is not recommended. Anyhow, the autocomplete object will be automatically uninitialized when the TextBox (or any other edit control) receives the WM_DESTROY message.
- Use modeless forms to enable the user to use the mouse on the drop-down suggest list as else only keyboard inputs will work on modal forms.

List of revisions:
Code:

13-Aug-2013
- Fixed a bug that the application will crash when there is an empty string in the custom source.
12-Aug-2013
- First release.

Attached Files
Viewing all 1321 articles
Browse latest View live




Latest Images