473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

this C# code in VB?

I have this code snippet in C# that I have to convert to VB

object o = null;
if (mode == PageTrackingMode.ByApplication) {
o = Page.Application[HitsKey];
}
else if (mode == PageTrackingMode.BySession) {
o = Page.Session[HitsKey];
}

In most of the C# code I see that is referring to Session and Application
variables I see that quotes are used i.e. Page.Session["HitsKey"] which
would translate to Page.Session("HitsKey") in VB. But the code above is
using the brackets without the quotes. What does that mean and how would
that translate to VB?
Thanks,
G
Nov 21 '05 #1
7 971
G Dean Blake wrote:
I have this code snippet in C# that I have to convert to VB

object o = null;
if (mode == PageTrackingMode.ByApplication) {
o = Page.Application[HitsKey];
}
else if (mode == PageTrackingMode.BySession) {
o = Page.Session[HitsKey];
}

In most of the C# code I see that is referring to Session and Application
variables I see that quotes are used i.e. Page.Session["HitsKey"] which
would translate to Page.Session("HitsKey") in VB. But the code above is
using the brackets without the quotes. What does that mean and how would
that translate to VB?
Thanks,
G

Woudln't that simply mean that HitsKey is a string variable or constant
defined someplace else?

Greg
Nov 21 '05 #2
Yes, HitsKey must be defined elsewhere. Here's the conversion.

Dim o As Object = Nothing
If mode = PageTrackingMode.ByApplication Then
o = Page.Application(HitsKey)
ElseIf mode = PageTrackingMode.BySession Then
o = Page.Session(HitsKey)
End If

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
G Dean Blake wrote:
I have this code snippet in C# that I have to convert to VB

object o = null;
if (mode == PageTrackingMode.ByApplication) {
o = Page.Application[HitsKey];
}
else if (mode == PageTrackingMode.BySession) {
o = Page.Session[HitsKey];
}

In most of the C# code I see that is referring to Session and Application
variables I see that quotes are used i.e. Page.Session["HitsKey"] which
would translate to Page.Session("HitsKey") in VB. But the code above is
using the brackets without the quotes. What does that mean and how would
that translate to VB?
Thanks,
G

Woudln't that simply mean that HitsKey is a string variable or constant
defined someplace else?

Greg

Nov 21 '05 #3
This code is actually inside a servercontrol where there is a property named
HitsKey but also there is code using a session and application variable
named "HitsKey". What I don't understand is why if they simply want to
refer to the property why not just say HitsKey instead of
Page.Session[HitsKey] (I don't know why they chose to name a session
variable and a property by the same name.) It's actually code from a book
on writing servercontrols.
Thanks,
G

"Russell Jones" <ar**@nospam.northstate.net> wrote in message
news:ub**************@TK2MSFTNGP15.phx.gbl...
Yes, HitsKey must be defined elsewhere. Here's the conversion.

Dim o As Object = Nothing
If mode = PageTrackingMode.ByApplication Then
o = Page.Application(HitsKey)
ElseIf mode = PageTrackingMode.BySession Then
o = Page.Session(HitsKey)
End If

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
G Dean Blake wrote:
I have this code snippet in C# that I have to convert to VB

object o = null;
if (mode == PageTrackingMode.ByApplication) {
o = Page.Application[HitsKey];
}
else if (mode == PageTrackingMode.BySession) {
o = Page.Session[HitsKey];
}

In most of the C# code I see that is referring to Session and
Application variables I see that quotes are used i.e.
Page.Session["HitsKey"] which would translate to Page.Session("HitsKey")
in VB. But the code above is using the brackets without the quotes.
What does that mean and how would that translate to VB?
Thanks,
G

Woudln't that simply mean that HitsKey is a string variable or constant
defined someplace else?

Greg


Nov 21 '05 #4
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> schrieb:
I have this code snippet in C# that I have to convert to VB

object o = null;
if (mode == PageTrackingMode.ByApplication) {
o = Page.Application[HitsKey];
}
else if (mode == PageTrackingMode.BySession) {
o = Page.Session[HitsKey];
}

In most of the C# code I see that is referring to Session and Application
variables I see that quotes are used i.e. Page.Session["HitsKey"] which
would translate to Page.Session("HitsKey") in VB. But the code above is
using the brackets without the quotes. What does that mean and how would
that translate to VB?


Woudln't that simply mean that HitsKey is a string variable or constant
defined someplace else?


