passing "constants"

Discussion in 'AutoCAD' started by lorier, Aug 13, 2004.

  1. lorier

    lorier Guest

    hi,
    I'm trying to get something like this to work
    sub test(strConstant as string)
    MsgBox aPref.GetString(strConstant)
    end sub

    where it's expecting strConstant to be an integer
    any ideas?

    thx
     
    lorier, Aug 13, 2004
    #1
  2. I'm trying to get something like this to work
    Lets start fresh - what exactly are you trying to do??? If I understand,
    what you are asking is never going to happen. At the msgbox, strConstant
    will ALWAYS be a string because you have it declared as such within the
    parameter. If it wasn't a string, you'd error out in the calling portion:

    Dim iCntr As Integer
    Test iCntr '<---- will bomb

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 13, 2004
    #2
  3. lorier

    lorier Guest

    ugly I know, but this is what i ended up doing. The task was to take a list of constant names and get their values. e.g. string,alignment,,,,kconstantname. And then do vice versa to set them. Hope this helps someone else. Or if there's another way I look forward to hearing about it.


    Option Explicit
    Dim alignmentPref As AeccPreferencesAlignment
    Dim cogoPref As AeccPreferencesCogo
    Dim crosssectionPref As AeccPreferencesCrossSection
    Dim parcelPref As AeccPreferencesParcel
    Dim profilePref As AeccPreferencesProfile
    Dim surfacePref As AeccPreferencesSurface
    Dim objVB As VBE
    Dim objComponents As VBComponents
    Dim objComponent As VBComponent
    Dim objCM As CodeModule
    Dim XL As Object
    Dim xlSheet As Object
    Dim xlcurcell As Excel.Range
    Dim intConstant As Integer
    Sub getPreferences()

    Set alignmentPref = AeccApplication.ActiveProject.Preferences.Alignment
    Set cogoPref = AeccApplication.ActiveProject.Preferences.cogo
    Set crosssectionPref = AeccApplication.ActiveProject.Preferences.CrossSection
    Set parcelPref = AeccApplication.ActiveProject.Preferences.Parcel
    Set profilePref = AeccApplication.ActiveProject.Preferences.Profile
    Set surfacePref = AeccApplication.ActiveProject.Preferences.Surface
    Set XL = GetObject(, "Excel.Application")
    Set xlSheet = XL.ActiveWorkbook.ActiveSheet

    Set objVB = ThisDrawing.Application.VBE
    Set objComponents = objVB.ActiveVBProject.VBComponents
    Set objComponent = objComponents.Item("Preferences")
    Dim strCat As String
    Dim strType As String
    Dim strConst As String
    Dim strProgram As String
    Dim strBegin As String
    While XL.ActiveCell.text <> ""

    strCat = XL.ActiveCell.text
    XL.ActiveCell.offset(0, 1).Select
    strType = XL.ActiveCell.text
    XL.ActiveCell.offset(0, 1).Select
    strConst = XL.ActiveCell.text
    strProgram = strProgram & _
    "xl.activecell.formula = " _
    & strCat & "Pref.Get" & strType & "(" & strConst & ")" & vbCr & _
    "XL.ActiveCell.offset(1, 0).select" & vbCr

    'MsgBox strProgram
    XL.ActiveCell.offset(1, -2).Select
    Wend

    strBegin = _
    "Set alignmentPref = AeccApplication.ActiveProject.Preferences.Alignment" & vbCr & _
    "Set cogoPref = AeccApplication.ActiveProject.Preferences.cogo" & vbCr & _
    "Set crosssectionPref = AeccApplication.ActiveProject.Preferences.CrossSection" & vbCr & _
    "Set parcelPref = AeccApplication.ActiveProject.Preferences.Parcel" & vbCr & _
    "Set profilePref = AeccApplication.ActiveProject.Preferences.Profile" & vbCr & _
    "Set surfacePref = AeccApplication.ActiveProject.Preferences.Surface" & vbCr & _
    "Set XL = GetObject(, " & Chr(34) & "Excel.Application" & Chr(34) & ")" & vbCr & _
    "Set xlSheet = XL.ActiveWorkbook.ActiveSheet"

    objComponent.CodeModule.AddFromString ( _
    "Sub setConstInfo()" & vbCr & _
    strBegin & vbCr & strProgram & vbCr & _
    "end sub")

    End Sub
     
    lorier, Aug 13, 2004
    #3
  4. lorier

    Ed Jobe Guest

    May I ask what the purpose for the task is? In order to find another way, we
    need to know the why. The task you gave is not the real task, but an
    algorithm for solving some problem. What is the real problem? Are you trying
    to save some settings so that they can be restored at a later date?

    --
    ----
    Ed
    ----
    list of constant names and get their values. e.g.
    string,alignment,,,,kconstantname. And then do vice versa to set them.
    Hope this helps someone else. Or if there's another way I look forward to
    hearing about it.
    AeccApplication.ActiveProject.Preferences.CrossSection" & vbCr & _
     
    Ed Jobe, Aug 13, 2004
    #4
  5. lorier

    Mark Propst Guest

    If you have a known list of constants couldn't you use a select case
    statement?

    Function ReturnConstantFromString(sInput as string) as Integer (or long?)(or
    variant?)
    Select case sInput
    Case is = "vbConstant1"
    ReturnConstantFromString = vbConstant1
    Case etc
    End select
    End Function

    problems was how to see the current preference settings, modify them, and
    then feed the list back to autocad to set the preferences. Come to think of
    it, I might have tried cycling through the properties of the various
    objects, but i'm not sure how to do that either. To try and bw be more
    concise with my question:
    name (name of a constant) at run time?
     
    Mark Propst, Aug 14, 2004
    #5
  6. Ok :) Now I see what you are trying to do. Best answer is one you *might*
    not want to hear - kill the xls and use xml. With xml you can store the
    data types so when you read in a node like kSpiralType
    you'll get its value as an integer so you can read in the node - value
    combo and just set the variable, something like

    SetVariable(node) = value

    Obviously this is an oversimplification but thats what I'd do. After all,
    once you go xml, you'll never go back <vbg>

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 14, 2004
    #6
  7. lorier

    lorier Guest

    Thanks alot for your input Mike, I'll check it out.
     
    lorier, Aug 14, 2004
    #7
  8. I should have added that in order for your XML parser [reader for the XML
    file] to distingush between embedded datatypes you'll need to create either
    a DTD or XSLT which are xml files [templates] that descrbe what is inside
    the actual XML file. I am working on a tutorial for this, but its not there
    yet. There is a lot of info available on the net tho.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 14, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.