Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String manipulation of calculation

Status
Not open for further replies.

theservant

Programmer
Aug 27, 2003
5
ZA
I have a textbox that have certain formulas which can change for example I have the following:

text1.text="ac123+af221*3-ag001"

I want to take a formula and seperate the string into different textboxes:
text2.text="ac123"
text3.text="+"
text4.text="af221"
text5.text="3"
text6.text="ag001"

Is there any way that this can be done
 
Look up the Left$, Mid$ and InStr functions. They will make it easy for you

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
theservant,

Put invisible Label1(0) label on your form below your formula txtFormula text box and leave enough space (sufficient for several labels) below that label.

Put Command button at the bottom of the form and copy this code:

Option Explicit

Private Sub Command1_Click()
Dim strTemplate As String
Dim intIndex As Integer
Dim intNumberOfLabels As Integer
Dim strElements() As String
Dim objLabel As Control

For Each objLabel In Me.Controls
If TypeName(objLabel) = "Label" Then
If objLabel.Index > 0 Then
Unload objLabel
End If
End If
Next objLabel

strTemplate = txtFormula.Text
strTemplate = Replace(strTemplate, "+", "@", , , vbBinaryCompare)
strTemplate = Replace(strTemplate, "-", "@", , , vbBinaryCompare)
strTemplate = Replace(strTemplate, "*", "@", , , vbBinaryCompare)
strTemplate = Replace(strTemplate, "/", "@", , , vbBinaryCompare)

strElements = Split(strTemplate, "@", , vbBinaryCompare)
intNumberOfLabels = UBound(strElements)

If intNumberOfLabels > -1 Then
Label1(0).Caption = strElements(0)
Label1(0).Visible = True
For intIndex = 1 To intNumberOfLabels
Load Label1(intIndex)
Label1(intIndex).Left = Label1(intIndex).Left
Label1(intIndex).Top = Label1(intIndex - 1).Top + Label1(intIndex - 1).Height + 100
Label1(intIndex).Caption = strElements(intIndex)
Label1(intIndex).Visible = True
Next intIndex
End If

End Sub

Private Sub Form_Load()
txtFormula.Text = "ac123+af221*3-ag001"
End Sub

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top