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

I am working on a large VB6 project.  I am using Windows XP  as the development environment.  For various reasons, I moved had to a new Windows XP machine.  I have everything set up the same as the old machine (Win-XP SP3, VB6 SP-6 etc).  My program needs connects to an SQL database.  I have all the same references selected as on the old machine, however for some reason my connection to the Microsoft ActiveX Data Objects Recordset 2.8 Library isn't "connected".  I get a debug error the first time I use ADODB as in:
Set rsTable as ADODB.Recordset

Open in new window

There is no intellisense associated with ADODB.  I have the Microsoft ActiveX Data Objects Recordset 2.8 Library selected in the References.  I have reinstalled the MDAC28SDK.  I have also re-registered the MSADOR15.DLL file.

The program will run on the machine, connect to the SQL etc fine when run from the .EXE, but won't run in the development environment.

Anyone have any ideas about this?
thanks in advance
Richard
0
The Ultimate Tool Kit for Technolgy Solution Provi
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Hi,

This is an extension to previous post: VB6 - Duplicate MSHFlexgrid1 rows if

The code provided by MartinLiss was working perfectly.

Now, if facing a problem where 3 columns can have multiple values separated by a comma ",".

For each of those rows, it should be duplicated so that i can have a sample of each scenarios possible.

duplicates-based-on-3-columns.jpg
How can i do that?

Thank you foe your help.
VB6---Duplicate-rows.zip
0
Hi,

I am currently using the following code to display a form with rounded windows. Issue is how to make it run in 64-bit.

Thanks
Option Explicit

' Region API functins Requires Windows NT 3.1 or later; Requires Windows 95 or later

Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Dim FrmWndh  As Long
Sub SetWindowShape(ByVal hWnd As Long)

    Dim lpRect As RECT
    Dim lFrmWidth As Long, lFrmHeight As Long
    Dim hRgn As Long
    GetWindowRect hWnd, lpRect
    lFrmWidth = lpRect.Right -

Open in new window

0
Hi Experts,

I have the function below that downloads files from a FTP server.

Option Explicit
 
Sub Example()
 
    Dim mySession As New Session
    
    ' Enable custom error handling
    On Error Resume Next
    
    Upload mySession
    
    ' Query for errors
    If Err.Number <> 0 Then
        MsgBox "Error: " & Err.Description
 
        ' Clear the error
        Err.Clear
    End If
     
    ' Disconnect, clean up
    mySession.Dispose
     
    ' Restore default error handling
    On Error GoTo 0
    
End Sub

