|
treddie wrote: So, the TreeView is the "only" answer. Search CP, and you'll find that a lot of people think something similar.
treddie wrote: so where do you stop? The moment I recognize the repeating pattern; same code, same handler, just a different level. Neat piece o' code that TnTinMan posted, mine would have been longer
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Search CP, and you'll find that a lot of people think something similar.
Well, at least I'm not alone.
Eddy Vluggen wrote: The moment I recognize the repeating pattern; same code, same handler, just a different level. Neat piece o' code that TnTinMan posted, mine would have been longer
Problem is I couldn't find a way to generalize the repeating code. I looked all over for something to do just that and continued to try to solve it, but my unfamiliarity with the TreeView properties bit my ass. That really is a nice compact piece of code.
After looking at it, it seems that what makes it work, is that once each match is made, what is important is the handle of the node. Otherwise, since two nodes can have the same name and text label, there would be no way for vb to know what node was being referred to. But the handles are all different. I tried working with the handles earlier, but could not find a way to get a node selected based on its handle.
modified 14-May-13 18:14pm.
|
|
|
|
|
Hi,
I'm playing around with encryption in vb.net. The passphrase that I use is stored in code. After building the app the passphrase is not visible anymore. But with the tool CodeReflect.NET I can find the passphrase again. How should I store the passphrase in a safe way?
Cheers,
Frank
|
|
|
|
|
have a look for c# DPAPI - in short, you generate/use a machine key and iirc, use that to encrypt your passphrase - to store in a config file or such - it can only be decrypted on that specific machine (again, iirc)
its not fool proof of course(*) - but its better that storing information in cleartext
(*) what I mean is, is you should protect your machine from unwanted access
'g'
|
|
|
|
|
Hmm, I think my post was incomplete. For the application (installed on more than 1 pc) that I'm building I would like to encrypt passwords that are stored in a SQL database. I thought that I could do this via encryption. So how and where is the best option to store the passphrase?
Cheers,
Frank
|
|
|
|
|
frankelman wrote: SQL database
what flavour DB are you using ?
frankelman wrote: I thought that I could do this via encryption
yes you can, but some databases have build in column encryption which could make life easier
frankelman wrote: So how and where is the best option to store the passphrase
there's never a fool-proof way to do this - eventually, something is going to have to get the passphrase from somewhere and use it to decrypt the data, which is an exposure risk - depending on what your SQL provider supplies, you could use an algorithm written in plsql/an external function/? that generates a machine-id to use as a secret/passphrase for example - then you could do something like
insert into table(x,y,z) values (x,y,encrypt(z,getpassphrase));
where getpassphrase is the plsql function that knows how to get or build the passphrase
Or, have a control table and store the passphrase base64 encoded or simply ceasar ciphered so its not obvious - we dont know your situation, so saying what the risks are and how to mitigate against them is hard
'g'
|
|
|
|
|
Currently I'm using MSSQL2008R2. I'll have a look at column encryption. But I also realize that my application does not contain very secret data, the password is the only thing I want to encrypt.
Cheers,
Frank
|
|
|
|
|
Hi again.
I have a peculiar problem that is somewhat reminiscent of vb6's Eval() function.
Let's say I have a TreeView populated with an entire harddrive's directory structure, and I want to select the node that contains a folder I am looking for. If I use the .Find method, the search could take forever, and I may end up with multiple places in the TreeView where this name is located. If I already have the full path to the correct folder, then I need a quick way to get to the node without having to search the entire tree.
Now, I actually have a quick way of doing this (at least I am confident it will work), but in the process of getting to that solution, I was experimenting with another idea that harks back to that vb6 Eval() function...Sort of. That other idea revolved around selectively expanding a tree branch and testing inside each child node to make sure that the next folder name in my full path could be found there. If so, it would expand that node and continue until all folders in the full path had been exhausted. Theoretically, I would then be at my desired node, which I could then select in the tree. But the problem is that in order to do that, you start at TreeView1.Nodes(0) and do a Find(). Once that node is selected, it gets expanded and you then do a Find() for the second folder, which gets found at Nodes(0).Nodes(x). Moving along in the same fashion, you get to Nodes(0).Nodes(x).Nodes(y), and so on till the task is completed. I think you can see the problem already...Without explicitly setting up Case blocks or If/Else blocks to handle each succession of methods,
Nodes(0)<br />
Nodes(0).Nodes(x)<br />
Nodes(0).Nodes(x).Nodes(y),...
there is no way for the code to handle this problem. And such a folder could lie at the tenth childnode, maybe even the twentieth, or more. The point being, it is a kludge to try to estimate when you should stop providing hard-coded cases and pray that some scenario doesn't exceed that limit.
That is when I was thinking if there was a way to build a string programatically to whatever length I needed it to be, like,
"TreeView1.Nodes(0).Nodes(x).Nodes(y).Expand"
and then convert that string into an actual code statement by having the string "evaluated" as such. Is this possible? As I stated above, I think I found another very elegant solution to my TreeView Find() problem which is simple and quick. But I am curious now, if vb.Net has the ability to turn a string into a code statement, or maybe even multiline text into actual vb.Net code?
|
|
|
|
|
I think you need to look at a recursive method. That is, a method that calls itself.
Something like: Find( CurrentNode, SubPath ) where the CurrentNode and SubPath are adjusted on each call to itself.
You should be able to find boatloads of examples on here, so I won't go into any more detail.
|
|
|
|
|
I was thinking about recursion, but I could not find a way to get the node depth to "recurse". Until just now maybe (lightbulb). But have to see if it is sound.
But I am still curious about my original question...Has someone found a way to turn text into code?
|
|
|
|
|
You don't need it.
Yeah, it's called an IDE and compiler. You have to do about the same thing in your code. Create an instance of the compiler and feed it not a string, not an object graph that represents the code you're creating. I wish it was as easy as a couple lines of code, but no. Far from it.
But, doing something like this really is not going to help you to solve your problem.
|
|
|
|
|
Bummer.
I'm so close to finishing a program I've been working on for a year and the only thing hanging me up is this damn TreeView problem. I just find it so bizarre that MS could not provide some very simple functionality to a TreeView, that I would think would be self-evidently obvious properties and methods to include straight-away. I come up with nifty solutions only to have them dashed by a lack of really basic control methods. So frustrating.
|
|
|
|
|
Just because it's a "simple" method to make your job easier, doesn't mean it's a good thing to put into the framework.
The .NET Framework is already too heavy. That's why it has been split into Full and Client Profile versions. Why put more stuff into it that's really not neccessary?
|
|
|
|
|
Only because it has such far reaching and useful consequences. I doubt that .Net will cease to grow and get even more heavy, but this option would serve so many uses where recursion is not an option.
|
|
|
|
|
Not so useful. Actually, pretty limiting in both security and performance.
First, it's poor-performing code as it has to be compiled before use, at runtime. Access to variables might also have to be done through reflection as you REALLY don't want to run this code in the same AppDomain as the application code because of HUGE security problems with running user-enterable code in an app. Google for "SQL Injection attacks" for examples on how bad this is. The compile-time compiler also cannot possibly predict the contents of a string so it cannot pre-compile anything, wasting more time. You MIGHT get away with a caching scheme to improve performance a little bit, kind of like how strings are stored, but again, you'd have to be able to store the string with the compiled code so you have a quick lookup of the string version of the code as a key.
Oh, and you also lose type-safety and Intellisense.
If you think you need to do this in your application code, it's generally taken as a sign your code design is DEEPLY flawed.
|
|
|
|
|
Good points. So the emphasis is back to the limitations of the .Nodes() property. What a shame they did not set it up as, for example, TreeView1.Nodes(NodesArray(x)).SelectedNode. That would be a perfect road map for the Nodes property to follow, to get to a destination in the tree.
|
|
|
|
|
That doesn't make sense either as you'd have to manually walk the tree to find the node that is selected. Not very efficient, is it??
The TreeView already has a SelectedNode property which will return the node that is selected. From there, it's trivial to navigate up to the Node tree to the root of the Nodes collection in the TreeView control.
Getting back to your original search problem, you're going about it wrong. You're thinking about searching a tree structure that's not designed to be searched efficiently.
What you should be doing is a dedicated indexing solution for a collection of paths, each of which contains a reference to the Node it came from. Searching the dedicated structure would be far more efficient then searching the TreeView Nodes collection.
|
|
|
|
|
TnTinMn offered the following solution back in post, 13 May '13 - 13:13. Seems pretty darn elegant and compact. I am in the process of testing its performance on a TreeView loaded with a huge drive's directory structure.
|
|
|
|
|
NeverJustHere wrote: Something like: Find( CurrentNode, SubPath ) where the CurrentNode and SubPath are adjusted on each call to itself.
That is easy in principle, but it does not appear that there is any way to tell vb.Net to restrict a Find() to a starting childnode and a sub path. Without that, recursion is useless. Unless I keep building a new node structure that omits the prior part already searched. If that node structure represents an entire harddrive, that would be slower than watching mountains grow.
|
|
|
|
|
|
dusty_dex wrote: Is this^ any help?
Hi Dusty_dex. Are you referring to the previous post? If so, I'm checking into it.
But I am still curious about my original question...Has someone found a way to turn text into code? In general, it would be so cool and useful for so many things.
|
|
|
|
|
treddie wrote: But I am still curious about my original question...Has someone found a way to turn text into code?
66-666-##-11-22-88-8-##-999-666-88-##-222-2-66-##-4-33-88-##-7777-666-6-33-##-444-66-8-33-777-33-7777-8-444-66-4-##444-3-33-2-7777-11111
|
|
|
|
|
Lol! OK, Mr. Blechley Park!
|
|
|
|
|
If you're curious about recursive functions/parsing/codifying information, perhaps you should read this book: Godel, Escher & Bach by Douglas E. Hofstadter.
also, A New Kind of Science by Stephen Wolfram is pretty interesting too.
|
|
|
|
|
DoH! More book reading for my schedule! I'll have to look those up. Thanks!
|
|
|
|
|