Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

580 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