TextString Conversion Method?

TextString Conversion Method?

Anonymous
Not applicable
718 Views
7 Replies
Message 1 of 8

TextString Conversion Method?

Anonymous
Not applicable
Hello Everyone, I wanted to ask what methods are better to use to carryout this function: I want to convert a textstrings in the following. EXAMPLES: ---------------------- FROM: AB1204 TO: 12'-4" FROM: AB0909 TO: 9'-9" Basically, I have a 4 digit number representing feet and inches. I think I have figured a method out by "bullying" the textstring using IF, THEN, LEFT. RIGHT, and MID functions. IF/THEN for feet less than 10 feet, etc.. I was thinking there must be a better way to do this. Any suggestions, code, example, etc. is grreatly appreciated. Throught this NewsGroup, I have learned much. Thank you, Dan
0 Likes
719 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
You're in luck... you don't need to bully the textstring's, the VAL function will take care of the values less than 10.... if your format is always 4-digit, padded with zeroes (and always integers), you could just use: dim too as string, from as string from="AB1204" too = Format(Val(Mid(from, 3, 2))) & "'-" & Format(Val(Mid(from, 5, 2))) & """" msgbox too HTH, James "Dan" wrote in message news:4162d1e6_3@newsprd01... > Hello Everyone, > I wanted to ask what methods are better to use to carryout this function: > > I want to convert a textstrings in the following. > EXAMPLES: > ---------------------- > FROM: AB1204 > TO: 12'-4" > > FROM: AB0909 > TO: 9'-9" > > Basically, I have a 4 digit number representing feet and inches. I think I > have figured a method out by "bullying" the textstring using IF, THEN, LEFT. > RIGHT, and MID functions. IF/THEN for feet less than 10 feet, etc.. > > I was thinking there must be a better way to do this. > > Any suggestions, code, example, etc. is grreatly appreciated. Throught this > NewsGroup, I have learned much. > > Thank you, > Dan > >
0 Likes
Message 3 of 8

Anonymous
Not applicable
AWESOME! I knew there must be a better way, and I learned about a new function. Thank you very much, Dan "James Belshan" wrote in message news:4162d971$1_3@newsprd01... > You're in luck... you don't need to bully the textstring's, the VAL function > will take care of the values less than 10.... if your format is always > 4-digit, padded with zeroes (and always integers), you could just use: > > dim too as string, from as string > from="AB1204" > too = Format(Val(Mid(from, 3, 2))) & "'-" & Format(Val(Mid(from, 5, 2))) & > """" > msgbox too > > > HTH, > James > > > "Dan" wrote in message > news:4162d1e6_3@newsprd01... > > Hello Everyone, > > I wanted to ask what methods are better to use to carryout this function: > > > > I want to convert a textstrings in the following. > > EXAMPLES: > > ---------------------- > > FROM: AB1204 > > TO: 12'-4" > > > > FROM: AB0909 > > TO: 9'-9" > > > > Basically, I have a 4 digit number representing feet and inches. I think > I > > have figured a method out by "bullying" the textstring using IF, THEN, > LEFT. > > RIGHT, and MID functions. IF/THEN for feet less than 10 feet, etc.. > > > > I was thinking there must be a better way to do this. > > > > Any suggestions, code, example, etc. is grreatly appreciated. Throught > this > > NewsGroup, I have learned much. > > > > Thank you, > > Dan > > > > > >
0 Likes
Message 4 of 8

Anonymous
Not applicable
Hi James, Curious about the use of val function I seem to get the same from too = Format(Mid(from, 3, 2)) & "'-" & Format(Mid(from, 5, 2)) & """" as from your line using val I didn't try every possible input value though It seems from the help description that it only eliminates alpha characters which in this case according to the specs is taken care of by the format of the input string ??? tia Mark "James Belshan" wrote in message news:4162d971$1_3@newsprd01... > You're in luck... you don't need to bully the textstring's, the VAL function > will take care of the values less than 10.... if your format is always > 4-digit, padded with zeroes (and always integers), you could just use: > > dim too as string, from as string > from="AB1204" > too = Format(Val(Mid(from, 3, 2))) & "'-" & Format(Val(Mid(from, 5, 2))) & > """" > msgbox too > > > HTH, > James > >
0 Likes
Message 5 of 8

Anonymous
Not applicable
I'm old school... I'm used to the Format$() function, which required a numeric parameter. So you had to go from string "09" to number 9 to string "9". The Format() function can apparently take a number OR a string value. I didn't know it could do that. James
0 Likes
Message 6 of 8

Anonymous
Not applicable
Thanks :-) Mark "James Belshan" wrote in message news:4162f79f$1_3@newsprd01... > I'm old school... I'm used to the Format$() function, which required a > numeric parameter. So you had to go from string "09" to number 9 to string > "9". The Format() function can apparently take a number OR a string value. > I didn't know it could do that. > > James > >
0 Likes
Message 7 of 8

Anonymous
Not applicable
NP... I think I still like the old school way, though. I'm not a big fan of Variants -- if I'm not even sure what type of variable I'm passing to a function, how likely is it that I know it has a valid value? An example.... I was curious what would happen if I sent it a string that was semi-numeric, so I tried Format("5.45a") thinking I'd get an error or "5.45". The result was "5:45:00 AM". In hindsight, it makes sense, but how many other unexpected answers are there lurking out there? Just my opinion..... James
0 Likes
Message 8 of 8

Anonymous
Not applicable
Good questions. Thanks again. I learned alot. Dan "James Belshan" wrote in message news:416314df$1_3@newsprd01... > NP... I think I still like the old school way, though. I'm not a big fan of > Variants -- if I'm not even sure what type of variable I'm passing to a > function, how likely is it that I know it has a valid value? An example.... > I was curious what would happen if I sent it a string that was semi-numeric, > so I tried Format("5.45a") thinking I'd get an error or "5.45". The result > was "5:45:00 AM". In hindsight, it makes sense, but how many other > unexpected answers are there lurking out there? > > Just my opinion..... > > James > >
0 Likes