ACK, but not necessarily a string...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

"G Dean Blake" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This code is actually inside a servercontrol where there is a property named HitsKey but also there is code using a session and application variable
named "HitsKey". What I don't understand is why if they simply want to
refer to the property why not just say HitsKey instead of
Page.Session[HitsKey] (I don't know why they chose to name a session
variable and a property by the same name.) It's actually code from a book on writing servercontrols.
Thanks,
G

You've kinda answered your own question there G.
They want to refer to the session(HitsKey) not the server control property
HitsKey that contains this code.
If they just used HitsKey then they would get a reference to the Propertry
not the session var.

Richard
Nov 21 '05 #6
But... if they want to refer to the session variable they should use
Page.Session("HitsKey") with Quotes. if they want to refer to the property
they should just say HitsKey. I have always enclosed my session variables
in quotes when writing in VB. I guess I don't know the meaning when the
quotes are not used. am I making sense?

"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"G Dean Blake" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This code is actually inside a servercontrol where there is a property

named
HitsKey but also there is code using a session and application variable
named "HitsKey". What I don't understand is why if they simply want to
refer to the property why not just say HitsKey instead of
Page.Session[HitsKey] (I don't know why they chose to name a session
variable and a property by the same name.) It's actually code from a

book
on writing servercontrols.
Thanks,
G

You've kinda answered your own question there G.
They want to refer to the session(HitsKey) not the server control property
HitsKey that contains this code.
If they just used HitsKey then they would get a reference to the Propertry
not the session var.

Richard

Nov 21 '05 #7
Sounds like you can refer to your session variable in one of two ways:

Page.Session(HitsKey) or Page.Session("my_session_key") where
"my_session_key" is whatever string value that was assigned as the key.

For both of these to return the same session value then HitsKey must be
defined like so:

Dim HitsKey As String = "my_session_key"

Sounds like they made HitsKey a property value for the server control so
that somebody could set what that text value key should be. As opposed to
hard-coding it in the server control as (for example) "my_session_key".

They are trying to encapsulate the server control and hide all the messy
details. One of those details is the session key's name. But you can't
really fully encapsulate a session variable, because the rest of the program
still has access to your session and not just through your server control.

Am I making sense? Probably not. :^)

Greg
"G Dean Blake" <gb@nospam.com> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
But... if they want to refer to the session variable they should use
Page.Session("HitsKey") with Quotes. if they want to refer to the
property they should just say HitsKey. I have always enclosed my session
variables in quotes when writing in VB. I guess I don't know the meaning
when the quotes are not used. am I making sense?

"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"G Dean Blake" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This code is actually inside a servercontrol where there is a property

named
HitsKey but also there is code using a session and application variable
named "HitsKey". What I don't understand is why if they simply want to
refer to the property why not just say HitsKey instead of
Page.Session[HitsKey] (I don't know why they chose to name a session
variable and a property by the same name.) It's actually code from a

book
on writing servercontrols.
Thanks,
G

You've kinda answered your own question there G.
They want to refer to the session(HitsKey) not the server control
property
HitsKey that contains this code.
If they just used HitsKey then they would get a reference to the
Propertry
not the session var.

Richard


Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Harold Crump | last post by:
Greetings, I have a PHP/MySQL application that I am deploying at a client's. I am fairly certain that they will steal my source code and re-sell to other companies. I would like to somehow...
0
by: Rasmus Fogh | last post by:
Dear All, I need a way of writing strings or arbitrary Python code that will a) allow the strings to be read again unchanged (like repr) b) write multiline strings as multiline strings instead...
0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
8
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src = inspect.getsource(os) but there is no...
5
by: Sky Fly | last post by:
Hi, I know that when an .NET exe is run, the CLR loads the exe (along with dependent assemblies), compiles them to native code then runs the code. Assuming the assemblies are loaded from a...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
3
by: DPfan | last post by:
What's exactly the meaning of "code reuse" in C++? Why such kind of reuse have more advantages over the counterpart in other language like in C? How is "code reuse" realized in C++? By...
1
by: geek04 | last post by:
i'm using pro*c to precompile my c++ code which accesses oracle 9i database, i'm running a oracle 9i client on my system on compiling the c++ file (generated by pro*c)i'm getting following...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
6
by: Fuzzyman | last post by:
Hello all, I'm trying to extract the code object from a function, and exec it without explicitly passing parameters. The code object 'knows' it expects to receive paramaters. It's 'arg_count'...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.