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

Patch Collection to support case sensitivity

$
0
0
The Collection is 3-4 and more times faster then the Dictionary when adding items, and 2 times slower when retrieving.

Tested compiled and runned from the IDE in the Windows XP 64 and in the Windows 7 64 with different versions of msvbvm60.dll and vba6.dll.
So it is must be stable.

VB Code:
  1. Private Declare Sub GetMem1 Lib "msvbvm60" (ByVal Address As Long, n As Byte)
  2. Private Declare Sub PutMem1 Lib "msvbvm60" (ByVal Address As Long, ByVal n As Byte)
  3. Private Declare Sub GetMem2 Lib "msvbvm60" (ByVal Address As Long, n As Integer)
  4. Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Address As Long, n As Long)
  5.  
  6. Private Const PAGE_EXECUTE_READWRITE = &H40&
  7. Private Declare Function VirtualProtect Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
  8. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  9.  
  10. Sub Main()
  11.   Dim c As New Collection
  12.   PatchCollection
  13.   c.Add 1, "Test"
  14.   c.Add 2, "test"
  15.   MsgBox c("Test")
  16.   MsgBox c("test")
  17. End Sub
  18.  
  19. Private Property Get MemByte(ByVal Address As Long) As Byte
  20.   GetMem1 Address, MemByte
  21. End Property
  22. Private Property Let MemByte(ByVal Address As Long, ByVal n As Byte)
  23.   PutMem1 Address, n
  24. End Property
  25. Private Function MemInt(ByVal Address As Long) As Integer
  26.   GetMem2 Address, MemInt
  27. End Function
  28. Private Function Mem(ByVal Address As Long) As Long
  29.   GetMem4 Address, Mem
  30. End Function
  31. Public Sub PatchCollection(Optional ByVal IsCaseSensitive As Boolean = True)
  32.   Dim Addr As Long
  33.   If InIDE = False Then
  34.     addr = GetModuleHandle("MSVBVM60.DLL")
  35.   Else
  36.     Addr = GetModuleHandle("VBA6.DLL")
  37.   End If
  38.   Addr = SearchPatchBytes(Addr)
  39.   PatchByte(Addr) = IsCaseSensitive + 1
  40.   Addr = SearchPatchBytes(Addr)
  41.   PatchByte(Addr) = IsCaseSensitive + 1
  42. End Sub
  43. Private Function InIDE() As Boolean
  44.   On Error Resume Next
  45.   Debug.Print 0 / 0
  46.   InIDE = Err.Number <> 0
  47. End Function
  48. 'Patch calls to the oleaut32_VarBstrCmp function
  49. Private Function SearchPatchBytes(ByVal Addr As Long)
  50.   Addr = Addr + 7
  51.   Do
  52.     Do
  53.       While MemByte(Addr) <> &H68 'push
  54.         Addr = Addr + 1
  55.       Wend
  56.       Addr = Addr + 1
  57.     Loop While (Mem(Addr) And &HFFFFFFFE) <> &H30000 'NORM_IGNORECASE = 0/1
  58.     Addr = Addr + 4
  59.   Loop While MemInt(Addr) <> &H16A 'push 1 (Locale identifier)
  60.   SearchPatchBytes = Addr - 4
  61. End Function
  62. Private Property Let PatchByte(ByVal Addr As Long, ByVal b As Byte)
  63.   Dim OldProtect As Long
  64.   VirtualProtect Addr, 1, PAGE_EXECUTE_READWRITE, OldProtect
  65.   MemByte(Addr) = b
  66. End Property

or with TLB (see my others posts to download it):
VB Code:
  1. Sub Main()
  2.   Dim c As New Collection
  3.   PatchCollection
  4.   c.Add 1, "Test"
  5.   c.Add 2, "test"
  6.   MsgBox c("Test")
  7.   MsgBox c("test")
  8. End Sub
  9.  
  10. Public Sub PatchCollection(Optional ByVal IsCaseSensitive As Boolean = True)
  11.   Dim addr As Long
  12.   If InIDE = False Then
  13.     addr = GetModuleHandle("MSVBVM60.DLL")
  14.   Else
  15.     addr = GetModuleHandle("VBA6.DLL")
  16.   End If
  17.   addr = SearchPatchBytes(addr)
  18.   PatchByte(addr) = IsCaseSensitive + 1
  19.   addr = SearchPatchBytes(addr)
  20.   PatchByte(addr) = IsCaseSensitive + 1
  21. End Sub
  22. Private Function InIDE() As Boolean
  23.   On Error Resume Next
  24.   Debug.Print 0 / 0
  25.   InIDE = Err.Number <> 0
  26. End Function
  27. 'Patch calls to the oleaut32_VarBstrCmp function
  28. Private Function SearchPatchBytes(ByVal addr As Long)
  29.   addr = addr + 7
  30.   Do
  31.     Do
  32.       While MemByte(addr) <> &H68 'push
  33.         addr = addr + 1
  34.       Wend
  35.       addr = addr + 1
  36.     Loop While (Mem(addr) And &HFFFFFFFE) <> &H30000 'NORM_IGNORECASE = 0/1
  37.     addr = addr + 4
  38.   Loop While MemInt(addr) <> &H16A 'push 1 (Locale identifier)
  39.   SearchPatchBytes = addr - 4
  40. End Function
  41. Private Property Let PatchByte(ByVal addr As Long, ByVal b As Byte)
  42.   Dim OldProtect As Long
  43.   VirtualProtect addr, 1, PAGE_EXECUTE_READWRITE, OldProtect
  44.   MemByte(addr) = b
  45. End Property

