Alternative to inet & webbrowser control to retrieve HTML only? - vb6

I would like to download only the HTML code in my VB6 program.
Webbrowser control is good but it hangs and also it has issues such as needing to disable the JavaScript, pic, etc in order to get just the HTML
The Inet control is better, but it is "buggy"
Is there any other control ?

If you only want to download the HTML of a page, you can easily use Winsock control.
Private Sub Form_Load()
Winsock1.Connect "stackoverflow.com", 80
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub Winsock1_Connect()
Winsock1.SendData "GET /questions/8624871/vb6-alternative-to-inet-webbrowser-control HTTP/1.1" & vbCrLf & "Host: stackoverflow.com" & vbCrLf & vbCrLf
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s, vbString
RichTextBox1.Text = RichTextBox1.Text & s
End Sub

My suggestion is to host WebKit.NET in your VB 6 application just like you would any other .NET control.
Although it is a .NET control, which means that it won't work natively out-of-the-box with VB 6, it is possible to use controls developed in .NET with a VB 6 application. Microsoft provides the Interop Forms Toolkit as an interoperability mechanism between the two languages.
Essentially, you'll use one of the .NET languages (it doesn't have to be VB.NET; you could also use C#) to create an ActiveX DLL containing your UserControl and register it for COM interop. Then, you can add this ActiveX control to your VB 6 project and hook up to handle the events it raises.
You can find a more complete sample on how to do this here on CodeProject, or here on CodeGuru.
Indeed this approach is not going to be trivial to implement. But I suspect that it's your only alternative to the bundled WebBrowser control, considering that IE was pretty much dominating the browser market back when VB 6 was popular and no one is developing new controls for VB 6 anymore.

You don't need API calls, you don't need WinSock, you don't need Inet, you don't need WebKit interop. Just do it the easy way, using native VB6 code. Here's an excellent article by Karl Peterson with sample code.

This is good code, and it works even in ASP, VBScript.
Function GetHTMLCode(strURL) As String
Dim strReturn ' As String
Dim objHTTP ' As MSXML.XMLHTTPRequest
If Len(strURL)=0 Then EXIT FUNCTION
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.open "GET", strURL,False
objHTTP.send 'Get it.
strReturn =objHTTP.responseText
Set objHTTP = Nothing
GetHTMLCode = strReturn
End Function
Now call this function like this (always write with protocol):
Msgbox GetHTMLCode("http://www.stackoverflow.com")

Related

How to list all Bluetooth devices in Visual Basic (vb.net) on WINDOWS

