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.

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
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
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

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.