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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constants 1

Status
Not open for further replies.

simoncpage

Programmer
Apr 4, 2002
256
GB
Hi all,

If I have the following constant

Public Const ABC as String

And I default ABC = "hello" but in my application I have an input box that accepts a new value and data type for ABC how can I make it so that if ABC is changed to ABC = 3.13 and Long how can I get this to write to the program so that you get

Public Const ABC as Long ??? after you close and reopen the program?

Any help again would be great thanks!

Simon
 
Const is for a varialbe that can't be changed. Try using:
Public ABC as String = "hello"


 
Try

Public Const ABC as Variant

If you are using Excel, the Excel specific InputBox (Application.InputBox) is more versatile than the regular Office InputBox

A.C.
 
so is there anyway of writing to a program to change the constant in there..?

If I use public ABC as string = "hello" and if I change the constant at run time it can change it then but it wont actually change the constant when I close and reopen the workbook - which is what I want to do!??
 
maybe you should consider saving the value in a custom document property

Code:
Option Explicit

Sub AddProperty()
  With ActiveWorkbook.CustomDocumentProperties
    .Add Name:="ABC", _
         LinkToContent:=False, _
         Type:=msoPropertyTypeString, _
         Value:="hello"
  End With
End Sub

Sub ModifyProperty()
  ActiveWorkbook.CustomDocumentProperties("ABC") = "hi"
End Sub

Sub ReadProperty()
  MsgBox ActiveWorkbook.CustomDocumentProperties("ABC")
End Sub
 
Ive come up with another option but that is an very interesting and useful way of updating constants and deserves a star

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top