469,890 Members | 1,409 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Declaring Variables

Hello,

I am using Visual Web Developer 2005 Express. I want to declare a varible,
using Visual Basic as the language and can't get anywhere. For example

Public Test1 as String

I'll get en error saying to change Public to Dim. When I do, it will say
that Test1 is an unused local variable.

Thanks for any help.

God Bless,

Mark A. Sam


Mar 11 '06 #1
6 3186

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
Hello,

I am using Visual Web Developer 2005 Express. I want to declare a
varible,
using Visual Basic as the language and can't get anywhere. For example

Public Test1 as String

I'll get en error saying to change Public to Dim. When I do, it will say
that Test1 is an unused local variable.

Thanks for any help.

God Bless,

Mark A. Sam

and it is unused until you use it somewhere in your code.

GalenS

Mar 12 '06 #2

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
Hello,

I am using Visual Web Developer 2005 Express. I want to declare a
varible,
using Visual Basic as the language and can't get anywhere. For example

Public Test1 as String

I'll get en error saying to change Public to Dim. When I do, it will say
that Test1 is an unused local variable.

Thanks for any help.

God Bless,

Mark A. Sam

Sounds like you are trying to declare a local variable, thus Public is not
an option.
You are also declaring a reference type (String), thus your declaration:

Dim Test1 as String

creates a String object variable that references nothing, hence the second
error.

Try something like this:

Dim xx As New String("THIS IS THE STRING")


Mar 12 '06 #3
Actually I'm just playing around trying to learn this stuff. I am
interested in Public variables, becuase I can see a use for them down the
road. Your example worked, but so should mine have worked. I followed the
example in Help. Do you know the syntax for declaring public variables? Do
I need to assign value to variables when they are declared?

Thanks.

Mark

Sounds like you are trying to declare a local variable, thus Public is not
an option.
You are also declaring a reference type (String), thus your declaration:

Dim Test1 as String

creates a String object variable that references nothing, hence the second
error.

Try something like this:

Dim xx As New String("THIS IS THE STRING")

Mar 12 '06 #4
Mark A. Sam <ms**@Plan-It-Earth.Net> wrote:
I am using Visual Web Developer 2005 Express. I want to declare a varible,
using Visual Basic as the language and can't get anywhere. For example

Public Test1 as String

I'll get en error saying to change Public to Dim. When I do, it will say
that Test1 is an unused local variable.


It sounds like you're putting that line of code inside a method, making
it a local variable. "Public" only makes sense for an instance or
shared variable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 12 '06 #5

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
Actually I'm just playing around trying to learn this stuff. I am
interested in Public variables, becuase I can see a use for them down the
road. Your example worked, but so should mine have worked. I followed
the example in Help. Do you know the syntax for declaring public
variables? Do I need to assign value to variables when they are declared?

Thanks.

Mark

To declare a public variable, do it within your class body, but outside any
code block.
Mar 12 '06 #6
Thanks. That works now. I thought I did that before without success.

Partial Class test

Inherits System.Web.UI.Page

Public variantTest As VariantType

Will this value be available from page to page?

"pvdg42" <pv****@newsgroups.nospam> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
Actually I'm just playing around trying to learn this stuff. I am
interested in Public variables, becuase I can see a use for them down the
road. Your example worked, but so should mine have worked. I followed
the example in Help. Do you know the syntax for declaring public
variables? Do I need to assign value to variables when they are
declared?

Thanks.

Mark

To declare a public variable, do it within your class body, but outside
any code block.

Mar 13 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Oliver Corona | last post: by
6 posts views Thread by Joe | last post: by
2 posts views Thread by ross.oneill | last post: by
1 post views Thread by ColinWard | last post: by
6 posts views Thread by =?Utf-8?B?QUw=?= | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.