Declaring Variables

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

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
 
Mark A. Sam said:
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
 
Mark A. Sam said:
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")
 
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
 
Mark A. Sam said:
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.
 
Mark A. Sam said:
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.
 
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?
 
Back
Top