声明一个案例列表在多个地方使用
我的页面中有以下代码,尽管案例数量要大得多,但工作正常。我需要在其他选择中使用完全相同的案例列表,但我不想在各处重复完全相同的代码。
我有这个:
Select Case Request.Cookies("LatestRefer").Value
Case "EZ12"
freeCallNumber = "0800 111 1111"
Case "EW56"
freeCallNumber = "0800 222 2222"
Case "AT34"
freeCallNumber = "0800 333 3333"
Case Else
freeCallNumber = "0800 444 4444"
End Select
我理想地想要这样的东西
Select Case Request.Cookies("cookie1").Value
myGlobalListOfCases()
End Select
Select Case Request.Cookies("cookie2").Value
myGlobalListOfCases()
End Select
Select Case Request.Cookies("cookie3").Value
myGlobalListOfCases()
End Select
有什么想法吗?
编辑:
Private Function getFreeCallNumber(ByVal value As String) As String
Select Case value
Case "EZ12"
Return "0800 111 1111"
Case Else
Return "0800 222 2222"
End Select
End Function
在 page_load 中:
If Not Request.Cookies("cookie1") is Nothing Then
freeCallnumber = Me.getFreeCallNumber(Request.Cookies("cookie1").Value)
Else
freeCallnumber = Me.getFreeCallNumber(Request.Cookies("cookie2").Value)
End If
这种方法可以工作,但有一个小问题。我必须加载页面两次才能更改电话号码(或者电话号码按上次加载时应有的方式显示)。希望这是有道理的......这是相当奇怪的行为。
I have the following code in my page which works fine although the number of cases is much much bigger. I need to use exactly the same list of cases in other selects but I don't want to have exactly the same code duplicate all over the place.
I have this:
Select Case Request.Cookies("LatestRefer").Value
Case "EZ12"
freeCallNumber = "0800 111 1111"
Case "EW56"
freeCallNumber = "0800 222 2222"
Case "AT34"
freeCallNumber = "0800 333 3333"
Case Else
freeCallNumber = "0800 444 4444"
End Select
I ideally want something like this
Select Case Request.Cookies("cookie1").Value
myGlobalListOfCases()
End Select
Select Case Request.Cookies("cookie2").Value
myGlobalListOfCases()
End Select
Select Case Request.Cookies("cookie3").Value
myGlobalListOfCases()
End Select
Any ideas?
EDIT:
Private Function getFreeCallNumber(ByVal value As String) As String
Select Case value
Case "EZ12"
Return "0800 111 1111"
Case Else
Return "0800 222 2222"
End Select
End Function
And in the page_load:
If Not Request.Cookies("cookie1") is Nothing Then
freeCallnumber = Me.getFreeCallNumber(Request.Cookies("cookie1").Value)
Else
freeCallnumber = Me.getFreeCallNumber(Request.Cookies("cookie2").Value)
End If
This kind of works but there's a slight problem. I have to load the page twice for the phone number to change (or the phone number appears as it should have done on the previous load). Hope this makes sense... it's fairly odd behaviour.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个方法:
调用它时:
我猜在VB.net中是这样的:
Create a method:
When calling it:
My guess that it's like this in VB.net:
您可以尝试Dictionary(Of TKey, TValue) 类
注意:是可序列化的:-Q
You can try the Dictionary(Of TKey, TValue) Class
Note: is is serializable :-Q