Category Archives: Visual Basic 6 (VB6)

Floating Point Numbers Validation

Just like the title says, the code in the attached file will validate the floating point numbers in a text box. Usage Create a form with a textbox, and insert the following into the form code: Private Sub Form_Load()    Text1.Text = Empty End Sub Private Sub Text1_KeyPress(KeyAscii As Integer)    ‘ Precision is 2 in this case   ‘ Send the… Read More »

Remove a Record from an Array

Remove any record from an array, without leaving a gap in the records. Option Explicit Private Type my_type   field1 As String   field2 As Long   field3 As IntegerEnd Type Const MAX_ARRAY = 10Dim my_array(0 To MAX_ARRAY – 1) As my_type ‘Delete the record RecPos (from 0 to MaxRecs)…MaxRecs is the maximum array dimensionPublic Sub DeleteRecordFromMyArray(RecPos As Integer, MaxRecs As Integer)   Dim i As… Read More »

Time Between Dates

Calculate the time elapsed between two dates. Option ExplicitPublic Function ElapsedTime(tStart, tStop) As String’ *******************************************************************’ Function Name : ElapsedTime *’ Created By : Herry Hariry Amin *’ Email : h2arr@cbn.net.id *’ Language : VB4, VB5, VB6 *’ Example : sYourVariable = ElapsedTime(tStartTime,tStopTime) *’ *******************************************************************    Dim dtr, dtl, jml As Long    dtl = (Hour(tStart) * 3600) + (Minute(tStart) *… Read More »

Find if a value exists in an Array

This handy little function will determine if a value is present in an array, and return true or false. Option Explicit Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean   On Error GoTo LocalError   If Not IsArray(arrSearch) Then Exit Function   If Not IsNumeric(FindValue) Then FindValue = UCase(FindValue)   IsInArray = InStr(1, vbNullChar & Join(arrSearch, vbNullChar) & vbNullChar, _vbNullChar & FindValue & vbNullChar)… Read More »

Get the Full Path of a File

This is a very simple way to get just the full directory path of a file passed in. Public Function GetTheFilePath(ByVal strFile) As String   Files = Split(strFile, “\”)   For I = 0 to (UBound(Files) – 1)      FilePath = FilePath & Files(I) & “\”   Next   GetTheFilePath = FilePathEnd Function Usage MyFilePath = GetTheFilePath(“C:\testing\jim\file.txt”) will return: C:\testing\jim\

Multiple Files with CommonDialog

Ever wonder how to return multiple files using the CommonDialog control? Here is a short demonstration of how to get it done. Private Sub cmdOpen_Click()   Dim sFileNames() As String   Dim iCount As Integer    cd.Filter = “All Files|*.*”   cd.Flags = cdlOFNAllowMultiselect   cd.ShowOpen    If cd.FileName <> “” Then      sFileNames = Split(cd.FileName, Chr(32))      For iCount = LBound(sFileNames) To UBound(sFileNames)         MsgBox sFileNames(iCount), vbInformation      Next    End IfEnd Sub

Convert a Decimal Number in a Given Base

Just a little something to help you do math in different numbering systems. Option Explicit ‘Convert a decimal number in another basePublic Function CBase(ByVal number As Long, ByVal base As Long) As String   ‘symbols to code the number   Const chars = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”   Dim r As Long    ‘verify if there are enought symbols to code the number in the selected base   If base… Read More »

String Encrypt and Decrypt

These two function provide a simple method to encrypt and decrypt a string. Simply drop this code in to a module, and it is ready for use. Option Explicit Public Function Encrypt(ByVal icText As String) As StringDim icLen As IntegerDim icNewText As StringicChar = “”   icLen = Len(icText)   For i = 1 To icLen      icChar = Mid(icText, i, 1)      Select Case Asc(icChar)         Case… Read More »

Read Remote Registry

This tip is based on existing tip (but with some bugfixes and explanation). The code should be treated as an example, e.g. more treating needed of other kinds of values Usage Dim CompName, sSMS_Site, sSMS_Travel As String CompName = “\\MyComputerName” sSMS_Site = ReadRemoteReg(CompName, HKEY_LOCAL_MACHINE, _ &nsbp; “SOFTWARE\Microsoft\Windows NT\CurrentVersion”, “SystemRoot”) Attachments File Uploaded Size 970-20190822-170650-remotereg.zip 8/22/2019 5:06:50 PM 2583

Get the Username of the Logged On User

This function will allow you to easily get the username of the currently logged on user. Just pop it in to a module, and you’re good to go. Private Declare Function GetUserName Lib “advapi32.dll” Alias “GetUserNameA” (ByVal lpBuffer As String, nSize As Long) As Long Public Function UserName() As String   Dim cn As String   Dim ls As Long   Dim res As… Read More »