Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable declaration

Status
Not open for further replies.

SlykFX

Programmer
Oct 12, 2002
76
GB
is it possible to assign a variable a value at declaration?

the main reason i would like to do this is im using user-defined types but would like each of them to start with preset values but cant use consts as they will change during the applications execution

im currently using a subroutine and passing each variable that uses the type but this is long-winded and id like a shorter way of doing things

any help much appreciated

I can't be bothered to have a sig!
 
is it possible to assign a variable a value at declaration?

im pretty sure the answer is no!

u can set up a generic type in the form load then just assign it to your new types in code

Private Type bobby
stringy As String
booly As Boolean
inty As Integer
doobly As Double
End Type

Private Sub Form_Load()
Dim Semp As bobby

Semp.stringy = "i am your god"
Semp.booly = True
Semp.inty = 28989
Semp.doobly = &H600000

End Sub

private sub SomeButton_click()

Dim arrayofsemp(19) As bobby

For i = 0 To 19
arrayofsemp(i) = Semp
Next i

end sub

hope that makes sense

good luck and merry christmas

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
To get the best response to a question, please check out FAQ222-2244 first
A General Guide To Excel in VB FAQ222-3383
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top