Dim and set variable on same line

Is there a way to DIM a variable and set it on the same line?

For example:
Dim test as String = "Hello"

smithmrk
smithmrkAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you cannot initialize a variable outside a procedure.

what are you using the variable for?
possibly, you only want a constant?

Public Const IPAddress As String = "10.31.30.26"

If you want to be able to change it:


Private gIPAddress As String

Public property Get IPAddress as string
  If gIpAddress = empty
    gIpAddress = "10.31.30.26"
  end if
  IPAddress = gIpAddress
End property

public Property Let IPAddress ( nv as string )
  gIpAddress = nv
End Property
0
 
sirbountyCommented:
Dim test: test="Hello"
0
 
smithmrkAuthor Commented:
OK, I guess my real problem is that I'm trying to do this under the Option Explicit so the entire Module can use the same variable and its value.

What I'm trying to do is the variable IPAddress and set it, so all my connections us the same variable instead of having to set it within each function.

Thanks,
smithmrk
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in vb6 or lower:
Dim test as string: test="Hello"

in vb.net:

Dim test as string = "Hello"
0
 
sirbountyCommented:
Not sure I understand you there- why not make it a global variable?

[Public] Dim IPAddress As String
0
 
smithmrkAuthor Commented:
Public IPAddress As String: IPAddress = "10.31.30.26"

Error = Compile Error - Invalid outside procedure

???
0
 
sirbountyCommented:
vb6 or vb.net?
0
 
smithmrkAuthor Commented:
Public Const IPAddress As String = "10.31.30.26"

That was what I was looking for!!!!!!!!!!!!

Thanks so much!
smithmrk
0
 
sirbountyCommented:
Ouch. : P
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.