?
Solved

I'm sure there is an easer way to ask this

Posted on 2003-02-23
9
Medium Priority
?
128 Views
Last Modified: 2010-05-01
Say I have some text in textbox1 e.g."10 Im 11 today". I then want to click on a command button, and the text goes to textbox2. but i also whant the command button to only read the first set of numbers e.g."10" and stops reading when it gets to the first space so textbox2 = "10" or what ever number is at the start of textbox1.
0
Comment
Question by:mangaman3000
[X]
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
9 Comments
 
LVL 4

Expert Comment

by:mcoop
ID: 8004433
It will probably help if you can explain what is in textbox1 at the start (as your posting came out with non-printable characters)

The basic practice is to identify a consistent, unique character/sequence at or near the boundary of the two fields you are trying to separate.

Then you can use functions like instr() and split() to separate the two halves with left() and mid()

What you do with them after that is relatively straightforward.

0
 

Author Comment

by:mangaman3000
ID: 8004467
can u read it now?
and also im new to vb can u give me a code, it will much appreciated.
0
 

Author Comment

by:mangaman3000
ID: 8004476
can u read it now?
and also im new to vb can u give me a code, it will much appreciated.
0
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!

 
LVL 1

Expert Comment

by:SilentRage
ID: 8004513
Private Sub Command1_Click()
Dim WordArray() As String
    'split the data into an array of words
    WordArray = Split(Trim(Text1.Text), " ")
    'the first word is the number or whatever you put in
    Text1.Text = WordArray(0)
End Sub
0
 
LVL 5

Accepted Solution

by:
Rhaedes earned 75 total points
ID: 8004514
Try this. I asume two textboxes (text1 and text2) and a commandbutton (Command1)

Private Sub Command1_Click()
Dim aChar As String
Dim goodChars As String
goodChars = "01234567890.," 'Contains all the acceptable characters
Text1.Text = Trim(Text1.Text) 'Remove leading spaces just in case
Text2.Text = "" 'Clear the target textbox

For n = 1 To Len(Text1.Text) 'Loop through the characters in Text1
aChar = Mid$(Text1.Text, n, 1) 'Take each in turn
If InStr(1, goodChars, aChar) = 0 Then Exit For 'Stop when you get to a bad character
Text2.Text = Text2.Text + aChar 'Copy the character across to Text2
Next n

End Sub


Kindest regards,
Rhaedes
0
 

Expert Comment

by:Abu_Obaid
ID: 8004566
'you can use this function to get the first number a string

Function GetNumber(Txt As String) As String
Dim strArry() As String
If Txt = "" Then
    GetNumber = ""
Else
    strArry = Split(Txt, " ", 2)
    If IsNumeric(strArry(0)) Then
        GetNumber = strArry(0)
    Else
        GetNumber = ""
    End If
End If
End Function

' to try this function add Text1, Text2 and Command1 to a standard for then use this code

Private Sub Command1_Click()
   Text2.Text = GetNumber(Text1.Text)
End Sub
0
 
LVL 4

Expert Comment

by:mcoop
ID: 8004762
Yes- more readable !!

I think the fellows above are helping you move in the right direction for code.

Last point to consider - if your source string format is always the same,  "## Im ## today"   a hard coded routine will do, but if your source strng is formatted in a number of ways, then you should adopt the smarter approach, and identify the required substrings first, then separate them.
0
 
LVL 3

Expert Comment

by:MCummings111400
ID: 8006021
Try this,

Const sDelim as String = " "

Text2.Text = Left(Text1.Text,InStr(Text1.Text,sDelim))
0
 
LVL 4

Expert Comment

by:mcoop
ID: 8006097
Try this -
one textbox, two listboxes
list1 gets all substrings
list2 only gets substrings with numeric values

Dim substr() As String
Private Sub Text1_Change()
  List1.Clear
  List2.Clear
  substr = Split(Text1, " ")
  For x = 0 To UBound(substr)
    List1.AddItem Trim(substr(x))
    If IsNumeric(substr(x)) Then
      List2.AddItem Trim(substr(x))
    End If
  Next
End Sub
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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

762 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