Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2003, 05:55 AM
Tall Arnie Tall Arnie is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 3 Tall Arnie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)?

Reply With Quote
  #2  
Old October 22nd, 2003, 08:15 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,179 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 3 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
  #3  
Old October 22nd, 2003, 08:45 AM
Tall Arnie Tall Arnie is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 3 Tall Arnie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old October 22nd, 2003, 10:18 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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..

Reply With Quote
  #5  
Old October 22nd, 2003, 10:19 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,179 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 3 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Value of Constant name in String variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT