|
-
Nov 3rd, 2011, 09:07 AM
#1
Thread Starter
Lively Member
New name for string
In my project I need to use a 190 very long strings with different number of characters (4-60).
I want to mark them in a short form with the numbers 001, 002, 003 ... 190.
Is there an easy way to display the full name of the string when I choose a short name ?
Of course, I do not want to write 190 times "if - end if" and also I would like to avoid a complicated database.
Onenew
Visual Studio 2010
-
Nov 3rd, 2011, 09:20 AM
#2
Re: New name for string
I need to use a 190 very long strings with different number of characters (4-60).
is this mean strings of variable length wright ?
I want to mark them in a short form with the numbers 001, 002, 003 ... 190.
what are these numbers, is it just like person & his ID. like 001 = string1
if so
there are 2 ways,
(1) Use a simple database ( access is preferable )
(2) load all the data in to a datatable & query it
-
Nov 3rd, 2011, 09:27 AM
#3
Thread Starter
Lively Member
Re: New name for string
More explanations. Strings have variable lengths.
For example:
001 = 1-8,2-9,3-10
002 = 1-10
003 = 1-6,8,10,12,14,16,18,20,22,24,26,28,30
Onenew
-
Nov 3rd, 2011, 09:36 AM
#4
Re: New name for string
fine
create a access database, & store these values and then query it.
what help you need here
-
Nov 3rd, 2011, 09:50 AM
#5
Hyperactive Member
Re: New name for string
Surely you could just put them in an array?
-
Nov 3rd, 2011, 10:03 AM
#6
Thread Starter
Lively Member
Re: New name for string
Hi, OhGreen,
Can you say something a little more about it and maybe give an example?
Onenew
-
Nov 3rd, 2011, 10:39 AM
#7
Re: New name for string
Surely you just need a dictionary.
Code:
Dim Data As New Dictionary(Of String, String)
Data.Add("001", "blah blah long string blah blah")
Data.Add("002", "Other long blah blah long string blah blah")
Data.Add("003", "Other other long blah blah long string blah blah")
You can then just pull them out when you need them like so:
Code:
MessageBox.Show( Data("001") )
MessageBox.Show( Data("003") )
-
Nov 3rd, 2011, 10:54 AM
#8
Hyperactive Member
Re: New name for string
Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list. You could use either method.
OneNew, how are you planning on:
a) changing the strings in the future (if necessary?)
b) entering the value initially
It would be possible using Grimfort's example to add features to delete or add items.
-
Nov 3rd, 2011, 10:54 AM
#9
Re: New name for string
I'd go with the dictionary, too. They are very convenient. You can also work with either just the keys or just the values, so it is probably your most versatile alternative.
My usual boring signature: Nothing
 
-
Nov 3rd, 2011, 11:00 AM
#10
Re: New name for string
 Originally Posted by OhGreen
Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list. You could use either method.
OneNew, how are you planning on:
a) changing the strings in the future (if necessary?)
b) entering the value initially
It would be possible using Grimfort's example to add features to delete or add items.
I don't think that's valid. Using a dictionary by any means, especially the way Grimfort did, it doesn't matter whether the items shift. In fact, it's hard to say that they would shift at all. They are key-value pairs. The key remains tied to the same value, regardless of whether you add or remove items. Item #10 may have the key "011". If you were to remove item #9, then Item#10 would become item #9, but it would still have the key "011", and would still have the associated value. You wouldn't normally use an index value (such as my #9 and #10) to access an item in a dictionary, but if you wanted to do that, then the dictionary should be a Dictionary (of Integer,String) where the integer is the same as the index. This could be done, but there isn't any sound reason to do so.
My usual boring signature: Nothing
 
-
Nov 3rd, 2011, 11:03 AM
#11
Re: New name for string
 Originally Posted by OhGreen
Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list.
This is not a problem, this is the design of a Dictionary. If position is important, you don't use a Dictionary, you use an actual List, but that defeats the whole lookup idea.
-
Nov 3rd, 2011, 11:13 AM
#12
Re: New name for string
i prefer to load the data in to a datatable & then query the same
please find the attachment,
how ever i failed to set the LINQ out put as datagridview datasource Grim any advice further in this context
-
Nov 3rd, 2011, 11:51 AM
#13
Hyperactive Member
Re: New name for string
Oh right okay, I've never really played with dictionary's simply because of knowing that they shift the position and presumed that would be an issue in most examples.
Wouldn't that then make arrays redundant? Or am I completely off when thinking they're very similar?
-
Nov 3rd, 2011, 11:55 AM
#14
Hyperactive Member
Re: New name for string
make_me_rain I personally agree, with the amount of data involved in this situation I'd rather have the strings stored within a database. Although with the vast amount it would make the code mammoth, you do have the option of creating a module to hide the bulk of the dictionary.
-
Nov 3rd, 2011, 12:00 PM
#15
Re: New name for string
190 strings is quite small, I have resource files with far far more entries than this. If this is just information you are spraying around like error codes, then a resource file is just as useful. Likely adding a database to this scenario will hit your 190 lines on its own .
-
Nov 3rd, 2011, 12:15 PM
#16
Re: New name for string
grim,Og my highlighted part is leftover
-
Nov 3rd, 2011, 12:27 PM
#17
Re: New name for string
I did not have any time to look at it, sorry!
-
Nov 3rd, 2011, 12:38 PM
#18
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
|