-
Feb 21st, 2012, 08:43 AM
#1
Thread Starter
Member
[RESOLVED] Import a file with code
Hi
I was wondering if someone could help me
I have a vb system and I wish to execute some code depending on the result of a text box. The text box could contain two strings, depending on the result I want to execute a set of rules to search for specific files e.g. if one option the code will search for certain files defined for example request.doc and if other option then it will search for other files, which are my rules for the searches. I want these rules to be external to the system and for them to be loaded in so that its easier for the user of the system to change these rules if needed so they dont have to go into the programming of the code. Is there a specific file I can use such as .xml or a just a basic .txt file and what would the syntax be for these?
Any help would be welcome!
-
Feb 21st, 2012, 09:00 AM
#2
Re: Import a file with code
Object serialization would be my first instinct. XML my second.
-
Feb 21st, 2012, 09:04 AM
#3
Thread Starter
Member
Re: Import a file with code
Thanks, what would be the syntax for XML? Also can I put code into a xml file?
-
Feb 21st, 2012, 10:35 AM
#4
Re: Import a file with code
You can put anything you want into an XML file. You dont know the structure of an XML file ? What do you mean its syntax ?
Could you provide in explicit details what exactly it is you're looking for. I dont fully understand what it is you want. Take your time and write out a proper, clear explanation so that we can help you.
-
Feb 21st, 2012, 10:46 AM
#5
Re: Import a file with code
It sounds like the biggest challenge is going to be creating a syntax. If you want non-programmers to be able to edit the file and change the search criteria, then you will need a text-based file such as XML, or even just .TXT, but when people can change a text file, they have every opportunity to turn it into garbage. This is probably worse with XML than with .TXT, because a clueless editor could corrupt the XML itself, making it unreadable by a normal XML parser. It gets even worse if those files hold code. A non-coder can't really be expected to edit code correctly. Heck, even coders tend to create plenty of bugs without testing.
I'd like to see a more complete description of the problem, as well, but I'd also lean towards an app that manages the files rather than just letting anybody go in and tinker at will.
My usual boring signature: Nothing
-
Feb 21st, 2012, 11:29 AM
#6
Thread Starter
Member
Re: Import a file with code
I meant how would i enter the search criteria into the xml file like:
<Rules>
<rule1>
<description>The code for checking if a file exists</description>
</rule1>
</Rules>
At the moment the full usability wont be too much of a problem as I would be the only one using it so I would be changing the files.
I need to have a system that can check a record and its 'proof', but depending what the record is classified as there will be different searching criteria. The first classification would need to check whether a request document is present in a folder and a closing confirmation document in the folder. The other classification will need these checks but also other checks such as a file which includes the time and date information. The system is to basically automate this process which was once done manually (ie searching for files). The searching criteria for better usage with a user should be external for them to change the searches it if need be if they are changed/updated. The main issue I have at the moment is coding the xml file itself and how to import it along with the other code for it to work
Any help would be brill
-
Feb 21st, 2012, 01:43 PM
#7
Re: Import a file with code
Would every single record in the database have a corresponding entry in the Xml/.TXT file ? Would you like the entries to refer to a specific record by its primary key ? Are they bound by the classification you spoke of ? How is this related to the textbox with the strings you mentioned earlier ?
You are giving us bits and pieces of information and im having a difficult time pinning down what it is you really need. I think you should just tell take a step back and describe the overall system that you're dealing with, like what type of software is it and what does your problem have to do with it.
-
Feb 21st, 2012, 02:06 PM
#8
Thread Starter
Member
Re: Import a file with code
Sorry its just im not sure how to explain it fully. To take a step back what I would want it to do basically is if a file is present a check box will be checked, so if a request document is present the box will tick. (also is there a way for the user to specify a folder to search for the file?.....getting off topic :S) However I think that I will need various if statements to say if textbox1.text = one then check for these files and if textbox1.text=two it will search for different files. I wanted the checks to be in a seperate file but am happy to have them in the system at this point as im on meltdown with this system so I appriciate you trying to help me . The system is in vb2010 and i think its mainly getting the logic right
-
Feb 21st, 2012, 02:19 PM
#9
Re: Import a file with code
Ok now we're getting somewhere. Are the checkboxes fixed in the software or do you want them to be generated dynamically based on settings in a file ?
-
Feb 21st, 2012, 02:23 PM
#10
Thread Starter
Member
Re: Import a file with code
The checkboxes change depending if the file is there or not, so will turn green and tick if the file is present and red if it isnt there
-
Feb 21st, 2012, 02:32 PM
#11
Re: Import a file with code
So what you really want is a way to check to see if a file exists ?
You can check for a file's existence like:-
vbnet Code:
Dim b As Boolean = My.Computer.FileSystem.FileExists("C:\MyFile.Txt")
-
Feb 21st, 2012, 03:20 PM
#12
Thread Starter
Member
Re: Import a file with code
Thank you If I have a FolderBrowserDialog Class on the form for the user is there any way this can determine what folder the search is looking in?
Thanks for your help, so if I wanted to do a file existence on a If statement so
If textbox1.text = 'New' then Dim b As Boolean = My.Computer.FileSystem.FileExists("C:\MyFile.Txt")
End If
-
Feb 21st, 2012, 09:13 PM
#13
Re: Import a file with code
The FolderBrowserDialog class has a SelectedPath property you can use to determine the path selected.
As for that If statement you got there....it isnt quite obvious what that is meant to do there.
-
Feb 22nd, 2012, 08:02 AM
#14
Thread Starter
Member
Re: Import a file with code
So if im searching for a specific file coulld I get the user to chose the folder path (as there is more than once evidence with the same file name but a different document) ie requestcheck.doc can i put it instead of the c: in Dim b As Boolean = My.Computer.FileSystem.FileExists("C:\MyFile.Txt") as the "c:\myfile.text is fixed I just want the c: to be not fixed within the search......just thought about this maybe error Thanks for still helping me
-
Feb 22nd, 2012, 09:28 AM
#15
Re: Import a file with code
vbnet Code:
Dim path As String = "c:\"
Dim f As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(path)
The above code returns all the files present at the root folder of the C drive. You can use the path returned by your FolderBrowserDialog instead and then enumerate the collection returned by GetFiles to find the file or files that you want.
-
Feb 22nd, 2012, 09:59 AM
#16
Thread Starter
Member
Re: Import a file with code
Thanks so i have
Dim path As String = "folderchoicetxt"
Dim f As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(path)
But it says 'Read Only Collection' is not defined. Sorry if im being a pain and i appriciate the help
-
Feb 22nd, 2012, 03:28 PM
#17
Re: Import a file with code
vbnet Code:
Imports System.Collections.ObjectModel
-
Feb 25th, 2012, 08:08 AM
#18
Thread Starter
Member
-
Feb 25th, 2012, 09:05 AM
#19
Re: Import a file with code
You need to pass a path to the GetFiles() Method
You also need quotes around any literal you try to put in there.
-
Feb 25th, 2012, 11:11 AM
#20
Thread Starter
Member
Re: Import a file with code
i am getting this error:
Could not find a part of the path 'C:\Users\Admin\Documents\VBProject\System\bin\Debug\file.xlsx\'.
Even when the dialogue box is changed to go to just my documents
Last edited by Emma11263; Feb 25th, 2012 at 11:32 AM.
-
Feb 25th, 2012, 11:53 AM
#21
Re: Import a file with code
Did you notice the \ after your filename? That should not be there.
-
Feb 28th, 2012, 06:58 AM
#22
Thread Starter
Member
Re: Import a file with code
I finally got it working.......thank you so much!!
However I used the combine path instead of the GetFile function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|