[VB6] 7-zip support

$
0
0
Here is an open source project that provides support for 7-zip in your VB6 projects.

https://github.com/wqweto/VszLib

Using VszLib.dll + 7z.dll your applications can create and extract 7z, zip, tar.gz, tar.bz2 and many more compression formats. Latest versions of 7z format include LZMA2 method for faster multi-core compression.

Post your comments and questions here.

cheers,
</wqw>
p.s. @Moderators: Please remove original thread.

[VB6] Google Cloud Print service support

The Best GGD That Was Ever Made

$
0
0
That is actually the title of this program I wrote (using VB6). It is based on the a sprite dumping software called GGD, which stands for Game Graphics Dumper. GGD was basically a very fancy version of a RAW image loader. It can take ANY file, and it does not know the format, nor how to read any header, so you supply a LOT of info so GGD can load the Graphics (stuff like, offset to image data, height, width, tiled or linear arranged pixels, color channel order, bits per pixel, offset to palette data, and all the same formats for the image are repeated for the palette, selectable endianness, etc). This way almost ANY format you can imagine (as long as it is in RGB or RGBA colorspace, cause YUV doesn't work here) that might ever be found in any video game or any other source (and as long as it isn't encrypted or compressed), can be displayed and saved as an ordinary bitmap file.

Well the controls for the original GGD were not user friendly, and the documentation was in Chinese or Japanese, so it was basically a "if you only know English, figure it out for yourself" type software (although some hacker made a translated version in English later, the controls still were horrible). Then came one called Tiled GGD that had some extra options for tiled graphics, including options for planar arranged color channels (instead of per-pixel arranged color channels, though I think planar color channels were also available in the original GGD), and it was based on GGD (it was a derivative work you might say), but it was made by an English speaking guy (luckily), and the controls were easier to use. However it lacked a number of features of the original GGD, namely it lacked the ability to arange the bit masks that were used to define which bits in a 16 (or 15) bit per pixel image were used for what colors, and also what ones were used for alpha (if any at all).

Well my program called "The Best GGD That Was Ever Made" is my own take on how the GGD program should have been designed, and has the functionality missing from Tiled GGD, which existed in the original GGD. It also is designed to have a much more intuitive user interface than the original GGD. To load a file, just drag it Windows explorer onto most any spot in the GUI, then press "load file" button. If it doesn't look right, change some of the parameters and press "load file" again. To load a palette, drag a file that you believe has the color palette for the image into the square black box and check the box "Use External palette", then press the "load file" button again. If the palette looks wrong, adjust the palette parameters and press "load file" again. To save a palette, select the option button (radio button) for the palette format you want, and press "save palette". When the picture looks right, press the "save image" button to save the image as a BMP file.

Below here is the VB code for the software.
Click to view: http://pastebin.com/raw.php?i=3tSjajtx
Click to download TXT file: http://pastebin.com/download.php?i=3tSjajtx




Here's the code that sets up the form in the FRM file.
Click to view: http://pastebin.com/raw.php?i=fLp30wPe
Click to download TXT file: http://pastebin.com/download.php?i=fLp30wPe



Here is a screenshot of the GUI:





It also has one dependency that isn't a normal VB6 runtime file. Download the DLL file at: http://www.dllbank.com/zip/n/nctimagefile.dll.zip

CRC32 - Fastest Implementation Available VB6

$
0
0
The implementation I have written achieves its speed through use of x86 assembly code. In fact, the entire implementation of the CRC32 algorithm is written in assembly.

I use assembly via some tricks involving class modules and the object's vtable. I allocate a block of memory, write the machine code to the memory, then rewrite the functions vtable entry to point to my block of code.

It is roughly 25x faster than the current "fastest" implementation found on pscode.con that gets its speed through asm assisted bitshifting (which was written by me too) and probably 100x to 150x faster than a pure VB approach.

The project and code file(s) can be found here:
http://www27.brinkster.com/wsckvbupdates/CRC32.zip

P.S. because it is hosted on a free web server, you might have to copy the link and manually paste it rather than clicking on it.
Also, look forward to more hashing algorithms, encryptions, and etc to be written in asm taylored for use with vb6 to be released in the future!

[VB6] TEMPer Gold USB HID Thermometer Class

