gpt4 book ai didi

vb.net - .ToString错误(vb.net)

转载 作者:行者123 更新时间:2023-12-02 11:04:48 25 4
gpt4 key购买 nike

由于某种原因,这对我不起作用,我不确定。我正在尝试为我的Web浏览器设置“设置主页”按钮,这是检查是否设置了页面,然后转到页面的代码:

    Dim HomepageInfo As String
If IO.File.Exists(Environment.SpecialFolder.ApplicationData & "\Homepage.Info") = True Then
HomepageInfo = IO.File.ReadAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info")
WebBrowser1.Url = HomepageInfo.ToString
Else
'Create a File with a Default Homepage (www.google.com)
IO.File.WriteAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info", "www.google.com")
End If

并且这显示为错误:HomepageInfo.ToString,错误是:“类型'String'的值不能转换为'System.Uri'。”

谢谢你的帮助!

最佳答案

WebBrowser.Url 属性接受uri对象而不是字符串:

Property Value Type: System.Uri A Uri representing the URL of the current document.



因此,您必须使用 Uri 类的实例:

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.



码:
Dim HomepageInfo As String
If IO.File.Exists(Environment.SpecialFolder.ApplicationData & "\Homepage.Info") = True Then
HomepageInfo = IO.File.ReadAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info")
WebBrowser1.Url = New Uri(HomepageInfo.ToString)
Else
'Create a File with a Default Homepage (www.google.com)
IO.File.WriteAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info", "www.google.com")
End If

关于vb.net - .ToString错误(vb.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19682260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com