Visual Basic Classic

164K

Solutions

58K

Contributors

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello,

I have got a vbscript which renames the file in a folder the requirement is to loop in a folder and all its subfolders to see the files and rename them.
It works great on a file level but, need to loop in the folders and subfolders as well.
Please find the vbscript attched.
Option Explicit

RenameFiles "C:\test"

Function CanRename(AFileName)

  On Error Resume Next

  Dim Dummy

  Err.Clear
  Dummy = Right(FileNameWithoutExtension(AFileName), 10)
  Dummy = DateSerial(Mid(Dummy, 7, 4), Mid(Dummy, 4, 2), Mid(Dummy, 1, 2))
  CanRename = (Err.Number = 0)
  Err.Clear

End Function

Function FileExtension(AFileName)

  Dim Count
  Dim Result

  Result = ""
  Count = InStrRev(AFileName, ".")
  If Count > 0 Then
    Result = Mid(AFileName, Count, 1024)
  End If

  FileExtension = Result

End Function

Function FileNameWithoutExtension(AFileName)

  Dim Count
  Dim Result

  Result = AFileName
  Count = InStrRev(AFileName, ".")
  If Count > 0 Then
    Result = Mid(AFileName, 1, Count - 1)
  End If

  FileNameWithoutExtension = Result

End Function

