Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load file from Registry Value?

Status
Not open for further replies.

Rob7412

Technical User
Jan 26, 2006
31
US
I am trying to open a file upon form Load() I am getting the file name from a registry Value

On Form Load I get a
"ByRef Argument Type Mismatch" error when I try to load the form.

When I debug print "FileNamefromReg" the the string is correct it is
"C:\Program Files\dtSearch Developer\UserData\ixlib.ilb"

However as you can see when I try to use
LoadDocument FileNamefromReg I get the above error

But if I Use
LoadDocument "C:\Program Files\dtSearch Developer\UserData\ixlib.ilb"
It works just Fine

What the Heck am I doing Wrong!
Thanks in advance

Below is the relevent code.





Private Sub Form_Load()

Const BRANCH = "Software\dtSearch Corp.\DTSEARCH\Indexes"
With Registry1
Dim FileNamefromReg
FileNamefromReg = .QueryValue(epHKEY_CURRENT_USER, BRANCH, "LibraryList")
LoadDocument FileNamefromReg
End With
End Sub



Public Function DisplayContents(sectionName As String)
Dim sectonContent As String
Dim sectionNode As IXMLDOMElement
Dim buffer As String
Dim subElt As IXMLDOMElement
With SectionsList
sectionName = .Text
Set sectionNode = articleDoc.selectSingleNode("//Item[title='" + sectionName + "']")
End With
End Function


Function LoadDocument(url As String)
articleDoc.async = False
articleDoc.Load url
loadSelections
End Function


Public Function loadSelections()
Dim sections As IXMLDOMNodeList
Dim section As IXMLDOMNode
Set sections = articleDoc.selectNodes("//Item")
SectionsList.Clear
For Each section In sections
SectionsList.AddItem section.selectSingleNode("IndexName").Text
Next
SectionsList.ListIndex = 0
End Function
 
It's because you declared FileNamefromReg as Variant (by default) while your sub expects String.
 
Thanks for the reply But I have tried "Dim FileNamefromReg As String" and it does not give the error but it also does not open the document any suggestions?





 
Check out this line:
FileNamefromReg = .QueryValue(epHKEY_CURRENT_USER, BRANCH, "LibraryList")
 
I have questions to you also. These are some of them. Let us take this function:

Public Function DisplayContents(sectionName As String)
Dim sectonContent As String
Dim sectionNode As IXMLDOMElement
Dim buffer As String
Dim subElt As IXMLDOMElement
With SectionsList
sectionName = .Text
Set sectionNode = articleDoc.selectSingleNode("//Item[title='" + sectionName + "']")
End With
End Function

There are a lot of strange things I can see in this block.

1. What was the purpose of sectonContent, buffer, and subElt?

2. Why do you want to return sectionName ByRef (by default)? And indeed, you do.

3. If you indeed need sectionName to be returned from the function then why you don't use the return value of the very function DisplayContents instead? Just declare it As String.

4. You set your sectionNode and never use it. Why?

5. Why you never set your objects to Nothing when you don't need them anymore?

6. If you don't want to use the returned value of the function (and you don't use this returned value) then why you don't use Sub instead?

vladk

 
I got this code from another site and am trying to modify it to fit my needs. I in essence need to read from the registry the location of the file I need to read. from that file I populate a list of indexes on my form so the user can choose which index they want to update. the goal of my project is to

1. Find the file with the index info from the registry
2. Open the File
3. Return the index values from the file to a listbox
4. Allow user to sect which indexes to perform operations on

So as you can see I don't know much about reading XML of .ilf files which are written out in XML format, thats why the wierd code. Is there any simplier code you can point me to in order to achieve this?
 
>5. Why you never set your objects to Nothing when you don't need them anymore?

Because it is basically an urban myth that this is necessary. Most of the time you don't need to, as the reference is freed up when the variable goes out of scope
 
strongm,

Are you sure that this was the actual reason for not doing that? BTW, I am doing that all the time like explicit reference to default properties, like always specifying ByVal and ByRef and so on. I consider it a good practice just because it helps clarify things and makes coder's intentions clear.

vladk
 
I''m not commenting about style, just about necessity. And I repeat, contrary to many sources, in most cases it is not necessary to set an object variable to Nothing.
 
strongm, right, I agree. The problem was that there are a lot of things that prepared and never used in the function, so if something is not set to Nothing then we will never know if this is because an object is supposed to be used but for some reason this not happened or because this thing just was overlooked. Your reply was right but also can make think that objects were not set to Nothing because somebody knew that this is not necessary.

Rob7412, I will not be available next week. I am sure, somebody will also help you. strongm, actually, is the best VB6 expert on this forum and either he or other excellent experts can help you.

Meantime you might want check this line:

FileNamefromReg = .QueryValue(epHKEY_CURRENT_USER, BRANCH, "LibraryList")

to make sure that FileNamefromReg gets expected value. It looks like you correctly decided to use DOM to read XML. The actual reading of XML file will, I assume, depend on the structure of the file and what element of that structure you need to extract. In order to find the filename from the registry you might want to use GetSetting VB function.

vladk
 
Vladk and everyone else.
Thanks I have the value writing to a text box for debugging purposes and it is perfectly correct. This is a real head scratcher because I use the exact text the registry value returns instead of the Dim 'ed object FileNamefromReg and it works perfectly. Thanks for the info and I will keep plugging away at it and see if I can figure out what is going on or at least figure out a work around.
 
Given that you have accepted vladk's correct explanation for why you get the type mismatch error, and that we are now working on why no file gets loaded when you dim FileNameFromReg as String

>I have the value writing to a text box

Trusting a textbox to correctly display the contents of a string for debug purposes is risky. You woukd be far better off checking the Locals window whilst in break mode. My suspicion (give we have no idea which Registry component you are using, and thus cannot say what it is expected to return) is that the returned string isn't quite what you think it is
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top