我想使用发送到 SetSectorImage 子的 Sector 变量来命名正在更改的图像(图像确实已经存在于 Web 表单中,我只是在更改 URL)。谷歌搜索只让我在 MSDN 上找到一篇关于 CallByName 方法的文章,但我不知道它是否能在这种情况下工作,而且我不知道如何工作。
如果有帮助,这里是这篇文章:http: //msdn.microsoft.com/en-us/library/22x2chfx.aspx
Imports System
Imports System.IO
Public Class Launcher
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetSectorImage("Sector1")
SetSectorImage("Sector2")
SetSectorImage("Sector3")
End Sub
Sub SetSectorImage(Sector As String)
Dim SectorStatus As String
Try
Using Reader As New StreamReader(Sector + ".txt")
SectorStatus = Reader.ReadToEnd()
Reader.Close()
Sector_SHOULD_BE_USED_HERE.ImageUrl = ("~/Images/" + SectorStatus)
End Using
Catch ex As Exception
ErrorMessage.Text = ("There was an error reading the status of: " + Sector)
ErrorMessage.Visible = True
End Try
End Sub
End Class