$
0
0
Note

Be sure to see the updated version (posted as version 2 below)!


Background

TEMPer is a series of products by PCsensor for measuring temperature (and in some cases humidity). There are many models on the market with varying capabilities. While some of the early units appear as USB Serial devices (COMx: ports) the newer ones are USB HID devices that use the standard Windows driver and don't require driver installation.

This Class (TEMPerGold.cls) is a Visual Basic 6.0 Class that works only with the TEMPer Gold product. It is a wrapper around the RDingUSB.dll that comes with the unit's software package. The software is a basic .Net application you may or may not find useful. There is basically ZERO documentation available on the companion mini-CD or online.

TEMPer Gold runs from about $9 to $20 USD (depending on where you shop) if you are curious.

In my case the product arrived in some limp baggies, perhaps returned by another customer? Everything was there, though the mini CD-R only seemed to have one unreadable session on it. The unreable disk might have been why it was returned. I downloaded the software package from PCsensor but never installed it since it requires .Net 2.0 on your machine.

I also never saw the "red" LED light up as described by PCsensor. But perhaps mine has a dummy LED where the LED would go, having been dropped to save costs - and because an "operating" LED is fairly useless here.


Basic Operation

If you plug in the TEMPer Gold without installing any software it "installs" in Windows as two HID devices: one a keyboard and the other a special function device.

As a "keyboard" you can make basic use of the TEMPer by opening Excel or even Notepad and then holding Caps Lock or Num Lock for 3 seconds, which makes it start "typing" readings until you hold down Caps Lock or Num Lock 3 seconds again.

Details on using the sample .Net applet can be found on the PCsensor web site (see link above). I didn't install it because I have too much .Net clutter here right now anyway, and did not want to risk the cruft a poorly constructed installer might leave behind even after uninstalling it.


Extracting RDingUSB.dll

Since my code requires this DLL you'll have to extract it in order to use TEMPerGold.cls yourself.

The easiest way is to locate the MSI package containing the PCsensor demo applet and do an "administrative install" to extract the installation files to a folder. Example:

Code:

msiexec /a "d:\work\temper\thepackage.msi" /qb TARGETDIR="d:\work\temper\packagefiles"

My Demo

The attached demo Project archive contains all of the files needed to build and run the VB6 demo. However for it to run you'll need to either put RDingUSB.dll in the Project folder yourself, or else place it where a normal system DLL Search will find it.

The demo as written manages the state of its UI to guide you through the right steps, but basically:
  • First you Open the device.
  • Then you can Get/Set the Calibration.
  • Then you can start taking sample readings.
  • Finally you Close the device.
Calibration is an offset ranging from -8 to +7°C, and it seems to be non-volatile. You only need to set it when you want to adjust it.


Oof!

This was a messy thing to track down and I had lots of false starts.

While written only for the TEMPer Gold you can probably modify it to work for other TEMPer devices that are USB HID devices. The USB COM-port type should be easier if you find one of those though the interaction back and forth seems quite different.

I found basically nothing useful online to help me write this class. There were a few spotty discussions on the older COM-port devices but that was about it for VB. The RDingUSB.dll is really a renamed SonixUSB.dll (based on a DUMPBIN of the file), which probably means the product uses some Sonix USB microcontroller to front-end the Fairchild FM75 temperature sensor inside.

I had to reverse-engineer the exported function calls by using Reflection to tear down the compiled .Net demo supplied.

If you've had a need for this same thing you've probably also been amused as well as frustrated. As I said there is little out there, but what you do find is a lot of hilarious (and mostly none too useful) posting by the Linux and Delphi communities. One can only wonder how they ever get anything to work. Then again to be fair, just look at so many posts here by both VBers and DotNetters.


Taking it Further

You could easily write a data logger application, charting application, etc. if you want one.

I'm thinking of adding it as optional functionality to my GossCam webcam server posted here in another thread.
Attached Images
   
Attached Files

Hyperlink Control

$
0
0
This is a UserControl for simulating a Hyperlink. The control is build up by a simple label.
But it have some advantages comparing to a simple label putted on a form.

It will show up a hand cursor when the mouse is over the control. In addition a hover effect can be used when the mouse is over it.
The control itself can receive focus, which is very helpful for keyboard users. But it only keeps the focus when control is not entered by mouse.

The control fires a "Jump" event. In that event the code should be put to open a url, document or anything else.

Attachment 90381

Attachment: Sample project with the hyperlink (user)control.

EDIT1:
- It now supports a ColorUsed property.
- The focus can be navigated now with the arrow keys within the controls container.
- Added a PrepareJump event where the user can set if the LostFocus Event will always be fired or not. (Example Usage: Calling a MsgBox in the Jump Event will not fire the LostFocus Event. Therefore a possible focusrect drawing is still visible while the MsgBox is displayed)
- other minor improvements
Attached Images
 
Attached Files

[vb6] Module: GetDataFromURL

