We help IT Professionals succeed at work.

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.

Hi,

I'm seeing a weird thing when i click on my vb6 button that runs below script.

From my vb6 app, i'm only having 1 single record when in reality, i have 9 records.
one records
And just to make sure the 9 records are good, i ran the same query using "Wbemtest.exe", and it pull me 9 records.
9 records
So at this point, i'm thinking that it may be an issue with my VB6 "FOR / NEXT loop. Looks like it only show the last record only in the msgbox.

Are you seeing anything wrong with below code that would only show 1 record instead of 9?


Private Sub bluetooth_device_Click()

 strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity where Description like '%Bluet%'", , 48)
    For Each objItem In colItems
        Text = "DeviceID: " & objItem.DeviceID
Text = Text & vbCrLf & "Description: " & objItem.Description
Text = Text & vbCrLf & "Caption: " & objItem.Caption
Text = Text & vbCrLf & "Name: " & objItem.Name
Text = Text & vbCrLf & "Manufacturer: " & objItem.Manufacturer
Text = Text & vbCrLf & "Status: " & objItem.Status
Text = Text & vbCrLf & "Service: " & objItem.Service
    Next objItem
    

    MsgBox Text

End Sub

Open in new window


Thanks for your help
0
Hi

I have below code in my VB6 application where it search for : SELECT * FROM Win32_PnPSignedDriver where (FriendlyName like '% ANT %')

It works but not 100% doing what i want him to do.

 strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPSignedDriver where (FriendlyName like '% ANT %')", , 48)
    'Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPSignedDriver", , 48)
    For Each objItem In colItems
        Text = "DeviceID: " & objItem.DeviceID
     Text = Text & vbCrLf & "CompatID: " & objItem.CompatID
Text = Text & vbCrLf & "Description: " & objItem.Description
Text = Text & vbCrLf & "DeviceClass: " & objItem.DeviceClass
Text = Text & vbCrLf & "DeviceID: " & objItem.DeviceID
Text = Text & vbCrLf & "DeviceName: " & objItem.DeviceName
Text = Text & vbCrLf & "DevLoader: " & objItem.DevLoader
Text = Text & vbCrLf & "DriverDate: " & objItem.DriverDate
Text = Text & vbCrLf & "DriverName: " & objItem.DriverName
Text = Text & vbCrLf & "DriverVersion: " & objItem.DriverVersion
Text = Text & vbCrLf & "FriendlyName: " & objItem.FriendlyName
Text = Text & vbCrLf & "HardWareID: " & objItem.HardWareID
Text = Text & vbCrLf & "InfName: " & objItem.InfName
Text = Text & vbCrLf & "InstallDate: " & objItem.InstallDate
Text = Text & vbCrLf & "IsSigned: " & objItem.IsSigned
Text = Text & vbCrLf & "Location: " & objItem.Location
Text = Text & vbCrLf & 

Open in new window

0
Hi,

I have below code that uses Powershell to pull some information. I would like to do the exact same thing, but using CMD instead. I can i do that?

Private Sub InfoAddressIp_Click()
Dim WshShell, oExec, sCommandLine
    sCommandLine = "ipconfig"

    Set WshShell = CreateObject("WScript.Shell")


    Set oExec = WshShell.Exec(sCommandLine)

    Do While oExec.Status = 0
         'WScript.Sleep 100
    Loop

    MsgBox oExec.StdOut.ReadAll
End Sub

Open in new window


Thanks again for your help
0
Hi, I normally use below Powershell script to pull the Windows Update status.

get-service wuauserv | select Displayname,Status,ServiceName,Can*

Open in new window


Now what i would like to do is to run that script via my VB6 application.
So by clicking on a button, it give me the result in a msgbox.

I'm able to do it for the "ipconfig" but not able for "wuauserv"

This is what i have so far:
Private Sub Command1_Click()
'get-service wuauserv | select Displayname,Status,ServiceName,Can*

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("ipconfig")

Do While oExec.Status = 0
     'WScript.Sleep 100
Loop
MsgBox oExec.StdOut.ReadAll
End Sub

Open in new window


Thanks for your help
0
Hi

I would like to use a VB application to give me the Task Manager service "wuauserv" status (Windows Update). I would like to create a command button that will pull the status and add it to my Label1.

Windows update
How can i do that?

Thanks for your help.
0
I have created a multiple-userform application called the “Text Editing Tool”, whose purpose is to enable me to select text, highlight it and add a comment without having to re-select the text. It also provides a means of loading a separate Word document table into its comments combobox to serve as pre-written comments that can be added without typing them each time.
The problem I’m experiencing is that whenever I open another form in the same project, or when I open a standard dialog box (save as), the comments list entries disappear. This occurs when I click ‘Manage Open’, which opens a userform that lists all the open documents, when I click ‘Choose Highlight Color’, which opens another userform so a highlight color can be selected, and when I click ‘Save List’, which opens the Save As dialog. In all three cases, whether I select a document to close in ‘Manage Open’, a color in ‘Choose Highlight Color’, or save a document in Save As, or if I just close those forms and dialog box without selecting anything, the comments list combobox in the main form (frmTextEdit) gets wiped out.
The frmTextEdit form also appears to close when I close the Save As dialog after clicking ‘Save List’ or ‘Create list’. Stepping through the code, Initialize is not run when I reopen this form.
I’ve tried preserving the comments list in an array, or repopulating it from the open Word document; I’ve tried adding doevents; and I’ve tried hiding the other forms instead of closing them, but nothing…
0
I need to log a putty session using vb6.  I am able to initiate Putty using the following:

