Results 1 to 5 of 5

Thread: code help

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    3

    code help

    Hey,

    I'm new here and am just starting to get into Visual Basic programming. Right now I'm using VB.net and I have a question about some code.

    I'm trying to make a program that the user types in their phone number like: (414) 555-5555. They then press a button and their area code, 414, not (414), goes into another text box. Any help with this is much appreciated.

  2. #2
    Lively Member hbandarra's Avatar
    Join Date
    Aug 2002
    Location
    Lisbon, PT
    Posts
    66

    Red face like this?

    Now protect your code from erroneous tiping:

    Code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Windows Form Designer generated code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
    
        End Sub
    
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents TextBox_Number As System.Windows.Forms.TextBox
        Friend WithEvents TextBox_Input As System.Windows.Forms.TextBox
        Friend WithEvents TextBox_Area As System.Windows.Forms.TextBox
        Friend WithEvents Button_Accept As System.Windows.Forms.Button
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents Label3 As System.Windows.Forms.Label
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.TextBox_Number = New System.Windows.Forms.TextBox()
            Me.TextBox_Input = New System.Windows.Forms.TextBox()
            Me.TextBox_Area = New System.Windows.Forms.TextBox()
            Me.Button_Accept = New System.Windows.Forms.Button()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.SuspendLayout()
            '
            'TextBox_Number
            '
            Me.TextBox_Number.Location = New System.Drawing.Point(232, 8)
            Me.TextBox_Number.Name = "TextBox_Number"
            Me.TextBox_Number.ReadOnly = True
            Me.TextBox_Number.TabIndex = 0
            Me.TextBox_Number.Text = ""
            '
            'TextBox_Input
            '
            Me.TextBox_Input.Location = New System.Drawing.Point(136, 48)
            Me.TextBox_Input.Name = "TextBox_Input"
            Me.TextBox_Input.TabIndex = 1
            Me.TextBox_Input.Text = ""
            '
            'TextBox_Area
            '
            Me.TextBox_Area.Location = New System.Drawing.Point(48, 8)
            Me.TextBox_Area.Name = "TextBox_Area"
            Me.TextBox_Area.ReadOnly = True
            Me.TextBox_Area.TabIndex = 2
            Me.TextBox_Area.Text = ""
            '
            'Button_Accept
            '
            Me.Button_Accept.Location = New System.Drawing.Point(256, 48)
            Me.Button_Accept.Name = "Button_Accept"
            Me.Button_Accept.TabIndex = 3
            Me.Button_Accept.Text = "Accept"
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(8, 8)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(40, 16)
            Me.Label1.TabIndex = 4
            Me.Label1.Text = "Area:"
            '
            'Label2
            '
            Me.Label2.Location = New System.Drawing.Point(176, 10)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(56, 16)
            Me.Label2.TabIndex = 5
            Me.Label2.Text = "Number:"
            '
            'Label3
            '
            Me.Label3.Location = New System.Drawing.Point(8, 48)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(128, 16)
            Me.Label3.TabIndex = 6
            Me.Label3.Text = "Type your number here:"
            '
            'Form1
            '
            Me.AcceptButton = Me.Button_Accept
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(368, 85)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.Label2, Me.Label1, Me.Button_Accept, Me.TextBox_Area, Me.TextBox_Input, Me.TextBox_Number})
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
    
        Private Sub Button_Accept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Accept.Click
            Me.TextBox_Area.Text = Me.TextBox_Input.Text.Substring(Me.TextBox_Input.Text.IndexOf("(") + 1, Me.TextBox_Input.Text.IndexOf(")") - Me.TextBox_Input.Text.IndexOf("(") - 1)
            Me.TextBox_Number.Text = Me.TextBox_Input.Text.Substring(Me.TextBox_Input.Text.IndexOf(")") + 1)
        End Sub
    End Class

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    3

    r u sure

    Are you sure it's that complicated? Can't you just use strings?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Code:
    Private Sub Button_Accept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Accept.Click
            Me.TextBox_Area.Text = Me.TextBox_Input.Text.Substring(Me.TextBox_Input.Text.IndexOf("(") + 1, Me.TextBox_Input.Text.IndexOf(")") - Me.TextBox_Input.Text.IndexOf("(") - 1)
            Me.TextBox_Number.Text = Me.TextBox_Input.Text.Substring(Me.TextBox_Input.Text.IndexOf(")") + 1)
        End Sub
    this is from Hbandarra's post .You should Thank him.
    bye

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    3

    thanks

    Thanks for your help guys, especially hbandarra

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width