| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 124947 | 2012-05-29 08:46:00 | VB.Net Numbers to words/variables and/or databases | icow (15313) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1278223 | 2012-05-29 08:46:00 | I'm generating numbers randomly into the variable random by using this code: random = Int((maxvalue * Rnd()) + 1) (maxvalue representing the maximum value that the random number can be). I have a series of variables called one, two, three...one_hundred containing specific text (they're strings). At the moment I'm only using 6 of these strings and coding them like so: if random = 1 then textbox1.text = one if random = 2 then texbox1.text = two and so on till I get to all six values. The thing is could potentially have over 500 different strings so coding them in manually seems like a pain. Is there an efficient way of getting my program to automatically grab the correct string. E.g. texbox1.text = X and then have a line (or lines) of code above this that makes X the string that corresponds to the value that random gives. An alternative is to dump all of the data into a database or text doc (with each string there is 5 other values which I associate with the base string). These values are used within the program when the original string is called. So if I was to use a database the program would need to randomly grab the row associated with the number generated randomly and then get the 4 cells next to that as well. Which im not really sure how to do, whatever will be easiest really. I have no problem with "hardcoding" me values into my program. |
icow (15313) | ||
| 1278224 | 2012-05-29 08:54:00 | I'd write a method that converts individual digits into strings (so 1 = one, 2 = two, etc), then write another that divides the number by decreasing powers of 10 and appending the appropriate string. So if you have the number 453: Dim dgt As Integer = 453 / 100 '=4 (integer) Dim number As String = getDigitString(4) + " hundred" Numbers 1 through 19 will need to be coded individually, as well as multiples of 10. For 23, you would call getDigitString(20) + getDigitString(3). Also note I wouldn't recommended using Visual Basic either. :p (Side note: there may already be a library or class floating around that can do this already, have a look on http://codeplex.com) |
pcuser42 (130) | ||
| 1278225 | 2012-05-29 09:03:00 | Or you could go... textbox1.text = random so the text in textbox1 equals the value of rnd:) Not sure if thats what you're looking for. Edit:sorry im wrong |
stratex5 (16685) | ||
| 1278226 | 2012-05-29 09:12:00 | I'd write a method that converts individual digits into strings (so 1 = one, 2 = two, etc), then write another that divides the number by decreasing powers of 10 and appending the appropriate string. So if you have the number 453: Dim dgt As Integer = 453 / 100 '=4 (integer) Dim number As String = getDigitString(4) + " hundred" Numbers 1 through 19 will need to be coded individually, as well as multiples of 10. For 23, you would call getDigitString(20) + getDigitString(3). Also note I wouldn't recommended using Visual Basic either. :p (Side note: there may already be a library or class floating around that can do this already, have a look on http://codeplex.com) Awesome, thanks :) If not visual basic, what would you recommend? |
icow (15313) | ||
| 1278227 | 2012-05-29 10:10:00 | Awesome, thanks :) If not visual basic, what would you recommend? C#. It's far more like what you'll encounter in the real world ;) |
pcuser42 (130) | ||
| 1 | |||||