$
0
0
Originally, i writed this module for self. Now i'm publish module for others. :)

This module created for the send GET\POST queries to the server.

GetDataFromUrl: - Sending request to remote server.
strURL - URL of the target page.
Optional strMethod = GET - Page request method: GET, POST or Multipart. (POST with multipart)
Optional Async = false - Run in asynchronous mod. (To prevent gui lags).
Optional strPostData = "" - Data to post. (Only if strMethod = POST\Multipart)
Optional boundary = "" - Boundary for multipart. (Only if strMethod = Multipart. Create with Make_Boundary.)

Make_Boundary: - Making Boundary for POST + multipart request.

Add_Multipart: - Adding fields for POST + multipart request.
post_field - Field.
post_data - Value of field. Leave empty, if you sending a file.
boundary - Boundary. (Create with Make_Boundary.)
Optional file_path = "" - Path to file. Leave empty, if you want to send post_data.Attachment 90481


GET request example:
Code:

Dim ansv As String
ansv = GetDataFromURL("http://vbforums.com")

POST request example:
Code:

Dim ansv As String
ansv = GetDataFromURL("http://vbforums.com", "POST", false, "field1=value1&field2=value2")


POST request with multipart example:
Code:

Dim ansv As String
Dim Multipart As String
Dim Boundary As String

Boundary = Make_Boundary

Multipart = Add_Multipart("Field1", "Value1", Boundary)
Multipart = Multipart & Add_Multipart("Field2", "Value2", Boundary)
Multipart = Multipart & Add_Multipart("File2", VbNullString, Boundary, "C:\test.txt") 'File upload example
Multipart = Multipart & "--" & Boundary & "--"


ansv = GetDataFromURL("http://vbforums.com", "Multipart", false, Multipart, Boundary)

---------------------------------
I hope you enjoy it. :) Sorry for my bad english.

Attachment 90481
Attached Files

[VB/VBA] LunarPhase - Phase of the Moon

$
0
0
When you don't need it, you don't need it. But when you do it can take a little thinking through.

The basic concept is fairly easy if you simply need rough, non-astronomical results. Take your target date/time, find out how far it is from a base date/time with a known phase (say New Moon), take the Lunar phase cycle period, and then the result is easy:

Phase = Delta Mod Period

Usually you'll want the value in more granular form. Maybe quarters is good enough, etc. so just divide the "Phase" value by the fraction of "Period" you want for granularity.

Another refinement is to make sure your base and target times are for the same time zone so you can avoid being off by 0 to 24 hours.


Here I used a UTC "base" New Moon date & time so I correct local time to UTC before calculating (this function is in the attached demo project). I found 24 images for the entire cycle so I am returning a phase value that is 1/24th of a Lunar period. I was careful to reduce the use of non-integer arithmetic and avoid rounding.

So hopefully this works out reasonably accurately for simple "display the phase of the Moon" purposes:
Code:

Public Const PhaseBase As Date = #1/17/1980 9:18:00 PM# 'GMT/UTC.
Public Const LunarSynod As Long = 42524    'Minutes.

Public Function LunarPhase(ByVal TargetDate As Date) As Integer
    'Returns lunar phase for TargetDate starting from PhaseBase
    'timestamp forward, at 1/24 cycle intervals, i.e. values
    'from 0 to 23:
    '
    '    0 = New Moon
    '    6 = First Quarter
    '  12 = Full Moon
    '  18 = Last Quarter
   
    LunarPhase = _
        (Fix(DateDiff("n", PhaseBase, ToUTC(TargetDate))) Mod LunarSynod) _
      \ (LunarSynod \ 24)
End Function

I've wrapped it in a small demo application for testing.
Attached Images
 
Attached Files

[VB6] - Lottery-Algorithm