I am getting so mad at trying to find out a working example. YES, I am new to VB.Net. I was used with VB6, long way back. I just cannot get that thing to do what I want.
My project: I am totally tired of using Steam and other 3rd party apps that require pairing and very hard or long configurations to emulate an XBox controller from a non-Xinput controller. I baught a RegeMoudal Pro Controller and OF COURSE, Windows does NOT read any button entries and I need to use a third party app. The problem with the apps is that they require too much configuration. I just want to transfer the controller's input into a Windows detectable input, that's it.
So, since I cannot go in FASM to do such a complexe project without breaking my head everywhere, I chose to go with the easy way, old school. I spent 2 days just figuring out that I had to reference UWP and a bunch of other things. Now, I said to myself, if I only get AT LEAST the list of devices connected on Bluetooth, I'll be able to start somewhere but nope. No matter what I find, noone has any Visual Basic codes to use in a clean way asside from very complexe code I barely understand.
Can someone please help me AT LEAST find out HOW to list all devices on Bluetooth. I do not care if they are connected or not, I just want to list the devices.
Here is what I got. A simple form with 1 single button and 1 single Label. I know, this just has a bunch of errors.
Imports Windows.Devices.Bluetooth
Imports Windows.Devices.Enumeration
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
Dim odevices = New DevicePicker
Dim odev As DeviceInformation
Dim sdevices As String
sdevices = ""
LabRes.Text = "Searching devices..."
For Each odev In odevices
sdevices = sdevices & Chr(13) & odev.GetType.Name
Next
End Sub
End Class
I just cannot figure out how to make this simple task so a gentle help would be nice.
I got discouraged because Windows does NOT capture any input of my controller detected as a Bluetooth Pro Controller but a simple webpage does capture every single input so I am annoyed because I was waiting for this controller since a long time because the XBOX ONE controller had serious joystick issues and made me rage quit games because the joystick would give small taps backwards when releasing it so those Xbox controllers are now on my blacklist because even when Microsoft sent it back to me, it had the exact same issue so I got a refund.
Now, I want to create my own version of Pro Controller to Xbox Controller input app. And I am insisting, Visual Basic code, not C++ or C#. And this is for WINDOWS, not android or any other systems. And refering to Microsoft's website to help does not either help because they give no samples in Visual Basic and I just don't understand the language they are using to explain everything, I'm just a simple person, oh, and the samples that can be taken need to be downloaded as project. I just want a sample code available neatly and easily without downloading anything.
So, after fideling so much with VB and trying to search. I finally found out how to list Bluetooth devices in Visual Basic (VB.Net).
FIRST of all, you NEED 32Feet.Net. I ran into the NuGet problem. I have absolutely NO clue what that is. After searching, I found out that nuGet packages can simply be unzipped using 7zip or other similar app. So here are the steps you need to do to prepare Visual Basic aka VB.Net to work with Bluetooth devices.
Go to 32Feet.Net's GitHub page here: https://github.com/inthehand/32feet
Download the "InTheHand.Net.Bluetooth - Bluetooth Classic" nuget package
Unzip the "nupkg" file in a folder of your choice
Open VB.Net
Navigate in the menus to "Project\Add a project reference..."
Click on the "Browse" button at the bottom of the project reference window
Browse in your newly downloaded and unziped nuget package folder under this path "runtimes\win\lib\netcoreapp#.#" and select the DLL "InTheHand.Net.Bluetooth.dll"
NOW you will be able to use the bluetooth functions. Next, we need to import the functions so they can be available when you code so you need to put this line at the very beginning of your project:
Imports InTheHand.Net.Sockets
Now that this is done, you can list you bluetooth devices. I will explain how I did my sample window. I put 1 button, 1 label and 1 timer object. When changing a label following the mentionned solution above with "Application.DoEvents()" My label still did not change text. So I used an old VB6 trick with a timer. I simply disable a timer object and when clicking on the button, I enable this timer which performs the actions I want. 1 VERY and excessively IMPORTANT thing, once you have started your timer actions, immediately disable your timer before performing any tasks inside this timer or else your function will repeat at the speed of your timer ticks.
So this is my complete code which lists the names of the Bluetooth devices on y computer in Visual Basic (VB.Net).
Imports InTheHand.Net.Sockets
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
LabRes.Text = "Searching devices..."
TmrBTScan.Enabled = True
BouGetDev.Enabled = False
End Sub
Private Sub TmrBTScan_Tick(sender As Object, e As EventArgs) Handles TmrBTScan.Tick
Dim bt_client As BluetoothClient = New BluetoothClient()
Dim odevices As BluetoothDeviceInfo() = bt_client.DiscoverDevices().ToArray()
Dim odev As BluetoothDeviceInfo
Dim sdevices As String = ""
Dim schr = ""
TmrBTScan.Enabled = False
For Each odev In odevices
sdevices = sdevices & schr & odev.DeviceName
schr = Chr(10) & Chr(13)
Next
LabRes.Text = sdevices
BouGetDev.Enabled = True
End Sub
End Class
This should list the names of all the Bluetooth devices. At least, it worked on my end and I hope this can help others that are looking for very clear steps in what to download, what to install, what to get, where to navigate, which files and what lines to code. It really is hard to get full complete instructions so I hope this helps.
Thanks for those that helped me here. I had to do some deep search, but at least I can get started on my project now.
First please fix this bug
The button_Click Event runs on the UI thread.
LabRes.Text = "Searching devices..."
the user will not see this text until the method finnished.
add this
LabRes.Text = "Searching devices..."
application.doevents()
It allows the UI to update while running code.
To get bluetooth devices in range
Private Sub SurroundingSub()
Dim client As BluetoothClient = New BluetoothClient()
Dim items As List(Of String) = New List(Of String)()
Dim devices As BluetoothDeviceInfo() = client.DiscoverDevicesInRange()
For Each d As BluetoothDeviceInfo In devices
items.Add(d.DeviceName)
Next
End Sub

Error in webautomation using vb6 in windows 10

I am automating a website to fill login details. I have developed that app in vb6 and that was working greatly in windows xp, 7 and 8. Now it is giving error in Windows 10.
In windows 10 when I run the exe directly, the login details are not filling.(I get "OnQuit fired" message). However, when I run the exe as Administrator it works properly.
This is the vb6 code,
Private Sub Form_Load()
Set Web = New SHDocVw.InternetExplorer
Web.Visible = True
Web.Navigate "https://mytestingsite/login.html ", 8
End Sub
Private Sub Web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error GoTo aaa
'MsgBox " URL: " & URL
If URL = "https://mytestingsite/login.html" Then
Web.Document.getElementById("Login_userName").Value = "abcd"
Web.Document.getElementById("Login_userName").onchange
Web.Document.getElementById("Login_password").Value = "123456789"
Web.Document.getElementById("dateField").Value = "15/09/1954"
End If
Exit Sub
aaa:
MsgBox Err.Description & " URL: " & URL
End Sub
Private Sub Web_OnQuit()
MsgBox "OnQuit fired"
End Sub
My question is why run as administrator is required for simple web automation ?
Is it not possible to run application in standard user in Windows 10 ?
How to solve this problem ?
Please don’t suggest me to rebuild application in .net ( It will take lot of time to convert my application to .net)
quick solution to your problem would be to publish a manifest along with your .exe
described here:
How do I create a manifest file in Visual Basic 6.0?