Shell "C:\Program Files\PuTTY\putty.exe telnet:192.168.1." & sWhichBox & ":10001", vbNormalFocus

Now I need to direct the output to a specific file in a specific directory using vb6.  The location  will look like this: sPath & "trident_" & sWhichBox & ".log"

I would really appreciate any assistance I can get with this?

Thank you very much!!
0
I had this question after viewing To Reindex DBF file Using VB6.
I think that the answer to above question is only demonstrate that Microsoft DAO 3.51 Object Library can index database file. However, if an index file is corrupted/damaged, the DAO won't work properly. Normally, I need to fix the damaged index file via "reindex" command using Foxpro. So, I would like to know if there is a way to do the reindex in VB6.

Best Regards
Ming
0
Hello,

I wrote an activeX dll (CustomWindowMessage.dll), wich hold an insanciable object (Factory).
My current project is referencing the dll (early binding).

I would like to late bind it:
The syntax for the CreateObject function require the class name and optionally the server name as parameters.
I did try the following, without success.
Dim Factory as Object
Set Factory = CreateObject("CustomWindowMessage.Factory")

Open in new window

Guess the class name is wrong.
How can I figure out the class name (and if necessary, the server name) ?
0
I am adjusting a VB6 statement in which the application is making a request from the SQL database and the value contains quotation marks in it.  The result is an error:  Incorrect syntax near 'value'  

The requesting statement from VB6 is:

select count(*), Max(Grouping) from tblOrgHours where Narrative = '" & Text1 & "'"

If Text1 contains quotation marks in it then the error is produced.  How can I avoid this?
0
In the attached file I'd like to keep the cell references the same despite the fact that I have to update the data in cells C2:H2.

To update I click inset a row which means the data moves down. When this happens the cell references increment one every time I add a row. That means instead of remaining "C2:G47" the cell references increment by one as shown in the formula below. The formulas  are in cells Q4:Y11.

=IFERROR(AGGREGATE(15,6,$C$3:$G$48/($C$3:$G$48>P4),1),"")

If it cannot be done with the formulas and data in same sheet.  I will need the code to use in the formula to reference from the new page to the data page.
KeepSameCellReferenceWhenMovingCell.xlsm
0
Hello, All.

I am trying my best to NOT have to encode the apostrophe in a URL name to this: Nothin%27_to_Lose.
I have tried to replace the apostrophe with a * or a Period, and when I do a Request.QueryString("Title") on this
Nothin*_to_Lose
It is replaced with
Nothin

What am I missing here?
Does the Request.QueryString() not work with these types of characters?

Wayne
0
I need a utility that will transmit data from a timing box to my pc over an ethernet cable.  Is there a better solution than TelNet?  It would be nice if it came with vb6 source code so I could modify it to control the directory where it sends the data.
0
I am a race timer and I use a proprietary timing software.  I am migrating to a new timing system and in order to get it to work with my software I have to stream the data from the timing box to a directory on my PC using a TelNet utility.  I have one that works perfectly...except that it seems to time out or simply stop communicating at certain points for one reason or another.  I need to resolve this in order to complete my migration.  

I found a TelNet program and modified it using vb6 to interface nicely with my system.  I have the source code.  I am looking for help on finding a setting or something that is causing the failure.  Let me know what I need to provide.  If this is more than I should be asking for I am willing to pay a reasonable fee for help with this.

Thank you very much!
0
listing in vb6 with errorTrying to get some calls running in VB6 to use Postmessage  Function
This is a call to the functions in a program wich now i can now only use bij shelling to commandline ,
like   Shell "J:\VIRT_KEYBORD\MOVETOPKB  ", vbHide
Utillity from  https://hot-virtual-keyboard.com/

According their on-site manal  should be possible to do like this


Const WM_CSKEYBOARD = &H400 + 192
Const WM_CSKEYBOARDMOVE = &H400 + 193
Const WM_CSKEYBOARDRESIZE = &H400 + 197
 
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
         ByVal lParam As Integer) As Integer



    'Move Hot Virtual Keyboard in Visual Basic; Move it first then show itresponse helpdesk    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Handles Button3.Click
        Dim hWnd As Integer
        hWnd = FindWindow("TFirstForm", "hvkFirstForm")
        PostMessage(hWnd, WM_CSKEYBOARDMOVE, 200, 200)
        PostMessage(hWnd, WM_CSKEYBOARD, 1, 0)
    End Sub

But calls to postmessga gives in Editor red syntax status
Support desk from supplier could not help me out on this

please see the attachd file from program listing and response helpdesk wich does not sove my problem

