首页
关于
Search
1
解决PyQt资源文件不存在的问题
361 阅读
2
VBA获取拼音缩写
323 阅读
3
欢迎使用 Typecho
317 阅读
4
VB.net使用Newtonsoft.JSON解析JSON
305 阅读
5
VB.net 获取网页源码
149 阅读
默认分类
Code
登录
Search
标签搜索
VB.net
Python
Qt
JSON
VBA
Excel
Hanse
累计撰写
10
篇文章
累计收到
0
条评论
首页
栏目
默认分类
Code
页面
关于
搜索到
10
篇与
的结果
2020-01-22
VB.net 获取网页源码
方法一Public Function getWebSource(ByVal url As String) As String Try Dim stream As IO.Stream = WebRequest.Create(url).GetResponse().GetResponseStream() Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8) Return sr.ReadToEnd() Catch ex As Exception Return "" 'Return ex.ToString() End Try End Function方法二节选自网络,实测较慢Public Function GetWebCode(ByVal strURL As String) As String Dim httpReq As System.Net.HttpWebRequest Dim httpResp As System.Net.HttpWebResponse Dim httpURL As New System.Uri(strURL) Dim ioS As System.IO.Stream, charSet As String, tCode As String Dim k() As Byte ReDim k(0) Dim dataQue As New Queue(Of Byte) httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest) Dim sTime As Date = CDate("1990-09-21 00:00:00") httpReq.IfModifiedSince = sTime httpReq.Method = "GET" httpReq.Timeout = 7000 Try httpResp = CType(httpReq.GetResponse(), HttpWebResponse) Catch Debug.Print("weberror") GetWebCode = "<title>no thing found</title>" : Exit Function End Try '以上为网络数据获取 ioS = CType(httpResp.GetResponseStream, Stream) Do While ioS.CanRead = True Try dataQue.Enqueue(ioS.ReadByte) Catch Debug.Print("read error") Exit Do End Try Loop ReDim k(dataQue.Count - 1) For j As Integer = 0 To dataQue.Count - 1 k(j) = dataQue.Dequeue Next '以上,为获取流中的的二进制数据 tCode = Encoding.GetEncoding("UTF-8").GetString(k) '获取特定编码下的情况,毕竟UTF-8支持英文正常的显示 charSet = Replace(GetByDiv2(tCode, "charset=", """"), """", "") '进行编码类型识别 '以上,获取编码类型 If charSet = "" Then 'defalt If httpResp.CharacterSet = "" Then tCode = Encoding.GetEncoding("UTF-8").GetString(k) Else tCode = Encoding.GetEncoding(httpResp.CharacterSet).GetString(k) End If Else tCode = Encoding.GetEncoding(charSet).GetString(k) End If Debug.Print(charSet) 'Stop '以上,按照获得的编码类型进行数据转换 '将得到的内容进行最后处理,比如判断是不是有出现字符串为空的情况 GetWebCode = tCode If tCode = "" Then GetWebCode = "<title>no thing found</title>" End Function Public Function GetByDiv2(ByVal code As String, ByVal divBegin As String, ByVal divEnd As String) '获取分隔符所夹的内容[完成,未测试] '仅用于获取编码数据 Dim lgStart As Integer Dim lens As Integer Dim lgEnd As Integer lens = Len(divBegin) If InStr(1, code, divBegin) = 0 Then GetByDiv2 = "" : Exit Function lgStart = InStr(1, code, divBegin) + CInt(lens) lgEnd = InStr(lgStart + 1, code, divEnd) If lgEnd = 0 Then GetByDiv2 = "" : Exit Function GetByDiv2 = Mid(code, lgStart, lgEnd - lgStart) End Function
2020年01月22日
149 阅读
0 评论
0 点赞
2019-10-05
VB.net 拖拽功能
摘自项目FXB:Private Sub MainForm_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop Dim Files(), Temp() As String Files = e.Data.GetData(DataFormats.FileDrop) Temp = Split(Files(0), ".") If UCase(Temp(UBound(Temp))) = "XLSX" Or UCase(Temp(UBound(Temp))) = "XLS" Then MsgBox(Files(0)) Else MsgBox("非Excel文件!", MsgBoxStyle.Exclamation) End If End Sub Private Sub MainForm_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then e.Effect = DragDropEffects.Link Else e.Effect = DragDropEffects.None End If End Sub
2019年10月05日
55 阅读
0 评论
0 点赞
2019-06-28
VB.net ListBox自绘(实现不同颜色字体等)
摘自网络:Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load SellList.DrawMode = DrawMode.OwnerDrawFixed SellList.Items.AddRange(New String() {"第一", "第二", "第三"}) End Sub Private Sub SellList_DrawItem(sender As Object, e As DrawItemEventArgs) Handles SellList.DrawItem 'Dim lb As ListBox = CType(sender, ListBox) If e.Index = -1 Then Return End If If e.Index = 2 Then e.Graphics.DrawString(SellList.Items(e.Index), SellList.Font, Brushes.Red, e.Bounds.X, e.Bounds.Y) Else e.Graphics.DrawString(SellList.Items(e.Index), SellList.Font, Brushes.Green, e.Bounds.X, e.Bounds.Y) End If End Sub
2019年06月28日
55 阅读
0 评论
0 点赞
2019-06-28
VB.net 数字千分符
摘自网络:Format(Text1.Text, "Standard")
2019年06月28日
58 阅读
0 评论
0 点赞
2019-04-02
VB.net 正则表达式
简单查找第一个匹配值Public Function getFirstReg(ByVal searchStr As String, ByVal regStr As String) As String Try Dim r As New Regex(regStr) Dim m As Match = r.Match(searchStr) If m.Success Then Return m.Value Else Return "" End If Catch ex As Exception Return "" End Try End Function替换字符Public Function regReplace(ByVal searchStr As String, ByVal replaceStr As String, ByVal regStr As String) As String Dim reg As New Regex(regStr) Dim result As String = reg.Replace(searchStr, replaceStr) Return result End Function
2019年04月02日
82 阅读
0 评论
0 点赞
1
2