$
0
0
On a german Forum I developed the following Lottery-Algorithm (which i haven't found on the Internet in this form).

I would like to hear your opinions and/or suggestions to improve it

vb Code:
  1. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  2.  
  3. Sub Lottery(ByVal DrawNumbers As Long, ByVal TotalNumbers As Long)
  4. Dim arrSource() As Long    
  5. Dim arrDest() As Long
  6.  
  7. Dim i As Long
  8. Dim j As Long
  9. Dim Counter As Long
  10. Dim RandomNumber As Long
  11.  
  12.     'What Lottery is played
  13.     ReDim arrDest(1 To DrawNumbers)
  14.     ReDim arrSource(1 To TotalNumbers)
  15.    
  16.     'Create Source-Array
  17.     For i = 1 To TotalNumbers
  18.    
  19.         arrSource(i) = i
  20.    
  21.     Next
  22.    
  23.     Counter = 0
  24.  
  25.     Randomize
  26.  
  27.     Do
  28.  
  29.         RandomNumber = Int(UBound(arrSource) * Rnd + 1)
  30.    
  31.         Counter = Counter + 1
  32.         arrDest(Counter) = arrSource(RandomNumber)
  33.        
  34.         'Cutting out the RandomNumber drawn
  35.         For j = RandomNumber + 1 To UBound(arrSource)
  36.        
  37.             CopyMemory arrSource(j - 1), arrSource(j), 4
  38.            
  39.         Next
  40.        
  41.         'Cut down the Source-Array
  42.         ReDim Preserve arrSource(1 To UBound(arrSource) - 1)
  43.            
  44.     Loop Until Counter = DrawNumbers
  45.    
  46.     For i=1 to DrawNumbers
  47.      
  48.          Debug.Print arrDest(i)
  49.  
  50.     Next
  51.  
  52. End Sub
  53.  
  54. 'Calling the function with
  55. Call Lottery (6, 49)

Caption Gradiator III / VB6 Form Gradient Titlebar

$
0
0
Hello, :wave:

Caption Gradiator III is a Basic Module that facilitates a custom gradient color titlebar for Visual Basic forms. The original program came from another VB author's web sight. The code was bloated and had several bugs including the failure to repaint area around the form control box buttons. The original author's approach to fixing the bugs was to tie the process to a sub class timer thereby increasing the bloat. My approach was to use better logic and less code. I learned from the original code as opposed to copying the code. The changes I made were significant and I have no problem with calling this my own program. The process is called from the Form_Load event and cancelled in the Form_Unload event as illustrated in the form code in the project.

Enjoy,
OldRon, aka servowizard
Attached Files

MemoryView

$
0
0
This started as a simple program to show a hex dump of 'safe' memory addresses,
i.e. those returned by VarPtr, StrPtr, VarPtrArray, and an undocumented
function, StringArrPtr.

After playing with it for a bit, I got interested in how VB stores its variables in memory
and this is the result.

It uses CopyMemory liberally, so if you start tweaking it, be careful and
save your project before running in case you crash VB. (You can select
Tools|Options|Environment and click on Save when program starts.)

The program allows you to examine numeric values, numeric arrays, numeric safe arrays,
string values, string arrays, string safe arrays, and UDTs (Types).

Here's a sample output

**Long variable with value of &H4030201
Start Address: &H0013F8AC Number of Bytes: 16
________________________________________________________________________________
Base: OS: Hex: Ascii:
0013F8AC 0000 01 02 03 04 40 F9 13 00 10 FA 13 00 01 00 00 00 ....@...........
________________________________________________________________________________
Attached Files

VB6 - Melas: Line Charting Classes

$
0
0
Why Melas?

I needed an alternative to the MSChart control for creating simple line charts in batch mode. MSChart can do the job just fine with some fiddling, however I needed to create these charts and write them as JPEG or PNG files for direct serving from a Web server. The only snag is that to capture the drawn chart from the MSChart control you need to use the clipboard and I didn't want to disturb its contents since a user might well be working while a background charting operation was going on.


What is Melas?

There is a main class called Melas and a set of "child" classes it uses to represent various things (axes, plots, legends, etc.). You create an instance of Melas and initialize it with a reference to some VB6 object having an hDc so that it can be drawn on. In most cases this will be a Form, a PictureBox, or a UserControl.

From there you use some MSChart-like operations to flesh out the rest and plot your lines.


Still Rough

There is more to do here yet, especially in terms of dealing with pesky boundary conditions (do I subtract a pixel here or not?), making sure rotated text gets positioned correctly, etc.

However I decided to post it as-is.

For one thing it is still simple enough that somebody could use it as an example or jumping-off point for creating their own more comprehensive MSChart alternative. For another I am taking the code in a specific direction for my own purposes that will make the logic more complex to follow as well as being less general-purpose in nature.


Notes

There is no code here to grab the resulting chart image and save it, the focus here is drawing the chart. You can use simple .SavePicture() operations to create BMP files or else use another technique to grab and save in other formats.

The core of the Melas classes is the Canvas class, which is primarily meant to create non-clipped and clipped regions where the Y-coordinate is flipped (0 at the bottom instead of the top as in regular VB6 drawing) and both X and Y are scaled without using a custom ScaleMode.

Inside the Melas class you will find places where it uses Canvas coordinates, and others where it draws directly and uses VB6 cordinates. Sorry about the confusion - this is just a heads-up to anybody trying to unravel the logic.

The attachment contains the Melas classes and 5 demos. There are some images in there and a small database, which is why the attachment is so large. Melas itself is fairly small and doesn't add a ton to the size of compiled programs.
Attached Images
     
Attached Files

VB6 IDE solving UAC and Visual Style issues

$
0
0
Hello,

the VB6 IDE (VB6.exe) has issues when the UAC (Windows Vista and 7) is activated.
This may cause that opening .vbp files for example will fail.

To solve this it is just required to add a resource directly into the VB6.exe.

The source code of "RequireAdmin.res" is:

Code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
        <requestedPrivileges>
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
        </requestedPrivileges>
      </security>
  </trustInfo>
</assembly>

In the attachment I have added the same as a compiled resource.

Use a resource hacker to put the resource file directly into the VB6.exe.
I used following resource hacker for that job: http://www.angusj.com/resourcehacker/
(File -> Open ... VB6.exe -> Action -> Add a new Resource ...)

The result is now that every time the VB6.exe will be accessed it is ensured that the admin rights are on.
Opening .vbp files works therefore without any problems.

I have also attached another compiled resource file with visual styles included, just for those who want it too.

The source code of "VisualStylesAndRequireAdmin.res" is:
Code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
        <requestedPrivileges>
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
        </requestedPrivileges>
      </security>
  </trustInfo>
  <dependency>
      <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" language="*" processorArchitecture="*" publicKeyToken="6595b64144ccf1df"/>
      </dependentAssembly>
  </dependency>
</assembly>

EDIT: Reason for this is that adding a manifest file into the VB6.exe directory won't work anymore in Windows 7.
Attached Files

VB6 - SysBitmaps Control: Free Toolbar images, from Windows

$
0
0
Here is a quicky for populating toolbars with standard bitmaps embedded in comctl32.dll.

There is still (at least) one bug: if you load some large (24x24) bitmaps and then shift and load some small 916x160 bitmaps the small ones get corrupted. probably an issue with the way I'm using PictureBoxes in there.

This is a control and not a class so that I can use those PictureBoxes to cut up the image-strip bitmaps instead of doing a lot of GDI API fiddling.
Attached Images
 
Attached Files

[VB6] Rotate Image

$
0
0
Hi Guys,

Do you have any idea to rotate image from VB6.0 (just the way windows photo viewer did).
I made an image viewer (zoom in, zoom out) to compare image, the problem is I can't rotate the image.
Kindly advice..

Thanks,
Jefri

Translator with Sound/Speech

$
0
0
Here is a little word translation sample i would like people to have.. if you have any questions feel free to ask. you can also download the sounds/speech, ask me how if you need and i will show you how

i only used textbox and mine does not display (chinese,arabic...) languages its shows up as ?????... if you need other languages i would recommend switch to other types of control that will support other languages such as "Microsoft Forms 2.0 Object Library" (or other controls)

Speech translation will work however, even if it does not display correctly in textbox

anyways here is a working translator with sound


***Additional*** Example of how to get speech/sound status
Code:

Private Sub Command1_Click()
WindowsMediaPlayer1.URL = "http://translate.google.com/translate_tts?ie=UTF-8&tl=" & GetLanguage(cmbTo) & "&q=" & ieGoogle.document.getElementById("result_box").innertext
ChangeStatus "Loading Speech/Audio...."
Do Until WindowsMediaPlayer1.playState = wmppsPlaying
  DoEvents
Loop
ChangeStatus "Playing Speech/Audio..."
Do Until WindowsMediaPlayer1.playState = wmppsStopped
  DoEvents
Loop
ChangeStatus "Ready"
End Sub

Private Sub Command2_Click()
WindowsMediaPlayer1.URL = "http://translate.google.com/translate_tts?ie=UTF-8&tl=" & GetLanguage(cmbFrom) & "&q=" & txtTranslate.Text
ChangeStatus "Loading Speech/Audio...."
Do Until WindowsMediaPlayer1.playState = wmppsPlaying
  DoEvents
Loop
ChangeStatus "Playing Speech/Audio..."
Do Until WindowsMediaPlayer1.playState = wmppsStopped
  DoEvents
Loop
ChangeStatus "Ready"
End Sub

Private Sub cmdTranslate_Click()
On Error Resume Next
  Command1.Enabled = True
  Command2.Enabled = True
  txtResult.Enabled = True
  txtResult.Text = ieGoogle.document.getElementById("result_box").innertext
 
  ChangeStatus "Preparing Speech/Audio...."
 
  WindowsMediaPlayer1.URL = "http://translate.google.com/translate_tts?ie=UTF-8&tl=" & GetLanguage(cmbFrom) & "&q="
 
  Do Until WindowsMediaPlayer1.playState = wmppsReady
    DoEvents
  Loop
  ChangeStatus "Ready"
End Sub

Attached Files

VB5/6/VBA - HeapsortVarVar, Another VB Sort

$
0
0
This is a VB6 static (.BAS) module for sorting a Variant array of Variant arrays using the Heapsort algorithm. It could easily be converted to a class (.CLS) if desired as well.

It should be usable in VB5 and VBA, but this hasn't been tested. it should even be convertable to VBScript, though with much reduced performance of course.


Why VarVars?

When I need to work on large sets of row/col-based (tabular) data and I can't use a database or ADO Recordset I find Variant arrays of Variant arrays handy. Much handier then a 2-D array of String because I can used typed data, far less clunky than working with inflexible UDT arrays where you can't iterate over the fields, and even more useful than 2-D Variant arrays.

Typed data instead of String for everything can be very useful. In a field typed as Single, Double, Currency, etc. 2 and 2.0 will compare properly.

For another thing you can build a "row" of fields easily just using the VB Array() function, then assign it to a "row" slot in your Variant rows array.


Why Heapsort?

The Heapsort is reasonably speedy, doesn't require additional space, and performs well even in worst-case input sequences.

But the main reason is that it is easy to modify to perform the sort in several steps. This makes it possible to use a Timer control to drive a "background" sort that doesn't cause your programs to become unresponsive. This does add to the time a little, but the Timer.Interval need only be 16 to 32 milliseconds for most purposes. It also allows you update progress bars, handle "cancel" button clicks, etc.

This has always been the preferred way to handle this in VB6, as the manual states in many places. DoEvents() calls have their place, but DoEvents() is evil, should rarely be used, and even then only used quite carefully.

However both a synchronous sort and a quantified "pseudo-async" sort are provided here.


Usage

Basically, just add HeapsortVarVar.bas to your projects.

Then when you have a Variant array of Variant arrays to sort, call the SortBy() subroutine (or the QuantumSortBy() function until it returns False).

You pass the column index to sort on, the outer (rows) array to be sorted, and an optional Boolean Descending value (True or False, default False) to specify the direction of the sort.

QuantumSortBy() has two more parameters but the source code comments should explain those. These need to be initialized before the first call of each sort to be performed.

There are no extra dependencies.


Issues

There are sorts that can be faster, Quicksort is popular. However they aren't usually enough faster to warrant sacrificing some of the things that are easy to do to Heapsort (e.g. a quantified pseudo-async version).

If you create a Quicksort adapted for this I'd love to see it. Right now HeapsortVarVar works plenty fast for me, but more speed without additional pain is always appreciated.

Bugs. As far as I can tell there aren't any, but if you find some I'd like to know about them.

I find this very versatile, and once "known bug free" it should make a useful and easily reusable sort for VB users. While you can use it for sorting single items, it would be better to just create a new version tailored to work on a simple single-valued 1-D array.


Demos

There are two in the ZIP archive attachment. They are "ready to run" with a sample input file included, though I'd try testing after compiling to an EXE first. There is more data included than it appears, though it ZIPpped fairly small because it's about 1500 records copied into the file multiple times. The sort isn't too bad even in the IDE, however populating and re-populating the flexgrid can take a while.

Yes, I know the flexgrids can sort, but here it is just being used for demo purposes.

HeapsortDemo

This is a GUI program that loads and parses the sample data into a VarVar and displays it in an MSHFlexGrid. Then you can click or shift-click the column headers to sort and redisplay the VarVar contents.

Yes, there are a couple of UI quirks, related to the column click selecting cells in the grid. The program tries to clear these selections but it doesn't always succeed. The grid is merely being used for demo purposes here anyway. But you may already know of a fix for that if you care.

DeleteDups

A simpler program without any Forms that loads up the sample data, then sorts on the second column as a Single value, then
writes a new file including only the first row for each unique "second column" value.

It uses MsgBox calls to display when it reaches each phase and the time each phase takes.
Attached Files

VB6 - SillyStream Encrypted Text I/O

$
0
0
While hand-rolled encryption is never a good idea, sometimes you don't need a high-security solution. SillyStream is a text I/O class that you can set a few parameters on and then do low-volme encrypted text file I/O. It would need optimization if you really need to work on large files, but it was really intended for smaller items such as settings files.


Usage

Pretty simple, just add SillyStream.cls to your Project. Then create instances as you need them (eaach only handles one file at a a time). Call Init() to set the parameters, then one of the open methods (input, output, append), and use the read and write methods, and finally the close method. Then you can open a new file either with or without setting new parameters first.


Parameters

There are two mask values (one a Byte, another a Long) and two dimensional parameters. These have funny names in the class and in the demo Project. See the comments for an explanation.


Cipher Used Here

This is a combination cipher, based on two very very simple ciphers.

The main feature here is a transposition cipher using the two dimensions provided to create a buffer block as a matrix. When writing or reading the file, the data is an inversion of this matrix.

On top of that we have simple (really simple) substitution cipher. All of the data characters a XORed with a one Byte mask. With some effort you could use a longer "password" mask but it complicates things (especially "open append" operations).

The final block is padded with pseudorandom values.

Finally, to make this work even with a padded final block, the actual data length is stored in the first 4 bytes of the file as a Long value. This is XORed with the Long mask you provide to help obscure it a bit. Adding these 4 bytes has another advantage: It makes it all little tougher to crack because simply trying to factor the file size will be a bit of a red herring even if someone guesses it uses a rectangular transposition cipher.

Dumb but cheap, and perhaps good enough.


Demo

The demo Project lets you open a new files, type some stuff, write is as characters or as a line 9adding newline), etc, and then close. Then you can read it back and see it displayed, using both reading by byte count or the slower reading by line.

