Author |
Topic  |
|
sadra
Starting Member
Iran
30 Posts |
Posted - 03 September 2011 : 00:20:29
|
Hi, who can help me?
i have a function for convert a numeric value to abc value in tow arrays but not work correctly
function NumberToABC(pString)
fString = trim(pString)
if fString = "" or IsNull(fstring) then
exit function
else
txtABCWords = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" ' 26
txtEquivalentReplace = "1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800" ' 26
aWords = split(txtABCWords, ",")
eReplace = split(txtEquivalentReplace, ",")
for i = 0 to ubound(eReplace)
fString = Replace(fString, eReplace(i), aWords(i), 1, -1, 1)
next
end if
NumberToABC = fString
end function
example: for "NumberToABC("60")" in correct form must have "O" but his function return "F"
Instead of returning the letter "O" letter "F" on returns.
Can anyone help me?
|
[red]how soon is too late[/red] |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 03 September 2011 : 03:32:43
|
it returns F because the first thing it finds to replace is 6 not 60, you need to reverse your for loop try
for i = ubound(eReplace) to 0 Step -1 fString = Replace(fString, eReplace(i), aWords(i), 1, -1, 1) next
|
MVC .net dev/test site | MVC .net running on Raspberry Pi |
 |
|
sadra
Starting Member
Iran
30 Posts |
Posted - 03 September 2011 : 05:36:35
|
Tanx Mr HuwR... Fixed |
[red]how soon is too late[/red] |
 |
|
Carefree
Advanced Member
    
Philippines
4217 Posts |
Posted - 03 September 2011 : 05:44:37
|
The way it's written, it should return "F0". An alternative approach would be something like this. With this method, it wouldn't matter where the value fell in the string or even if the values weren't in order.
<%
Dim strABC, strP, strF, intI, intJ, intK, intL
strP=Request.Form("NValue")
strF=Trim(strP)
If strF > "" Then
NumberToABC(strF)
End If
Response.Write "<form action=""n2a.asp"" method=""post"">" & vbNewLine & _
" <table align=""center"" width=""300px;"" bgColor=""white"" border=""0"" style=""border-collapse:collapse;"" cellpadding=""0"" cellspacing=""0"">" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" width=""100%"" bgColor=""lightblue"">" & vbNewLine & _
" <table align=""center"" width=""100%"" bgColor=""black"" border=""1"" style=""border-collapse:collapse;"" cellpadding=""4"" cellspacing=""1"">" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""2"" bgColor=""lightblue"">" & vbNewLine & _
" <font face=""arial"" size=""6"" color=""navy""><b>Number to String</b>" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""right"" width=""50%"" bgColor=""#D7954B"">" & vbNewLine & _
" <font face=""arial"" size=""4"" color=""#4F0F00"">Numeric Value: " & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""left"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
" <input type=""text"" name=""NValue"" value=""" & Request.Form("NValue") & """ size=""20"" maxlength=""10"">" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine
If strABC > "" Then
Response.Write " <tr valign=""middle"">" & vbNewLine & _
" <td align=""right"" width=""50%"" bgColor=""#D7954B"">" & vbNewLine & _
" <font face=""arial"" size=""4"" color=""#4F0F00"">Alpha Value: " & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""left"" width=""50%"" bgColor=""#FFFFFF"">" & strABC & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine
End If
Response.Write " </table>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" width=""100%"">" & vbNewLine & _
" <input type=""submit"" value=""Submit"">" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
"</form>" & vbNewLine
Response.End
Function NumberToABC(strF)
If strF = "" or IsNull(strF) Then
Exit Function
Else
txtABCWords = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
txtEquivalentReplace = "1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800"
If Instr(txtEquivalentReplace,strF) Then
intJ = 0: intK = 0
For intI = 1 to len(txtEquivalentReplace)
If mid(txtEquivalentReplace,intI,1) = "," Then
intJ=intJ+1
If mid(txtEquivalentReplace,intI+1,len(strF))=strF Then
intK=intJ
intL=(intK*2)+1
strABC = mid(txtABCWords,intL,1)
Exit For
End If
End If
Next
Else
Response.Write "Number not found."
End If
End If
End Function
%>
|
 |
|
sadra
Starting Member
Iran
30 Posts |
Posted - 04 September 2011 : 01:56:36
|
Tanx Mr "Carefree" for your try and your times |
[red]how soon is too late[/red] |
 |
|
|
Topic  |
|
|
|