Solved

Dim and set variable on same line

Posted on 2007-04-02
9
308 Views
Last Modified: 2008-02-01
Is there a way to DIM a variable and set it on the same line?

For example:
Dim test as String = "Hello"

smithmrk
0
Comment
Question by:smithmrk
  • 4
  • 3
  • 2
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18838811
Dim test: test="Hello"
0
 

Author Comment

by:smithmrk
ID: 18838842
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18838844
in vb6 or lower:
Dim test as string: test="Hello"

in vb.net:

Dim test as string = "Hello"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18838854
Not sure I understand you there- why not make it a global variable?

[Public] Dim IPAddress As String
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:smithmrk
ID: 18838920
Public IPAddress As String: IPAddress = "10.31.30.26"

Error = Compile Error - Invalid outside procedure

???
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18838968
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18838995
vb6 or vb.net?
0
 

Author Comment

by:smithmrk
ID: 18838998
Public Const IPAddress As String = "10.31.30.26"

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

Thanks so much!
smithmrk
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18839003
Ouch. : P
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now