|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Value of Constant name in String variable
In my program I have a string variable containing the name of a constant
myStringVar = "xlLineMarkersStacked" Q: How do I get the actual value of that constant (66 in this case)? |
|
#2
|
||||
|
||||
|
is xlLineMarkersStacked that name of your constant? if so, then you don't need the quotes, just do
Code:
myStringVar=str(xlLineMarkersStacked)
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
I'll try to explain in a bit more detail:
xlLineMarkersStacked is an Excel constant which displays a specific type of line chart. I'm writing a small charting tool in which the user can choose the linestyle he wants: Line, Stacked Line, or 100% Stacked Line. Each of these lines can be displayed with or without markers. Hence, on my userform are three radiobuttons and one checkbox. Based on the user's selection I need to establish which of the following constants I need: xlLine (4) xlLineStacked (63) xlLineStacked100 (64) xlLineMarkers (65) xlLineMarkersStacked (66) xlLineMarkersStacked100 (67) (In brackets are the actual values of these constants). Because of the non-contiguous numbering, and the structured naming, I thought it would be handier to go by names instead of by numbers. My code looks like this: 'Get the selected line type strLineType = "xlLine" if chkMarkers = True then strLineType = strLineType & "Markers" if optLineStacked = True then strLineType = strLineType & "Stacked" elseif optLineStacked100 = True then strLineType = strLineType & "Stacked100" end if 'Get the constant value intLineType = ????(strLineType) This is where I get stuck: I have the name of an Excel constant stored in a string variable without any relation to the actual constant (hence CInt / CLng won't do). How do I get to the actual constant value? If my string variable constains "xlLineMarkersStacked", how do I get to integer value 66? |
|
#4
|
|||
|
|||
|
I think u should only use "select...case..." statement:
dim strLineType as string dim intLineType as integer select strLineType case "xlLine" intLineType=4 case "xlLineStacked" intLineType=63 .... End select I think it is impossible that u want to compare between variable and constant.. |
|
#5
|
||||
|
||||
|
can you do a select case statement.. something like this?
Code:
Private Sub Form_Load()
Dim strYourElement As String
Dim intSelection As Integer
strYourElement = InputBox("Enter Your value Here", "Value")
Select Case strYourElement
Case "xlLineMarkersStacked"
intSelection = 66
Case Else
intSelection = 943
End Select
MsgBox intSelection
End Sub
I just tried this on a blank form, and it did display a value of 66. I hope this helps |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Value of Constant name in String variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|