SaveSetting

SaveSetting

Anonymous
Not applicable
573 Views
14 Replies
Message 1 of 15

SaveSetting

Anonymous
Not applicable
Can someone help pls. I wrote a macro for a family of parts and want to "savesetting" each part in the registry. Here are my subs. If I replace sfile in the UserForm_Initialize() and UserForm_Terminate() with "Part1" then this program works fine. Otherwise I got the erro msg (see att.) Option Explicit Dim sFile As String Private Sub cmdDataBase_Click() Dim oDoc As Inventor.Document Set oDoc = ThisApplication.ActiveDocument sFile = Right(oDoc.DisplayName, 13) MsgBox ("File Name is:" & sFile) oDoc.Update End Sub Private Sub UserForm_Initialize() chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, "ShowSlotAndCrimp", "true") End Sub Private Sub UserForm_Terminate() SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", chkShowSlotAndCrimp.Value
0 Likes
574 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
In your SaveSettings shouldn't you be writing the value of sFile to the "Section". -- Kent Keller Autodesk Discussion Forum Facilitator "Calimesa" wrote in message news:41487be7_2@newsprd01... > chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, > "ShowSlotAndCrimp", "true") > > End Sub > > > Private Sub UserForm_Terminate() > > SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", > chkShowSlotAndCrimp.Value > > > >
0 Likes
Message 3 of 15

Anonymous
Not applicable
You might want to check and make sure sFile has the file extension stripped off it, but I'm not sure that matters or not, though "Part1" has no extension on it, so it could be that. "Calimesa" wrote in message news:41487be7_2@newsprd01... > Can someone help pls. > I wrote a macro for a family of parts and want to "savesetting" each part in > the registry. > Here are my subs. > If I replace sfile in the UserForm_Initialize() and UserForm_Terminate() > with "Part1" then this program works fine. Otherwise I got the erro msg (see > att.) > > > Option Explicit > Dim sFile As String > > Private Sub cmdDataBase_Click() > Dim oDoc As Inventor.Document > Set oDoc = ThisApplication.ActiveDocument > > sFile = Right(oDoc.DisplayName, 13) > MsgBox ("File Name is:" & sFile) > > oDoc.Update > End Sub > > Private Sub UserForm_Initialize() > > chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, > "ShowSlotAndCrimp", "true") > > End Sub > > > Private Sub UserForm_Terminate() > > SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", > chkShowSlotAndCrimp.Value > > > >
0 Likes
Message 4 of 15

Anonymous
Not applicable
Kent, Not sure to follow you (I'm still a VBA idiot !) Do you mind to explain more to me. Thx "Kent Keller" wrote in message news:41487e59_3@newsprd01... > > In your SaveSettings shouldn't you be writing the value of sFile to the > "Section". > -- > Kent Keller > Autodesk Discussion Forum Facilitator > > > "Calimesa" wrote in message > news:41487be7_2@newsprd01... > > > chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, > > "ShowSlotAndCrimp", "true") > > > > End Sub > > > > > > Private Sub UserForm_Terminate() > > > > SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", > > chkShowSlotAndCrimp.Value > > > > > > > > > >
0 Likes
Message 5 of 15

Anonymous
Not applicable
Thanks. I tried to strip off the ".ipt" and got the same error msg. "Bob S." wrote in message news:41487ead$1_2@newsprd01... > You might want to check and make sure sFile has the file extension > stripped off it, but I'm not sure that matters or not, though "Part1" > has no extension on it, so it could be that. > > "Calimesa" wrote in message news:41487be7_2@newsprd01... > > Can someone help pls. > > I wrote a macro for a family of parts and want to "savesetting" each part in > > the registry. > > Here are my subs. > > If I replace sfile in the UserForm_Initialize() and UserForm_Terminate() > > with "Part1" then this program works fine. Otherwise I got the erro msg (see > > att.) > > > > > > Option Explicit > > Dim sFile As String > > > > Private Sub cmdDataBase_Click() > > Dim oDoc As Inventor.Document > > Set oDoc = ThisApplication.ActiveDocument > > > > sFile = Right(oDoc.DisplayName, 13) > > MsgBox ("File Name is:" & sFile) > > > > oDoc.Update > > End Sub > > > > Private Sub UserForm_Initialize() > > > > chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, > > "ShowSlotAndCrimp", "true") > > > > End Sub > > > > > > Private Sub UserForm_Terminate() > > > > SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", > > chkShowSlotAndCrimp.Value > > > > > > > > > >
0 Likes
Message 6 of 15

