[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Dim and set variable on same line

Posted on 2007-04-02
9
Medium Priority
?
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 143

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

Author Comment

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

Error = Compile Error - Invalid outside procedure

???
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

656 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