检查有效的互联网连接 [英] Check for active internet connection

查看:94
本文介绍了检查有效的互联网连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写了一个小型应用程序,该应用程序可访问大量搜索网站并将结果保存在word文档中,该文档每天运行数百次.

Wrote a small app that accesses a bunch of search websites and puts the results in a word document, which gets run a few hundred times a day.

它将单个搜索结果保存在多个本地文件夹中,因此下次搜索这些单词时,它将在本地捕获它们,而无需再次加载网站.

It saves individual search results in a number of local folders so the next time those words are searched, it grabs them locally instead of loading the website again.

这工作正常-即使速度不快.令人们印象深刻的是,直到几周前,他们才通过手工加载六个不同的搜索网站,进行搜索,然后将结果复制并粘贴到Word文档中来手动完成此操作.

This works fine - even though it's not quick. People are impressed because until a few weeks ago they did this manually by literally loading up six different search websites, searching, and then copying and pasting the results in a word document.

但是,我们办公室的互联网不可靠,并且在最近半天一直处于关闭状态.这意味着大约有400个错误搜索已保存在本地文件夹中,并插入到最终文档中.

However, our Office's internet is unreliable, and has been down the last half a day. This has meant about 400 bad searches have been saved in the local folders, and inserted into the final documents.

当一个人正在搜索时,他们可以判断互联网是否已断开,以后再进行搜索.但是,显然,该应用程序无法识别,并且因为我没有使用API​​或其他任何东西,并且由于我限于使用VBA环境(甚至不允许使用MZ工具),所以我需要找到一些方法来在继续进行程序流程之前,请检查互联网是否正常运行,而不必依赖过多的引用,并且最好不要对"404未找到页面"进行屏幕抓取.

When a person was searching they could tell if the internet was broken and they would do their searches later. Obviously, though, this app can't tell, and because I'm not using APIs or anything, and because I am limited to using the VBA environment (I'm not even allowed MZ tools), I need to find some way to check that the internet is working before continuing with the program flow, without relying on too many references, and preferably without screenscraping for the phrase "404 Page Not Found".

我对VB不太熟悉,VBA在很多方面都使我失望,所以可能有一些简单的方法可以做到这一点,这就是为什么我在这里问.

I'm not very familiar with VB, and VBA is ruining me in so many ways, so there's probably some easy way to do this, which is why I'm asking here.

感谢任何帮助.

推荐答案

您可以使用MSXML库&使用XMLHttpRequest类进行检查

You could use MSXML library & use XMLHttpRequest class to check for things

例如

On Error Resume Next
Dim request As MSXML2.XMLHTTP60
request.Open "http://www.google.com"
request.Send
Msgbox request.Status

该状态将为您提供请求所发生事件的HTTP状态代码. 根据您的情况,您可能需要再做一些检查.

The status will give you HTTP Status code of what happened to the request. You might have to do some more checks, depending on your scenario.

希望有帮助.

这篇关于检查有效的互联网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