Anonymous
Not applicable
Opps, I somehow missed seeing sFile in the SaveSettings . I see it now ;~) Have you looked in the regstry and compared what you get when you do it using Part1 vs sFile? -- Kent Keller Autodesk Discussion Forum Facilitator "Calimesa" wrote in message news:41488099$1_3@newsprd01... > Kent, > Not sure to follow you (I'm still a VBA idiot !) > Do you mind to explain more to me. > Thx
0 Likes
Message 7 of 15

Anonymous
Not applicable
From the VBA Help File: SaveSetting appname := "MyApp", section := "Startup", _ key := "Top", setting := 75 Kent is asking if you should be writing the filename as the Section portion. It does appear by the VBA help file that you ARE putting the string stored in sFile into the Section portion of the registry, so maybe he is saying that is the wrong place to put the partname? I don't know that either. You may want to look at writing and getting your boolean values using the numbers 0 (false) and 1 (true) instead of strings "true" or "false"? Your current scheme is going to end up with the following: Appname: 2ndTooling Section: String value of sFile or "Part1" Key: ShowSlotAndCrimp Setting: true or false? 0 or 1? I was wondering though, do you get the error on both subs? In other words, do you get the same error when executing both SaveSettings and GetSettings, or is it only one of them? Have you checked the registry to see if it is actually writing anything? They should be ending up in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\2ndTooling Bob S. "Calimesa" wrote in message news:41488099$1_3@newsprd01... > Kent, > Not sure to follow you (I'm still a VBA idiot !) > Do you mind to explain more to me. > Thx > > > "Kent Keller" wrote in message > news:41487e59_3@newsprd01... >> >> In your SaveSettings shouldn't you be writing the value of sFile to the >> "Section". >> -- >> Kent Keller >> Autodesk Discussion Forum Facilitator >> >> >> "Calimesa" wrote in message >> news:41487be7_2@newsprd01... >> >> > chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, >> > "ShowSlotAndCrimp", "true") >> > >> > End Sub >> > >> > >> > Private Sub UserForm_Terminate() >> > >> > SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", >> > chkShowSlotAndCrimp.Value >> > >> > >> > >> > >> >> > >
0 Likes
Message 8 of 15

Anonymous
Not applicable
Nope, it was just a problem getting info from the screen to my brain. ;~) -- Kent Keller Autodesk Discussion Forum Facilitator "Bob S." wrote in message news:41488bc9 so maybe he is > saying that is the wrong place to put the partname?
0 Likes
Message 9 of 15