Private Sub Download(ByRef mySession As Session)
 
    ' Setup session options
    Dim mySessionOptions As New SessionOptions
    With mySessionOptions
        .Protocol = Protocol_Sftp
        .HostName = "example.com"
        .UserName = "user"
        .Password = "mypassword"
        .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
    End With
    
    ' Connect
    mySession.Open mySessionOptions
    
    ' Upload files
    Dim myTransferOptions As New TransferOptions
    myTransferOptions.TransferMode = TransferMode_Binary
     
    Dim transferResult As TransferOperationResult
    Set transferResult = _
        mySession.GetFiles("/home/user/*", "H:\FTP\", False, myTransferOptions)
     
    ' Throw on any error
    transferResult.Check
     
    ' Display results
    Dim transfer As TransferEventArgs
    For Each transfer In transferResult.Transfers
        MsgBox "Download of " & transfer.Filename & " 

Open in new window

0
Hi,
I have this MSFlexgrid1 that can have up to 50000 rows of data.

In column 4 called "Test5" in attached project, i can have values separated by a comma ",".

What i would like to do is to duplicate the rows and just keep one value per row.



Ex:

It i have 3 values separated by a comma, it would duplicate 2 extra rows with all the same values in all columns but for the column 4, it will put a unique value per row.

How can i do that?.

Thank you for your help
0
I have been programming in VB6 for years.  I have a desire to begin programming in VB.NET.  With .NET would I be able to make my application usuable from a webpage?  The current program I have is written in VB6 and can only be used from a windows desktop.  Here is one of my forms below for registering individuals in VB6.  What is the fastest way to begin learning how to convert this code into VB.NET?  If I get the .NET software does it have the ability to convert and if it does, how well does it perform?

Thanks for answering my preliminary questions as I know I have a road ahead.

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset
conn.Open "Provider=sqloledb;Data Source=" & ConnectionIP & ",1433;Network Library=DBMSSOCN;Initial Catalog= " & CAPDB & "; User ID=xx;Password=xxxx"

   ' If Not AsNumbers(Me.Text19.Text) Then
   '     MsgBox "Please enter a valid address", vbOKOnly
   '     Exit Sub
   ' End If


If DTPicker1 = ServerTime Then
    MsgBox "You Need to enter a BirthDate", vbOKOnly
    Exit Sub
End If

If Val(Text6) <= 0 Then
    MsgBox "Your Birthdate is Incorrect.  Please adjust.", vbOKOnly
    Exit Sub
End If

If Text2 = "" Then
    MsgBox "You Need to enter a Last Name", vbOKOnly
    Exit Sub
End If

If Text3 = "" Then
    MsgBox "You Need to enter an First Name", vbOKOnly
    Exit Sub
End If

If Combo12 = "CCASP" Or Combo12 = "Scouting Network" Then
    If Combo6 = "" Then
    MsgBox "You Need to enter a Sub Group", vbOKOnly
    Exit Sub
  

Open in new window

0
We just upgraded to Exchange 2016 from Exchange 2010 and all of our CDO mail-enabled Classic ASP sites are no longer sending mail properly.  As far as I can tell the emails just end up in the BadMail folder on the webserver.  Any direction is most appreciated!  This is a time sensitive issue for us.

Example:

    Set iMsg = CreateObject("CDO.Message") 'calls CDO message COM object
    Set iConf = CreateObject("CDO.Configuration") 'calls CDO configuration COM object
    Set Flds = iConf.Fields
    Flds( "http://schemas.microsoft.com/cdo/configuration/sendusing") = 1 'tells cdo we're using the local smtp service
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "e:\inetpub\mailroot\pickup" 'verify that this path is correct
    Flds.Update 'updates CDO's configuration database
    Set iMsg.Configuration = iConf 'sets the configuration for the message
	
    iMsg.To = "yyyyy@thecenter.org"
    iMsg.CC = "zzzzz@thecenter.org"

    sEmailBody = "Please find the attached file for checks dated " & sCheckDate & vbcrlf & vbcrlf & sContent
    iMsg.AddAttachment "e:\Inetpub\wwwroot\CBCHECK\data\ARS311584621i.txt"
    
    iMsg.From = "webmaster@thecenter.org" 'must be "someone@domain.com"
    iMsg.Subject = "FE - CBCHECK - " & sCheckDate 
    iMsg.HTMLBody = sEmailBody

    iMsg.Send 'commands CDO to send the message

Open in new window


Thanks,
Andrew
0
I have the below VB Script a friend here helped create. There was one thing I'm trying to add to it to change it.
It forwards e-mail to selected recipients but what I'd want is that if there are no recipients that fit the criteria, to don't forward/send and instead move the item to a different folder called "Unprocessed".

Public Sub ForwardwithCC()
Dim strRecip As String
Dim objMsg, oMail As MailItem
Dim NS As NameSpace
Set NS = Application.GetNamespace("MAPI")
 
' For a reply or reply all, replace forward  with Reply or ReplyAll
Set objMsg = ActiveExplorer.Selection.Item(1).Forward
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
Set oMail = ActiveExplorer.Selection.Item(1)
 
On Error Resume Next
 
For Each Recipient In oMail.Recipients
If InStr(Recipient.Address, "@ourdomain.com") > 0 Or InStr(Recipient.Address, "ExchangeLabs") > 0 Then strRecip = Recipient.Address & ";" & strRecip

Next Recipient
 
objMsg.To = strRecip

  objMsg.Display
  
  ' objMsg.Send
  
oMail.Move NS.Folders("Personal Folders").Folders("_Processed")

  
Else
End If
 
Set objMsg = Nothing
End Sub

Open in new window

0
Help modify VB script to move the email I selected before forwarding to another folder after it's been forwarded?

I am trying to get this script that forwards an e-mail I selected before forwarding to move to a sub-folder of my inbox once it's been forwarded.

The following will forward the e-mail successfully accordingly, but doesn't move to a subfolder:

Public Sub ForwardwithCC()
Dim strRecip As String
Dim objMsg, oMail As MailItem
Dim NS As NameSpace
Set NS = Application.GetNamespace("MAPI")
 
' For a reply or reply all, replace forward  with Reply or ReplyAll
Set objMsg = ActiveExplorer.Selection.Item(1).Forward
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
Set oMail = ActiveExplorer.Selection.Item(1)
 
On Error Resume Next
 
' For Each Recipient In oMail.Recipients
' strRecip = Recipient.Address & ";" & strRecip
' Next Recipient

For Each Recipient In oMail.Recipients
If InStr(Recipient.Address, "@ourdomain.com") > 0 Or InStr(Recipient.Address, "ExchangeLabs") > 0 Then strRecip = Recipient.Address & ";" & strRecip

Next Recipient
 
objMsg.To = strRecip

  objMsg.Display
  
  ' objMsg.Send
  
oMail.Move NS.Folders("Personal Folders").Folders("_Processed")

  
Else
End If
 
Set objMsg = Nothing
End Sub

Open in new window

0
I have a vb6 application that creates a .csv file with several pieces of information.  One of the values that are populated in the file is an ID number and location number that are 8 and 5 digits, with leading zeros.  This is the problem that I have, when the file is created it is created correctly with the leading zeros, however, when it is opened in Excel the zeros are stripped off by Excel.  How can I ensure that when the file is opened in Excel that the values are there with the zeros.  

For example:

00000065 --> Shows in Excel as: 65 without the zeros.

In the code, I am currently using this: Format(.IDNum, "@@@@@@@@") and Format(.LocNum, "@@@@@").

Both of these open in Excel without the leading zeros.  I have also tried putting a colon in front of the "@" values, and this for some reason solves the problem in part as it opens in Excel as ":00000065", which is what I want, only without the colon.  Please advise.

aj85
0
Upgrade your Question Security!
LVL 12
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

I unfortunately have to use vbscript for a local Outlook solution that basically is forwarding e-mails one at a time to the original recipients in the e-mail, excluding the original sender.
However I'm looking to have this exclude any recipients as well that are not @ourdomain.com. Does anyone know how to do that with this pieced together script, or have a better approach?
Additionally, I am wanting to move the e-mail after it's been sent, to a separate folder called "Processed" in the sub-folder...

Public Sub ForwardwithCC()
Dim strRecip As String
Dim objMsg, oMail As MailItem
 
 
' For a reply or reply all, replace forward  with Reply or ReplyAll
Set objMsg = ActiveExplorer.Selection.Item(1).Forward
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
Set oMail = ActiveExplorer.Selection.Item(1)
 
On Error Resume Next
 
For Each Recipient In oMail.Recipients
strRecip = Recipient.Address & ";" & strRecip
Next Recipient
 
objMsg.To = strRecip
  objMsg.Display
  objMsg.Send
  
Else
End If
 
Set objMsg = Nothing
End Sub

Open in new window

0
I'm using the spread grid control
http://helpcentral.componentone.com/NetHelp/Spread8/WebSiteHelp/webframe.html

I have a sql server stored procedure that returns a recordset.
I am binding the recordset to the spread grid.

One of the columns from the stored procedure is a double data type that contain both negative and position decimals numbers like this -12.42 or 4.67

Right now the column is set on the grid like this.

The data displays just fine on this grid

        fpgrid1.Col = 2
        fpgrid1.Text = CDbl(CurrentRS!EmployeeHoursWorked)

There is just one problem though. When I click on the column header to sort Ascending the sorting is not working correctly because of the negative numbers.
If I click on the column header again it sorts the column Descending but again its not sorting correctly because of the negative numbers.

I know its the negative numbers because if I only put positive numbers in the table the stored procedure uses then the sort on this column works fine.

Can I do a type conversion on this grid column so the negative numbers get sorted correctly?
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/functions/type-conversion-functions

or

Anyone know why the negative numbers aren't getting sorted correctly?
0
I have created an ASP.NET project (VB) with the default setup.
Now I want to link this to the SQL server installed in my laptop.
How do I do that?
Here is the connection string as of now.
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApp2-20180726120151.mdf;Initial Catalog=aspnet-WebApp2-20180726120151;Integrated Security=True"

Open in new window

Appreciate your help.
0
How to align center username and password  in login page ASP.net with VB.
I am new to asp.net/web app.

Appreciate your help.
0
Dear All,

I have huge dataset, over 12,000 rows, This comes from another database. I need to write a code or a formula so that for the Actual Cost Column and Estimated Cost column on every project so I can automatically see what was the actual cost of each project (if any) and planned cost of each project (if any).

The problem is each project has its sub-items. Everytime we have an asteric thats indicates this is start of the costs for the new project.

I have attached an example, the Ideal Solution tab has the solution and the way i want this to look. I will really appreciate if anyone can help me with this.

Thanks.
ESTIMATED-VS-ACTUAL.xlsx
0
Hi Experts,
I have following code working perfectly fine in Excel, however in Access it gives me an error Object doesn't support this property or method.
Both applications have same references.
      Dim patient As New Dictionary

                              patient(fieldName) = fieldValue

Open in new window


here is the class reference
Private Sub Class_Initialize()
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
    Set dict_pKeyValues = New Collection

    Erase dict_pKeys
    Erase dict_pItems
    Set dict_pObjectKeys = New Collection
#Else
    Set dict_pDictionary = CreateObject("Scripting.Dictionary")
#End If
End Sub

Private Sub Class_Terminate()
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
    Set dict_pKeyValues = Nothing
    Set dict_pObjectKeys = Nothing
#Else
    Set dict_pDictionary = Nothing
#End If
End Sub

Open in new window


Any idea what could be the culprit?

Thanks in advance.
0
Hi Experts,
I have this question after solving the following..
https://www.experts-exchange.com/questions/29108803/Script-to-read-all-files-of-specific-folder.html#acceptAnswerByMember
In that question I got a script how to count all records of files in one folder.
However now I need to know from that count how many are under one specific category.
Therefore I thought the best way would be to concatenate all files into one, just ignoring the headers.
And from there I will link to MS Access and get the results from a query.
Anyone has either a script for that or another way to accomplish the task?
Thanks in advance.
0
Hi Experts,
I am looking for a script that will read all files of a specific folder (.txt,.csv) and count how many records they're in total.
all files have fields header, however some files only contains the header and should not be count.
Thanks in advance.
0
Hi, cannot use "line input #n, string.variable" anymore to read a text file line by line in VB 2010. There are several methods, none of which seem to work including the below.
Can you suggest a simple method that does work.

The below when debug mode was started did nothing. The text file had three lines in it, "line 1", "Line 2" & "Line 3".

Imports System
Imports System.IO
Imports System.Text
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fileReader As System.IO.StreamReader
        fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\myfiles\test.txt")
        Dim stringReader As String
        stringReader = fileReader.ReadLine()
        MsgBox("The first line of the file is " & stringReader)
    End Sub
End Class
0
Cloud Class® Course: Python 3 Fundamentals
LVL 12
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

I need to call a userform sub e.g MyControl_Click where the userform will change at run time. I do have a variable which contains the userform object, but I have not found a way to execeute the  above sub.

'**** get the userform object, e.g.
set myUserForm = Userforms(0)

'***** Call sub in the userform
call myUserform.MyControl_Click

throws a run-time error '438' - Object does not support this property or method, even when MyControl_Click is defined as public sub
0
I have the following code which is working perfectly:

Public Sub MakeThisConfidential()
Application.ActiveInspector.CurrentItem.Sensitivity = olConfidential
Application.ActiveInspector.CurrentItem.Save
' MyMsg = MsgBox(Prompt, 0, "This message has been marked Confidential and will be encrypted by Fusemail")
MyMsg = MsgBox("Click OK to accept status" & vbCrLf & "This will encrypt the Current Message using fusemail", 0, "This message has been marked Confidential")
End Sub

Sub ToggleSensitivity()
    If ActiveInspector.CurrentItem.Sensitivity = olConfidential Then
        ActiveInspector.CurrentItem.Sensitivity = olNormal
        MyMsg = MsgBox("Click OK to accept status" & vbCrLf & "This will NOT encrypt the Current Message using fusemail", 0, "This message has been marked Normal")
    Else
        ActiveInspector.CurrentItem.Sensitivity = olConfidential
        MyMsg = MsgBox("Click OK to accept status" & vbCrLf & "This will encrypt the Current Message using fusemail", 0, "This message has been marked as Confidential")
    End If
End Sub

Open in new window


I have attached it to 2 separate buttons
I want to be able to run the macros and change the current button image. The image is added by the outlook interface:
In the New Mail window:
File - Options - Customise Ribbon - Main Tabs - New Mail Message
There is a group in here which has buttons with the macro's attached
0
Hello,
I have an application that is connecting to a board via a COM port.

I wrote the following function to open/close the port:
static public bool ConnectEMR4(string portID, string strCommand)
        {
            SerialPort mySerialPort = new SerialPort( portID, 9600,Parity.None,8,StopBits.One);
            
            try
            {

                // Create random data to write to the stream.
                byte[] dataArray = new byte[25];
                new Random().NextBytes(dataArray);

                mySerialPort.Open();

                mySerialPort.Write(dataArray, 0, dataArray.Count());

                mySerialPort.Close();
                MessageBox.Show("Connection successful");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return true;
        }

Open in new window

The problem I have is that I am trying to convert from a VB6 app to C# version.
My exposure to the COM Devices is minimal. The OBC command needs to combined a checksum added.

A VB6 version that I need to convert to C# would be these module:

'******************************************************************************
Attribute VB_Name = "modCRC"
Option Explicit

'******************************************************************************
'Procedure Name             :  CalcCRC()
'Procedure definition       :  Calculates the 2 Byte CCITT CRC-16 Checksum
'Description of Arguments   :  String
'Values 

Open in new window

0
Hi all
I want to combine 3 sheet change events in to one macro. With the help from this site, I have a macro with two change events. I want to add one more in to the existing one. The current code is
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim cell As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error GoTo Skip
If Not Intersect(Target, Range("C6:C3000")) Is Nothing Then
    For Each cell In Target.Columns(1).Cells
        r = cell.Row
        If Cells(r, "C") <> "" Then
            If Cells(r, "P") = "" Then
                Cells(r, "P").NumberFormat = "dd/mm/yyyy"
                Cells(r, "P") = Now
            End If
        End If
    Next cell
ElseIf Not Intersect(Target, Range("AB6:AB3000")) Is Nothing Then
    If Target <> "" Then
        If LCase(Target.Value) = "completed" Then
            Target.EntireRow.Hidden = True
        End If
    End If
End If
Skip:
Application.EnableEvents = True
End Sub

Open in new window


My new requirement is to add the following code into the existing one

 If Cells(r, "AB") <> "Allocated back to TL/Site" Then
            If Cells(r, "W") = "" Then
                Cells(r, "W").NumberFormat = "dd/mm/yyyy"
                Cells(r, "W") = Now

Open in new window


Your thoughts please

Regards
0
Hi, I am getting a Macro Error "Error in Loading DLL" in my Excel. I go to "References" and it says "UNSAVED: VBA Project". How can I fix this?
0
Having issue with code.

I am attaching 2 files here. One file have 2 Tabs the other one have 3 tabs. I am having issue with 3 tabs file. Flag are not generate from database tab for both square and round tab. Previously i am having both square and round flag in one tab with different columns but now i have separated them into 2 Tab. Its not working right now. Can someone please help me, also i am trying to add one button (select & copy) control which works something like that  we can select no. of flag and copy those flags.
Flag_Square---Round-Tab-wise.xlsm
Flag_Square-round.xlsm
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.