Even though slower, I expect most people to just read by line most of the time. Writing by line is probably going to be more useful then by text length as well.

Sample inputs:
Code:

This is a test.
This is only a test.
How now, brown cow?
Mellow yellow, such a silly fellow!
Test test test test test test test test test test testing!

Hex dump:
Code:

0000        e5 54 12 f0 0f 2f 35 13  35 2c 33 37 28 2f 2f 3e  .T.../5.5,37(//>
0010        51 7c 07 8c 15 33 75 37  34 7b 7b 7b 34 2f 3e 7b  Q|...3u74{{{4/>{
0020        28 04 83 14 93 22 32 56  22 2c 38 22 3a 2c 7b 28  (...."2V",8":,{(
0030        2f 2f 0b 90 1b a0 29 28  51 7b 7b 34 3e 7b 7a 2f  //....)(Q{{4>{z/
0040        2f 3e 7b 18 97 28 a7 36  7b 0f 3a 35 2c 37 28 56  />{..(.6{.:5,7(V
0050        3e 7b 28 2f 1f a4 2f b4  3d 32 33 7b 34 64 37 32  >{(/../.=23{4d72
0060        51 28 2f 2f 3e 2c ab 3c  bb 4a 28 32 2f 2c 56 34  Q(//>,.<.J(2/,V4
0070        37 0f 2f 3e 7b 28 33 b8  43 c8 51 7b 28 3e 77 51  7./>{(3.C.Q{(>wQ
0080        2c 37 3e 7b 28 2f 2f 40  bf 50 cf 5e 3a 7b 28 7b  ,7>{(//@.P.^:{({
0090        16 77 22 28 2f 2f 3e 32  47 cc 57 dc 65 7b 32 2f  .w"(//>2G.W.e{2/
00a0        39 3e 7b 7b 2f 3e 7b 28  35 54 d3 64 e3 72 2f 28  9>{{/>{(5T.d.r/(
00b0        75 29 37 28 3d 7b 28 2f  2f 3c 5b e0 6b f0 79 3e  u)7(={(//<[.k.y>
00c0        7b 56 34 37 2e 3e 2f 2f  3e 7b 7a 68 e7 78 f7 86  {V47.>//>{zh.x..
00d0        28 34 51 2c 34 38 37 3e  7b 28 2f 56 6f f4 7f 0e  (4Q,487>{(/Vo...
00e0        8d                                                .

Hex dump of a test with the data XORing omitted. Normally you wouldn't do this but it shows that the transposition and padding can be effective all alone:
Code:

0000        e5 54 12 f0 54 74 6e 48  6e 77 68 6c 73 74 74 65  .T..TtnHnwhlstte
0010        0a af 30 b5 3c 68 2e 6c  6f 20 20 20 6f 74 65 20  ..0.<h.lo  ote
0020        73 37 b6 3d bc 49 69 0d  79 77 63 79 61 77 20 73  s7.=.Ii.ywcyaw s
0030        74 74 3e c3 44 c9 50 73  0a 20 20 6f 65 20 21 74  tt>.D.Ps.  oe !t
0040        74 65 20 4b ca 51 d0 5d  20 54 61 6e 77 6c 73 0d  te K.Q.] Tanwls.
0050        65 20 73 74 52 d7 58 dd  64 69 68 20 6f 3f 6c 69  e stR.X.dih o?li
0060        0a 73 74 74 65 5f de 65  e4 71 73 69 74 77 0d 6f  .stte_.e.qsitw.o
0070        6c 54 74 65 20 73 66 eb  6c f1 78 20 73 65 2c 0a  lTte sf.l.x se,.
0080        77 6c 65 20 73 74 74 73  f2 79 f8 85 61 20 73 20  wle stts.y..a s
0090        4d 2c 79 73 74 74 65 69  7a ff 80 0d 8c 20 69 74  M,ystteiz.... it
00a0        62 65 20 20 74 65 20 73  6e 87 08 8d 14 99 74 73  be  te sn.....ts
00b0        2e 72 6c 73 66 20 73 74  74 67 8e 15 94 21 a0 65  .rlsf sttg...!.e
00c0        20 0d 6f 6c 75 65 74 74  65 20 21 9b 1c a1 28 ad    .oluette !...(.
00d0        73 6f 0a 77 6f 63 6c 65  20 73 74 0d a2 29 a8 35  so.wocle st..).5
00e0        b4                                                .


Bugs

I havent found any, but if you do be sure to mention them.
Attached Files

[RESOLVED] [VB6] Coloring Excel Cell from VB6

$
0
0
Hi Guys,

Do you have any idea how to set excel cell from VB6 Codes?

Set ExlObj = CreateObject("excel.application")
ExlObj.ActiveSheet.Cells(1, 1).Columns.ColumnWidth = 18
ExlObj.ActiveSheet.Cells(l, m).Rows.BackColor = vbGreen << IS NOT WORKING

Thanks,
Jefri
Viewing all 1520 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>