Thanks for help
0
i need to add 2 additional features to the search form in the excel workbook but when it opens on my home pc it produces error msgs & will not work.
At work, it works perfectly.
Could you please change the code so it works for me at home also. I have excel 2016 at work & at home.
zSearch-form_shape.xlsm
0
I'm having to support an ancient VB6 application. Currently, I'm writing a COM object class for it. Everything works except for assigning a value to a property. This particular property needs to behave like a VB6 variant data type when used in VB6 code.

I have the simplest little class in C#
    [ComVisible(true)]
    [Guid("1EB35E9B-60EE-4A26-BAEB-6A2D7AC32FF0")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class FooThingy
    {
        private object _value;

        public object Value
        {
            get
            {
                return _value;
            }
            set
            {
                _value = value;
            }
        }

        public FooThingy()
        {

        }
    }

Open in new window

And I call it via the simplest VB6 code. I have added line numbers for easy reference.
Public Sub Main()
    
1    Dim foo As FooThingy
2    Set foo = New FooThingy
3    If (foo.value <> "hello") Then
4        foo.value = "Testing"
5    End If

End Sub

Open in new window

At line 4 it fails with a runtime error 424 "Object required" yet line 3 evaluates with no problem. I know VB6 has this weird distinction between Property Let and Property Set and I'm guessing that is somehow related. What I need to figure out is how do I get my C# class to work with the VB6 code above. Perhaps there's some kind of marshaling declaration that will do the trick? I'm really hoping there's an answer to this because my alternative is to go through this very old VB6 program that was very badly written and find all the places where assignment is being done and replace it with a SetValue() method call which DOES work.
0
For some time now I've been writing C# COM visible DLLs for use in an old VB6 application.

I've recently become aware that my COM visible class isn't browsable in the Object Browser nor does the IDE catch compile-time errors. Here's a sample interface and class:
namespace Sample
{
    [Guid("FDB56085-E1C2-41E3-8B6A-86F734B9338B")]
    public interface ITest
    {
        #region Methods

        void Foo();
        void Bar();

        #endregion
    }
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("6717C7FC-9E3F-47A1-955C-09734F96B18F")]
    public class Test: ITest
    {
        #region Public Methods

        public void Foo()
        {

        }

        public void Bar()
        {

        }

        #endregion
    }
}

Open in new window

All this compiles fine and any code I insert into Foo() or Bar() will execute without a problem. However, I can also do this in VB6:
    Dim tAs Sample.Test
    t.Foo
    t.Bar
    t.CompileError

Open in new window

and the compiler doesn't complain at all. At runtime the last line does generate an error indicating that the method is not implemented but nothing at compile time. Also, the entire class is not browsable in the Object Browser. I can live with the 2nd part but I'm hoping there's a way to force the compiler to catch such errors during compilation. Any suggestions?
0
Finding out status of printspooler empty or not
In Vb6 we do shelling this

I use ( advised by : Steve Knight )   this to turn a printer(s) off line
cscript "C:\Windows\System32\Printing_Admin_Scripts\nl-nl\prncnfg.vbs" -t  -p "HP OfficeJet One" +workoffline
cscript "C:\Windows\System32\Printing_Admin_Scripts\nl-nl\prncnfg.vbs" -t  -p "HP OfficeJet Two" +workoffline
this 5 total printers

Then start the job by setting the first printer on line
 cscript "C:\Windows\System32\Printing_Admin_Scripts\nl-nl\prncnfg.vbs" -t  -p "HP OfficeJet One" -workoffline
Start printwork for this one

Now before turning next printer on line I must know that spooler for this first Job is empy at printer
then next job , etc.
0
I am trying to loop through a spreadsheet and copy every 5th row of a sheet into multiple new worksheets. Basically every 5 rows of data should be placed into a new worksheet. The code I am trying to modify to suit my purposes is

Option Explicit

Sub loopTest()
Dim hdr As Range 'header range
Dim dta As Range 'data range
Dim cl As Integer 'copy line
Dim ns As Excel.Worksheet

Set hdr = Excel.Worksheets(1).Range("A2:Q2") 'set this range for what ever range your headers are on
cl = 3 'set this value for what ever row your data starts on
Do While Excel.Worksheets(1).Range(Cells(cl, 1), Cells(cl, 1)).Value <> "" 'this stops the loop when there are no more records
Set dta = Excel.Worksheets(1).Range(Cells(cl, 1), Cells(cl + 2, 17)) 'this sets the data range change the number 3 to how ever many columns there are in your dataset
Set ns = Excel.Worksheets.Add(, ActiveSheet) 'this sets the new sheet to the ns (new sheet = ns ) variable
hdr.Copy
ns.Range("A1").PasteSpecial xlPasteAll
dta.Copy
ns.Range("A2").PasteSpecial xlPasteAll
cl = cl + 5
Loop

End Sub

Open in new window


I currently get an error on the line:
Do While Excel.Worksheets(1).Range(Cells(cl, 1), Cells(cl, 1)).Value <> "" 'this stops the loop when there are no more records

Open in new window


The error I am receiving is Application-defined or object-defined error. I am unsure how to interpret this error.

testworkbook with the code and error is attached.
0
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
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

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.