Function RenameFileName(AFileName)

  Dim DATE_DELIMITER
  DATE_DELIMITER = "-"

  Dim LITERAL_DELIMITER
  LITERAL_DELIMITER = "_"

  Dim FileName
  Dim DateText

  FileName = FileNameWithoutExtension(AFileName)
  DateText = Right(FileName, 10)
  RenameFileName = _
    Mid(DateText, 7, 4) & DATE_DELIMITER &  Mid(DateText, 4, 2) & DATE_DELIMITER &  Mid(DateText, 1, 2) & LITERAL_DELIMITER & _
    Left(FileName, 

Open in new window

0
Success in ‘20 With a Profitable Pricing Strategy
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Using VB6, I'm trying to detect if a couple of keys are pressed at the time the icon to start the program is clicked.  I need to detect if a particular key combination is pressed before any forms are displayed, so I can't use something like form.keypress (no form loaded yet).
0
Is there any way to determine what the current error handling is in vb6?

Default error handling crashes the program displaying the error message.

If you use:
ON ERROR GOTO Label

Open in new window

The program goes to the point in the code with the label and continues executing (presumably, you have defined what to do here to mitigate the error)

If you use:
ON ERROR RESUME NEXT

Open in new window

The program will continue ignoring errors until it either can't run at all, you handle the errors, or you disable the resume next option.  I often (but not always) use ON ERROR RESUME NEXT to allow the program to continue and then I explicitly check for an error number and handle the error there.  For example:
ON ERROR RESUME NEXT
X = 5
IF X = "bob" THEN X = "Bob"
IF ERR.NUMBER <> 0 THEN
   'Handle the error
END IF 

Open in new window


And to disable graceful error handling, you use
ON ERROR GOTO 0

Open in new window


But is there any way to tell if graceful error handling is on?  Any way to tell that the last time an ON ERROR statement executed it was set to go to a label, resume next, or goto 0?
0
I am looking for a source for downloading intraday data at various intervals. Thank you very much!
0
I have a quick question.  What data type in SQL do would I typically use for an option true/false button?  The true/false button is coming from a VB application.
0
When installing a apps on Window 10 and run, it hang up and return the following messsage..

Any idea ?

Faulting module path: C:\KJTech\Guardian\TABCTL32.OCX
0
One pc in network must write to a random file, on a shared map ,   to a specific record nummer one string in a field  without closing the file it will do that on a event or command  , thus update that record with new string
Other Pc must open that file, keeps it open, and reads every 2 second that record, if string has value
it will read it and sets record to zero spaces and update file
How  to do this without conflict ???
0
I would like to speed this query up if at all possible.  Not sure if that can be done with execute rather than  open.  Big meet Saturday...just trying to optimize execution.  Thanks!

    i = 0
    ReDim PartsToSwitch(0)
    Set rs = New ADODB.Recordset
    sql = "SELECT r.RosterSrvrID, ir.ElpsdTime FROM Roster r INNER JOIN IndRslts ir ON r.RosterSrvrID = ir.RosterSrvrID "
    sql = sql & " WHERE ir.RaceSrvrID = " & lRaceFrom & " AND r.Gender = '" & sGender & "' ORDER BY ir.ElpsdTime"
    rs.Open sql, conn, 1, 2
    Do While Not rs.EOF
        dblElpsdTime = ConvertToSeconds(rs(1).Value)
        
        iMyGrade = 0
        If iGradeFrom > 0 Then iMyGrade = GetMyGrade(rs(0).Value)   'get my grade only if using grade as a filter
        
        If iMyGrade >= iGradeFrom And iMyGrade <= iGradeTo Then 'make sure the grade is in the correct window
            If dblElpsdTime >= dblTimeFrom Then
                If dblElpsdTime <= dblTimeTo Then
                    PartsToSwitch(i) = rs(0).Value
                    i = i + 1
                    ReDim Preserve PartsToSwitch(i)
                End If
            End If
        End If
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing

Open in new window

0
How do you write a Worksheet Selection Change to Hide rows before a start time and hide rows after the end time.
  My schedule starts at row 5 Column D.  It contains entries in 15 minute increments starting at 12:00am. and extends 11:45pm, row 101.
In B7 and B8 I have Start time Row: and End time Row, calculations.  So I know (form example) that if the start time is 6:00am then that is row 30 and If stop time is 19:00, then that is row 81.
  So what I would like to do is have a change event, that will (in the example above), Hide rows 29 through Row6, and Hide Rows 82 through Row 101.

This is variable because AB5 (work Start Time) and AC5 (work end time) can change, but the start time Row Count and End time Row count B7 and B8 will automatically update when AB5 and AC5 is changed. (I have already done that).

I hope this makes sense...
Thanks,
Norm
0
I have a vb classic two-dimensional array called Arr(2, i).  It is currently sorted by the third element (index 2).  I want to sort it by the first element (index 0) and then keep it sorted within index 0 by index 2.  In other words, if the array consisted of:

Arr(0, 0) = 1
Arr(1, 0) = x
Arr(2, 0) = 100

Arr(0, 1) = 2
Arr(1, 1) = x
Arr(2, 1) = 200

Arr(0, 2) = 1
Arr(1, 2) = x
Arr(2, 2) = 300

Arr(0, 3) = 2
Arr(1, 3) = x
Arr(2, 3) = 400

I would like it to be sorted into this:

Arr(0, 0) = 1
Arr(1, 0) = x
Arr(2, 0) = 100

Arr(0, 1) = 1
Arr(1, 1) = x
Arr(2, 1) = 300

Arr(0, 2) = 2
Arr(1, 2) = x
Arr(2, 2) = 200

Arr(0, 3) = 2
Arr(1, 3) = x
Arr(2, 3) = 400
0
Why Diversity in Tech Matters
LVL 19
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

I am writing a windows forms application. One of the windows forms has an edit text box control on it. If I tab outside of this particular edit control, I would like the "tab-out" action to be interpreted as the user pressing the enter button. I believe that there is a Lost Focus event for the text box control, so possibly I can check for that event. What I need to know is how to force an "Enter" event when the tab out (Lost focus) event occurs.

Does anyone know how I could cause the "Enter" event to occur when the focus changes?
0
I want to determine if there is an open VNC connection to the host PC from inside my VB6 app. How can I do this?
0
I have a form which is used for two purposes, Quoting and Job Costing. There is a combobox to select which either of these options.

On the form is a Combobox (allow Inserts) which looks up a table of parts we are likely to use again a job.

If "Quoting" is selected we pick the item from a pre-populated table, then obtain a price from a supplier.

If, however, it is a "Job Costing" (i.e. the job has been carried out) we want the combobox to select from the table of parts used (which will have the cost we paid already available).

Thanks in anticipation
0
In other postings here, I learned (from Vadim Rapp) that I should pay attention to where components of a program are installed. Programs should go to Windows Program folders. Files of data that are read from and written to should go to Windows Data folders.

I am maintaining a legacy program that I created using VB6 a long time ago. Here is a list of files to be installed for this program. Please check my sort between "Program" and "data" folders.

PROGRAM FILE FOLDER:
4 .exe
1 .ico
2 .bmp
14 .txt Read only. Two are assembled into coded matrices. 12 are "Help" files.
1 .OCX regestered by the installer.

DATA FILE FOLDER:
Eleven data files that are program modifiable.
Some are text and some are Excel spreadsheets.
The Excel spreadsheets are "mission critical." To prevent users from getting in there and messing things up, I gave them the suffix ".sdp" which is not recognized by Windows (but is recognized by my program). These have to be replaceable by a set from this program run on a different computer.

I use Inno to build the installer. Here are two Inno script lines. The one for the OCX is different from all the rest.

Source: "F:\SS_Build\DataCalendar.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\SS_Build\MSFLXGRD.OCX"; DestDir: "{app}"; Flags: restartreplace sharedfile regserver

Now (finally) to my questions:

(1) "DestDir" was established by Inno during creation of the installer. There has to be a way to specify two different …
0
I have a vb6 program that takes data from SQL and puts it into an excel sheet.  One of the SQL fields has A LOT of text in it and when it pastes into the excel field I get an "application defined or object defined error"  There are about 2400 words in the field.  It seems I traced it to the fact that there is too much data in the one field being placed into the excel field.   Does that sound too large for the field or any other observations?  If its too big, what are the limits on size?
1
I am maintaining a legacy app I wrote in VB6 a long time ago. Development is done on
an external hard drive that I switch between two machines, XP for development, and
Win7 to test run. I use Inno to build the installer. Installer works successfuly all
the way up through Win10. Installation occupies a shade under 1 MB.
All required associated files for the project, and four compiled executables
(including the new one) are gathered  on the external hard drive in a folder named
"SS_Build".

I was asked to add a feature (MakeNewPlayers.exe). An Excel spreadsheet is read in,
modified, and written out. Works perfectly in development mode. Works perfectly when
executed from the Build folder under XP. Works perfectly when executed from the Build
folder under Win 7.

Doesn't work from the installation created by Inno. Program stalls near the bottom,
where the modified Excel spreadsheet is written out. The message box does not appear.
If I exit, system asks me if I want to save "Book1", which tells me the modified
spreadsheet actually was created (but apparently not named), confirmed by looking at
"Book1".

Here is the relevant source code:

Set oXLApp = CreateObject("Excel.Application")
If oXLApp.Application.Version > "11.0" Then
    iXLversion = 56
Else
    iXLversion = -4143
End If
Set oXLApp = Nothing

Set oXLApp = CreateObject("Excel.Application")
(code that modifys spreadsheet goes here)

SavePath = App.Path & "\" & sWorkbookName

Open in new window

0
What is the best way to have a timer displaying the running time of a race (or several races) in vb6.  Let's say that one race started at precisely 8:00:00 AM and a second race started at 8:14:56 AM.  I would like a display on our results page that continually shows the elapsed time of each race (h:mm:ss would be fine).  I could use a quick blurb of pseudo-code if anyone has the time.  I could figure this out but I want it to be as "efficient" a utility as possible because results and other functionality will be occurring throughout the duration of the event.

Thanks in advance!!
0
Dear Team,

I have the below vba code to insert bullets with customize formats and alignment. Now I am looking forward to the incorporate the following below mentioned actions  in the code .

Please note that slide contains 2 text placeholder one for the Title and other for text


1. Reposition my text placeholder having (Top=75, Left=90,Width=739 and Height may vary depending on text.To have more clarity for the position of text placeholder I have appended below the image of shape dimensions from Microsoft power point 2016.


2. the text inside the placeholder should be calibri , size 12 & color (R=89,G=89,B=89)

For the size and margins to be freezed I am attaching an image for better clarity.



I need to collate this action with the below mentioned codes to have alignment of text and bullets


Sub Mybullets()

Dim pghcnt As Integer

With ActiveWindow.Selection.TextRange

.ParagraphFormat.bullet.Font.Name = "Wingdings"

.ParagraphFormat.bullet.Character = 167

.ParagraphFormat.Alignment = ppAlignJustify

.ParagraphFormat.bullet.Font.Color = RGB(89, 89, 89)

.ParagraphFormat.bullet.RelativeSize = 0.75


End With

For pghcnt = 1 To Windows(1).Selection.TextRange.Paragraphs.Count

Windows(1).Selection.TextRange.Paragraphs(pghcnt).IndentLevel = 1

With Windows(1).Selection.ShapeRange.TextFrame.Ruler

.Levels(1).FirstMargin = 7

.Levels(1).LeftMargin = 20

End With

Next

End Sub

Open in new window

Further the layout contains title and content placeholder.

Please help me to collate the text part as well.

Thanks in advance

Regards
Dilpreet Singh
content.PNG
0
i have two different server having SQL server 2014. it has two different IP address. I can create ODBC to both server. when i try connect two different database on different server , i got the message ODBC SQL SERVER - INVALID OBJECT NAME in vb6 application,  I can open database on local server. but cannot open file on different server with different IP address.  What could be the problem. how can solve this problem. Thanks in advance.
0
Announcing the Winners!
LVL 19
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

How can I authenticate the User ID and Password to be valid from VB.Net and VB6 programs with Windows 7 Active Directory?
0
How do I pass an object as a parameter in vb6 when calling a sub?  I want to create a sub that will execute an ftp script in a module but the Inet object is in the form.  I should know this but...  Also, is that ByVal or ByRef?  I assume ByRef?

Thank you in advance!
0
I need to access data from a race timing machine via an ethernet connection as runners cross the finish line.  I have a TelNet connection that is working but I am not sure how to keep it from timing out.  In my search for a solution to that I have been directed to SSH.  I have open SSH installed on my Windows 10 machine.  How can I connect my timing box with my PC using a vb6 program.  This piece is all very new to me.

Thanks for your assistance!
0
I have a TelNet utility in my vb6 app for race timing to get finish times from my timing machine to my computer.  It has been working well but at the last race (one of the first I have used it for) it stopped sending data after about an hour.  Is there typically a time-out feature in TelNet and, if so, how can it be adjusted?  I can post the code if need be.
0
I have Excel 2016 and I need to have this statement executed on 540 rows.  How would I set this up to be applied to all of those rows?

=SUBSTITUTE(SUBSTITUTE(B$1,"before-value",A3),"after-value",B3)

Open in new window


This creates a statement out of the combined rows.  Currently, I have to increment the cell values manually for each pair.
1
Hi all, I'm trying to make a program that picks up scanner codes from a hand scanner device that's plugged into a USB port on a Windows PC.  I'm writing it in Visual Basic 6 because it's still my favorite program for making quick apps like this.  The hand scanner just sends the string of text that's in the code to the PC, and it sends it very fast.  To start out, I made a pretty simple program just to see if it's possible to catch all the characters fast enough and I'm having trouble with that part.  It seems to grab random characters and I can't go lower than 1 ms on the timer.  

I need it to be able to grab the characters from the keyboard buffer even if it's not the program that's in focus so I used the GetAsyncKeyState function from windows api.  Here is my form code that isn't catching all of the characters:

Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Private Sub Command1_Click()
    Label1.Caption = ""
End Sub

Private Sub Timer1_Timer()
    Dim nKey, nChar As Integer
    Dim nText As String
    For nChar = 16 To 255
        nKey = GetAsyncKeyState(nChar)
        If nKey = -32767 Or nKey = -32768 Then
            nText = CStr(nChar) + " "
            Label1.Caption = Label1.Caption + nText
        End If
    Next
End Sub

Open in new window


All I have on the form are a label, buttons, and timer with a 1 ms interval. The label1 will show a few random character codes from the code after I scan one. Does anyone have advice for making it catch all the characters from the hand scanner?  I also tried it with GetKeyState and it had the same problem.
0

Visual Basic Classic

164K

Solutions

58K

Contributors

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.