save last spot?

Discussion in 'AutoCAD' started by Jason Wilder, Apr 24, 2004.

  1. Jason Wilder

    Jason Wilder Guest

    I have a form that I created that uses a Tab Strip to switch between
    different types of details that I want a drafter to insert in a drawing.

    Once they've selected the routine, I do a frmDetails.Hide, they place the
    detail on the sheet, then I have frmDetails.Show, so that they can insert
    other details as needed.

    How do I retain the last shown location both on the Tab Strip and the
    Listbox (where the files are listed), so that they don't have to hunt again
    for the next detail?
     
    Jason Wilder, Apr 24, 2004
    #1
  2. Jason Wilder

    A Seidel Guest

    Generally a form's state is retained between hide and show. Perhaps
    you want to save states between runtimes. I use the following method
    of saving a simple structured macro preference text file that is read
    and saved by the macro when it runs and closes out. This method is
    fast, easy to maintain, and easy to troubleshoot. Here is an example:

    Const PrefData = "brk2hidn.dat"
    Const PrefPath = "U:\" ' set this to the path were preferences will
    be stored
    ' Use Preferences.Files.TempFilePath to use AutoCAD's local temppath
    for prefpath instead

    A typical userform init:

    Private Sub UserForm_Initialize()
    GetPrefs
    Me.Caption = DlgTitle1
    If Res = 0 Then Res = DefRes
    FillLayerBox
    FillLTypeBox
    FillColorBox
    SetLayerBoxIndex (HidLayer)
    SetLTypeBoxIndex (HidLinType)
    SetColorBoxIndex (HidColor)
    LastMiss = 0
    UpDateMissBox
    SetPrefs
    SetSize 0
    End Sub

    Typical getprefs and saveprefs:

    Sub GetPrefs()
    Dim MacroPref As String
    Dim x As Integer
    Dim stat As Integer
    On Error GoTo skip
    MacroPref = PrefPath & PrefData
    ReDim Favors(0 To 0)
    Open MacroPref For Input As #1
    Do While Not EOF(1) ' Loop until end of file.
    Input #1, Line
    Select Case Left(Line, 3)
    Case Is = "fx:" ' dialog left
    DlgLeft = Right(Line, Len(Line) - 3)
    Case Is = "fy:" ' dialog top
    DlgTop = Right(Line, Len(Line) - 3)
    Case Is = "rs:" ' resolution
    Res = Val(Right(Line, Len(Line) - 3))
    Case Is = "la:" ' resolution
    HidLayer = Right(Line, Len(Line) - 3)
    Case Is = "lt:" ' resolution
    HidLinType = Right(Line, Len(Line) - 3)
    Case Is = "co:" ' resolution
    HidColor = Right(Line, Len(Line) - 3)
    Case Is = "gd:" ' gap distance
    GapDist = Val(Right(Line, Len(Line) - 3))
    Case Is = "ug:" ' use gap distance
    UseGap = Right(Line, Len(Line) - 3)
    Case Is = "ul:" ' use layer
    UseLay = Right(Line, Len(Line) - 3)
    Case Is = "ut:" ' use linetype
    UseLineT = Right(Line, Len(Line) - 3)
    Case Is = "uc:" ' use color
    UseColor = Right(Line, Len(Line) - 3)
    Case Is = "kt:" ' keep trucking
    KeepTruckn = Right(Line, Len(Line) - 3)
    Case Is = "tm:" ' Trim mode
    TrimMode = Right(Line, Len(Line) - 3)
    End Select
    Loop
    Close #1 ' Close file.
    skip:
    On Error GoTo 0
    End Sub

    Private Sub SavePrefs()
    Dim MacroPref As String
    Dim x As Integer
    On Error GoTo skip
    MacroPref = PrefPath & PrefData
    Close #1
    Open MacroPref For Output As #1
    Print #1, "This is the BREAK2HIDDEN.DVB preferences file. " &
    Issue
    On Error GoTo skip
    Print #1, "fy:"; DlgTop
    Print #1, "fx:"; DlgLeft
    Print #1, "rs:"; Res ' default resolution
    Print #1, "la:"; HidLayer ' default layer
    Print #1, "lt:"; HidLinType ' default linetype
    Print #1, "co:"; HidColor ' default color
    Print #1, "gd:"; GapDist ' gap distance
    Print #1, "ug:"; UseGap ' use gap distance
    Print #1, "ul:"; UseLay ' use layer
    Print #1, "ut:"; UseLineT ' use linetype
    Print #1, "uc:"; UseColor ' use color
    Print #1, "kt:"; KeepTruckn ' keep trucking mode
    Print #1, "tm:"; TrimMode ' trim mode
    skip:
    Close #1
    On Error GoTo 0
    End Sub

    Typical Userform Terminate

    Private Sub UserForm_Terminate()
    SavePrefs
    End Sub
     
    A Seidel, Apr 26, 2004
    #2
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.