Anonymous
Not applicable
Idiot again !!! How to view the registry??? Thanks. "Kent Keller" wrote in message news:41488b2e$1_3@newsprd01... > Opps, I somehow missed seeing sFile in the SaveSettings . I see it now ;~) > > Have you looked in the regstry and compared what you get when you do it > using Part1 vs sFile? > > -- > Kent Keller > Autodesk Discussion Forum Facilitator > > > "Calimesa" wrote in message > news:41488099$1_3@newsprd01... > > Kent, > > Not sure to follow you (I'm still a VBA idiot !) > > Do you mind to explain more to me. > > Thx > > >
0 Likes
Message 10 of 15

Anonymous
Not applicable
The registry isn't some place to be taken lightly. If you mess something up there you have the chance the computer will never run right again. It probably isn't a good idea for you to be putting stuff in the registry without having a good understanding of it. Not trying to discourage you, but just making sure you understand the importance of it, and that it probably isn't the best place to be putting all kinds of random info using savesettings and getsettings. That said, go to Start >> Run >> and type in Regedit. Browse to HKEY_CURRENT_USER\Software\VB and VBA Program Settings and you should find all the things you have been storing there. You can have regedit open, view the values, run your code, and then hit F5 in the regedit window and see the new values. It seems to me for the type of info you are trying to store, you might be better off in doing it in either a ini file or a .txt file. Here is a good site to learn more about the registry http://www.winguides.com/registry/ -- Kent Keller Autodesk Discussion Forum Facilitator "Calimesa" wrote in message news:4148a783$1_1@newsprd01... > Idiot again !!! > How to view the registry??? > Thanks. > > "Kent Keller" wrote in message > news:41488b2e$1_3@newsprd01... > > Opps, I somehow missed seeing sFile in the SaveSettings . I see it now > ;~) > > > > Have you looked in the regstry and compared what you get when you do it > > using Part1 vs sFile? > > > > -- > > Kent Keller > > Autodesk Discussion Forum Facilitator > > > > > > "Calimesa" wrote in message > > news:41488099$1_3@newsprd01... > > > Kent, > > > Not sure to follow you (I'm still a VBA idiot !) > > > Do you mind to explain more to me. > > > Thx > > > > > > > >
0 Likes
Message 11 of 15

Anonymous
Not applicable
Could you please show me how to write these to the .txt file. Thanks "Kent Keller" wrote in message news:4148abbd$1_3@newsprd01... > The registry isn't some place to be taken lightly. If you mess something up > there you have the chance the computer will never run right again. It > probably isn't a good idea for you to be putting stuff in the registry > without having a good understanding of it. Not trying to discourage you, > but just making sure you understand the importance of it, and that it > probably isn't the best place to be putting all kinds of random info using > savesettings and getsettings. > > That said, go to Start >> Run >> and type in Regedit. Browse to > HKEY_CURRENT_USER\Software\VB and VBA Program Settings and you should find > all the things you have been storing there. You can have regedit open, > view the values, run your code, and then hit F5 in the regedit window and > see the new values. > > It seems to me for the type of info you are trying to store, you might be > better off in doing it in either a ini file or a .txt file. > > Here is a good site to learn more about the registry > http://www.winguides.com/registry/ > > -- > Kent Keller > Autodesk Discussion Forum Facilitator > > > "Calimesa" wrote in message > news:4148a783$1_1@newsprd01... > > Idiot again !!! > > How to view the registry??? > > Thanks. > > > > "Kent Keller" wrote in message > > news:41488b2e$1_3@newsprd01... > > > Opps, I somehow missed seeing sFile in the SaveSettings . I see it now > > ;~) > > > > > > Have you looked in the regstry and compared what you get when you do it > > > using Part1 vs sFile? > > > > > > -- > > > Kent Keller > > > Autodesk Discussion Forum Facilitator > > > > > > > > > "Calimesa" wrote in message > > > news:41488099$1_3@newsprd01... > > > > Kent, > > > > Not sure to follow you (I'm still a VBA idiot !) > > > > Do you mind to explain more to me. > > > > Thx > > > > > > > > > > > > > > >
0 Likes
Message 12 of 15

Anonymous
Not applicable
There should be info in the standard VBA help file (not Inventor programing help) and the always helpful google comes up with a lot of examples http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=visual+basic+write+text+file+-net&btnG=Search You could also replace text in the above google search with ini These sources should do a much better job of showing you than I ever could ;~) -- Kent Keller Autodesk Discussion Forum Facilitator "Calimesa" wrote in message news:4148acae_1@newsprd01... > Could you please show me how to write these to the .txt file. > Thanks
0 Likes
Message 13 of 15

