Combining Number In A String

Posted on 2003-03-19
Medium Priority
Last Modified: 2010-04-07
I am using a DTMF receiver connected to my parallel port to receive the tones generated by the phone. So far, when i press 1 on the phone, a 1 appears in the text box (txtNumIn). The same for 2-0.

What i would like to do is as i press the numbers 555-1212, i would like all the numbers to appear in the text box. What is happening now is 5 appears, then 5 then 5 the 2, 2, 2 and 2. I do not want the single numbers, i want all 7 to be grouped together and when the total numbers in the string reach 7 digits, for the string to stop accepting numbers and output the number to a .dat file.

So basically,

Group the dialed numbers in a string (show the digits being dialed in a text box) and when the total digits reah 7, export the data to a .dat file. I need the 7 numbers to be shown in the same text box together (555-1212) and not just 5, just 2, just 2 .......

Question by:markdude5988
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8169723
Not the best way, but wherever you are printing those numbers to the text box, use a variable instead. If the len is seven then print it out to a file or the textbox. Maybe something like this?:

'Put in Declarations
public spNum as string

'Put where you get Parrallel Port info
dim sInputChar as string

'sInputChar is input from parrallel port

'make sure we got something from p port
if len(trim(sInputChar)) > 0 then
    spNum = spNum & sInputChar 'input from p port

    if len(spNum) = 7 then
        'write to textbox
        txtout.text = spNum
        'Clear var and startover
        spNum = ""

    end if
end if


Expert Comment

ID: 8169833
my guess is when you receive the DTMF code, you are doing something like: textbox1.text = dtmfcode each time.

change it to:
textbox1.text = textbox1.text & dtmfcode

this will append the numbers as you get them.

Accepted Solution

DocM earned 300 total points
ID: 8170376

textbox1.text = textbox1.text & dtmfcode

Private Sub Text1_Change()
    If Len(Text1.Text) = 3 Then
        Text1.Text = Text1.Text & "-"
        Text1.SelStart = Len(Text1.Text)
    End If
    If Len(Text1.Text) = 8 Then
        AppendToFile (Text1.Text)
        Text1.Text = ""
    End If
End Sub

Sub AppendToFile(strText)
    FileNumber = FreeFile
    Open "C:\Filename.dat" For Append As FileNumber
    Print #FileNumber, strText
    Close FileNumber
End Sub


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question