I was trying to improve upon my existing code by creating a subroutine to replace code I used in every telephone number element and thought I could make use of the new command ThisElement released in version 1.0.4.
The code below was what I was using to properly format and control the data for a telephone number. // Formats Telephone Number (not Subroutine)
var vHPhone as String var vNewHPhone As String var vhphonecount var vhpnentered
Vhpnentered = @num(HomePhone) // Writeln(Vhpnentered) vhphonecount = @num(@len(vhpnentered)) //writeln(vhphonecount)
If vhphonecount = "10"
{ @color(HomePhone,0,7) vHPhone = @Num(HomePhone) vNewHPhone = "(" + @Left(vHPhone, 3) + ") " + @Mid(vHPhone, 4, 3) + "-" + @Right(vHPhone, 4) HomePhone = vNewHPhone } else { @color(HomePhone,7,1) @msgbox("The Telephone Number needs to be Exactly 10 Digits", "The numbers you entered " + @num(Homephone),"is : " + Vhphonecount + " Digits Please check Home Telephone and Re-enter") }
Originally I used this code in on element change on every telephone element by copying and changing the element name. I have since learned that the better method would be to create a subroutine or a function that will be called from each element. So I tried creating a subroutine (see below) It does not work.
// Formats Telephone Number with a Subroutine using ThisElement
Subroutine FormatPhone() // Name of Subroutine
// Declare Variables var vHPhone as String var vNewHPhone As String var vhphonecount var vhpnentered
// set Variables to empty var vHPhone = “” var vNewHPhone = “” var vhphonecount = “” var vhpnentered = “”
// Setting variable Vhpnentered to @num of element called from.
Vhpnentered = @num(ThisElement) // Writeln(Vhpnentered)
// Calculating number of digits vhphonecount = @num(@len(vhpnentered)) //writeln(vhphonecount)
// how to handle if or if not 10 digits
If vhphonecount = "10"
{ @color(ThisElement,0,7) vHPhone = @Num(ThisElement) vNewHPhone = "(" + @Left(vHPhone, 3) + ") " + @Mid(vHPhone, 4, 3) + "-" + @Right(vHPhone, 4) ThisElement = vNewHPhone } else { @color(ThisElement,7,1) @msgbox("The Telephone Number needs to be Exactly 10 Digits", "The numbers you entered " + @num(ThisElement),"is : " + Vhphonecount + " Digits Please check Home Telephone and Re-enter") }
End Subroutine
I placed this code in Global Code section
And in my telephone elements on element change I put FormatPhone()
I thought that this would call the subroutine named FormatPhone and pass the Element Name it was called from. I seem to be misunderstanding the correct method to create my subroutine
Can someone comfortable with Subroutines and functions please explain were I went wrong. Some of us are slow learners and need a little more help then others. (This shows the importance of the upcoming Sesame conference and Masters Seminar classes in October)
Thanks,
Robert
|