Anonymous
Not applicable
Kent, Do you have a sample of "savesetting" into a .txt file? Thanks. "Kent Keller" wrote in message news:4148abbd$1_3@newsprd01... > The registry isn't some place to be taken lightly. If you mess something up > there you have the chance the computer will never run right again. It > probably isn't a good idea for you to be putting stuff in the registry > without having a good understanding of it. Not trying to discourage you, > but just making sure you understand the importance of it, and that it > probably isn't the best place to be putting all kinds of random info using > savesettings and getsettings. > > That said, go to Start >> Run >> and type in Regedit. Browse to > HKEY_CURRENT_USER\Software\VB and VBA Program Settings and you should find > all the things you have been storing there. You can have regedit open, > view the values, run your code, and then hit F5 in the regedit window and > see the new values. > > It seems to me for the type of info you are trying to store, you might be > better off in doing it in either a ini file or a .txt file. > > Here is a good site to learn more about the registry > http://www.winguides.com/registry/ > > -- > Kent Keller > Autodesk Discussion Forum Facilitator > > > "Calimesa" wrote in message > news:4148a783$1_1@newsprd01... > > Idiot again !!! > > How to view the registry??? > > Thanks. > > > > "Kent Keller" wrote in message > > news:41488b2e$1_3@newsprd01... > > > Opps, I somehow missed seeing sFile in the SaveSettings . I see it now > > ;~) > > > > > > Have you looked in the regstry and compared what you get when you do it > > > using Part1 vs sFile? > > > > > > -- > > > Kent Keller > > > Autodesk Discussion Forum Facilitator > > > > > > > > > "Calimesa" wrote in message > > > news:41488099$1_3@newsprd01... > > > > Kent, > > > > Not sure to follow you (I'm still a VBA idiot !) > > > > Do you mind to explain more to me. > > > > Thx > > > > > > > > > > > > > > >
0 Likes
Message 14 of 15

Anonymous
Not applicable
Here is a quick and dirty example of writing to and reading from a text file. The Sub Write_Text will create a file called c:\FileNames.txt, and write 3 filenames to it. The sub Get_Text will open the file and read the lines from it. Public Sub Write_Text() Dim sFileName(2) As String Dim x As Integer sFileName(0) = "C:\Part1.ipt" sFileName(1) = "C:\Assem1.iam" sFileName(2) = "C:\Drawing1.idw" Open "C:\FileNames.txt" For Output As #1 For x = 0 To 2 Write #1, sFileName(x) Next x Close #1 End Sub Public Sub Get_Text() Dim sTempVar(2) As String Dim x As Integer Open "C:\FileNames.txt" For Input As #1 x = 0 Do While Not EOF(1) Input #1, sTempVar(x) x = x + 1 Loop Close #1 MsgBox sTempVar(0) & vbCr & sTempVar(1) & vbCr & sTempVar(2) End Sub -- Kent Keller http://www.KWiKMcad.com Autodesk Discussion Group Facilitator "Calimesa" wrote in message news:4148e478$1_1@newsprd01... > Kent, > Do you have a sample of "savesetting" into a .txt file? > Thanks.
0 Likes
Message 15 of 15

Anonymous
Not applicable
Hi,

You don't need to strip the .ipt. The reason you are getting the error is that your variable sFile is not initialize at first time when the UserForm_Initialize() method is called and hence it tries to access the "" registry key which is wrong. There should be a valide name, whether it exist or not is imaterial. So the correct version of your code is as follows

Option Explicit
Dim sFile As String

Private Sub cmdDataBase_Click()
Dim oDoc As Inventor.Document
Set oDoc = ThisApplication.ActiveDocument

sFile = Right(oDoc.DisplayName, 13)
MsgBox ("File Name is:" & sFile)

oDoc.Update
End Sub

Private Sub UserForm_Initialize()
cmdDataBase_Click
chkShowSlotAndCrimp.Value = GetSetting("2ndTooling", sFile, "ShowSlotAndCrimp", "true")

End Sub


Private Sub UserForm_Terminate()

SaveSetting "2ndTooling", sFile, "ShowSlotAndCrimp", chkShowSlotAndCrimp.Value

End Sub

Please note that I have called the cmdDataBase_Click() method before calling the GetSetting method so that the sFile variable is initialize by some value.

Hope it solves your problem

Manoj
0 Likes