vb6 can't open a connection obj that used to work perfectly

This code is in an ActiveX .dll. For a year this connection worked perfectly, now it doesn't. Here's the code:
Dim objConnection As ADODB.Connection
Dim objRs As ADODB.Recordset
Dim theConnectionStr As String
Dim SanMarDB As Databas
Dim SanMarRs As Recordse
.
.
.
Set objConnection = New ADODB.Connection
theConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & gProgramFilesPath & ";" & _
"Extended Properties='text;HDR=YES;FMT=Delimited;IMEX=1'"
objConnection.Open theConnectionStr
Here is my list of references in the .dll:
Visual Basic for Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures
Microsoft Scripting Runtime
Microsoft Excel 14.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 6.1 Library
Microsoft Data Formatting Object Library 6.0 (SP6)
Microsoft Shell Controls and Automation
I get one of two error messages. Here's the first
Invalid setting in Excel key of the Engines section of the Windows Registry.
Google pointed me to some reasons for this error message and I've checked the registry setting and it appears correct, CSVDelimited, no 5-char entries, etc.
The second error message is:
Object variable or With block variable not set
The thing that makes this particularly strange is that I have another dll that has exactly the same references and code and it works perfectly. (only some filenames are different).
Any thoughts? Thanks for helping me out with this.
-t
Something to at least try:
theConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='" & gProgramFilesPath & "';" & _
"Extended Properties='text;HDR=YES;FMT=Delimited;IMEX=1'"
I.e. use quotes (apostrophes above) around the value for Data Source in case of characters that disrupt connection string parsing.
Also, isn't IMEX only used with the Excel IISAM and not the Text and HTML IISAMs?
Mixing ADO and DAO in one program is odd, but hopefully unrelated.

VB6 code to find windows OS version

I am using OSVERSIONINFO to check the OS in my vb6 application. But i am not able differentiate between windows 7 and windows server 2008 R2 because they have same version number,dwMajorVersion and dwMinorVersion. So how to differentiate between these. I think it can be done in vb.net using some other method. But how it can be done in vb6?
As Xearinox noted in the above comment, OSVERSIONINFOEX returns more information.
In particular, you can examine wProductType to determine whether VER_NT_WORKSTATION (0x0000001) is set or not. If it is, the machine is running a client OS, otherwise, server.
The chart in the remarks section of the OSVERSIONINFO MSDN entry even has a column which points out detecting the various OS's using that struct item.
Right Click On Tool Bar > Components And Add > Microsoft SysControl 6.0.
Double Click The SysInfo Button to Add on Form and use this code
Private Sub Form_Load()
Dim HancyRockz as string
HancyRockz = "OsVersion :- " & SysInfo1.OSVersion & " / Built " & SysInfo1.OSBuild
Text1.Text=HancyRockz
End Sub

Is there any serial communication software for VB 6.0,?

I am compiling a VB 6 code which requires serial communication from ports. For performing serial communication, I need some software tool like SAX Commstudio Active X or MSComm.ocx. But the problem is I have downloaded Sax Commstudio Active X from the commstudio official website, but that was a trial version for 1 day only. then i tried to download the same software from
http://visualstudiogallery.msdn.microsoft.com/en-us/
But the link is unavailable.
Now I am really in a fix how to get any of the serial communication software which is compatiable with VB 6 code. It will be better if some one provide me the sax commstudio download link or nay serial communication software downalod link!
Regards
Asad
Adding the VB6 MSComm Control to your Toolbar
In the VB6 IDE, select menu item Project, then select Components. The Components dialog box will appear. On this dialog, in the Controls tab, check the box next to the item 'Microsoft Comm Control 6.0' and then click the OK button on the dialog. This will add the component to your toolbar.
It's been a while since I've used this control but maybe this article will help you get started:
Visual Basic: MSComm Control
If you Google mscomm you'll find many more articles.
add the mscomm control in the components tab : Project - Components - Microsoft Comm Control 6.0
then add the control to your form and use the following code to configure and open it :
with mscomm1
.settings = "9600,N,8,1"
.commport = 1
.portopen = true
end with 'mscomm1
to send something :
mscomm1.output = "output to send"
use the oncomm event to receive data :
private sub mscomm1_oncomm()
dim strinput as string
select case mscomm1.commevent
case comevreceive
strinput = mscomm1.input
processdata strinput 'process the data here
end select
end sub
(code is unchecked, just typed in, but i think it should work :))

Resources