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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO I ADD TEXTBOX CONTENTS SO THEY DO NOT CONCATENATE?

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
US
I HAVE A USER FORM THAT I NEED TO ADD THE NUMBERS IN THE TEXT BOXES TO FORM A REAL NUMBER THAT IS PLACED IN A DIFFERENT TEXTBOX. THE PROBLEM IS IF I HAVE A NUMBER 2 IN ONE TEXBOX AND 5 IN THE OTHER THE DISPLAYED RESULT IS 25 NOT 7. HOW DO I FORMAT THIS TO FUNCTION PROPERLY? THE NUMBERS ARE ATTRIBUTES RETRIEVED FROM AN AUTOCAD BLOCK.
 
Hi,

Is this all done in VBA? Is the form a VBA userform?

What have you got for the code, please post a sample so I can see what's going on or not!!



Cheers,

Paul @ basepoint designz..


basepoint designz
renegade@bpdesignz.com
 
i have include the entire vba code. the form is a vba userform. thanks for the help, this is probably basic for you, i am an amature. this is the start of the code.

Public acad As Object
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public theatts As Variant
Public MsgBoxResp As Integer
'declare global variables


Sub UpdateAttrib(TagNumber As Integer, BTextString As String)
'This Sub Procedure tests the attribute data to check
'that is not a null value

If BTextString = "" Then
'if the attribute is empty

theatts(TagNumber).TextString = ""
'put a '-' place holder

Else
'if it is not empty

theatts(TagNumber).TextString = BTextString
'use the attribute value

End If

End Sub






Private Sub Label1_Click()

End Sub


Private Sub UserForm_Initialize()
Dim BlkG(0) As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
'declare local variables


Set acad = GetObject(, "AutoCAD.Application")
'set reference to AutoCAD

Set doc = acad.ActiveDocument
'set reference to the drawing

Set ms = doc.ModelSpace
'set reference to model space

Set ssnew = doc.SelectionSets.Add("TBLK")
'create a selection set
ssnew.SelectOnScreen

Pt1(0) = 0: Pt1(1) = 0: Pt1(2) = 0
Pt2(0) = 3: Pt2(1) = 3: Pt2(2) = 0
'set up the array

BlkG(0) = 2
'group code 2 for block name


ssnew.Select 5, Pt1, Pt2, BlkG, TheBlock
'get the block

If ssnew.Count >= 1 Then
'if the block is found

theatts = ssnew.Item(0).GetAttributes
'get the attributes

UserForm1.txt1.Text = UCase(LTrim(theatts(0).TextString))
'get the title attribute
'clear any leading spaces and
'convert to uppercase

UserForm1.txt0.Text = UCase(LTrim(theatts(0).TextString))
UserForm1.txt1.Text = UCase(LTrim(theatts(1).TextString))
UserForm1.txt2.Text = UCase(LTrim(theatts(4).TextString))
UserForm1.txt3.Text = UCase(LTrim(theatts(5).TextString))
UserForm1.txt4.Text = UCase(LTrim(theatts(8).TextString))
UserForm1.txt5.Text = UCase(LTrim(theatts(9).TextString))
UserForm1.txt6.Text = UCase(LTrim(theatts(12).TextString))
UserForm1.txt7.Text = UCase(LTrim(theatts(13).TextString))
UserForm1.txt8.Text = UCase(LTrim(theatts(16).TextString))
UserForm1.txt9.Text = UCase(LTrim(theatts(17).TextString))
UserForm1.txt10.Text = UCase(LTrim(theatts(20).TextString))
UserForm1.txt11.Text = UCase(LTrim(theatts(21).TextString))
UserForm1.txt12.Text = UCase(LTrim(theatts(24).TextString))
UserForm1.txt13.Text = UCase(LTrim(theatts(25).TextString))
UserForm1.txt14.Text = UCase(LTrim(theatts(28).TextString))
UserForm1.txt15.Text = UCase(LTrim(theatts(29).TextString))
UserForm1.txt16.Text = UCase(LTrim(theatts(32).TextString))
UserForm1.txt17.Text = UCase(LTrim(theatts(33).TextString))
UserForm1.txt18.Text = UCase(LTrim(theatts(36).TextString))
UserForm1.txt19.Text = UCase(LTrim(theatts(37).TextString))
UserForm1.txt20.Text = UCase(LTrim(theatts(40).TextString))
UserForm1.txt21.Text = UCase(LTrim(theatts(41).TextString))
UserForm1.txt22.Text = UCase(LTrim(theatts(2).TextString))
UserForm1.txt23.Text = UCase(LTrim(theatts(3).TextString))
UserForm1.txt24.Text = UCase(LTrim(theatts(6).TextString))
UserForm1.txt25.Text = UCase(LTrim(theatts(7).TextString))
UserForm1.txt26.Text = UCase(LTrim(theatts(10).TextString))
UserForm1.txt27.Text = UCase(LTrim(theatts(11).TextString))
UserForm1.txt28.Text = UCase(LTrim(theatts(14).TextString))
UserForm1.txt29.Text = UCase(LTrim(theatts(15).TextString))
UserForm1.txt30.Text = UCase(LTrim(theatts(18).TextString))
UserForm1.txt31.Text = UCase(LTrim(theatts(19).TextString))
UserForm1.txt32.Text = UCase(LTrim(theatts(22).TextString))
UserForm1.txt33.Text = UCase(LTrim(theatts(23).TextString))
UserForm1.txt34.Text = UCase(LTrim(theatts(26).TextString))
UserForm1.txt35.Text = UCase(LTrim(theatts(27).TextString))
UserForm1.txt36.Text = UCase(LTrim(theatts(30).TextString))
UserForm1.txt37.Text = UCase(LTrim(theatts(31).TextString))
UserForm1.txt38.Text = UCase(LTrim(theatts(34).TextString))
UserForm1.txt39.Text = UCase(LTrim(theatts(35).TextString))
UserForm1.txt40.Text = UCase(LTrim(theatts(38).TextString))
UserForm1.txt41.Text = UCase(LTrim(theatts(39).TextString))

UserForm1.txt1.SetFocus
UserForm1.txt1.SelStart = 0
UserForm1.txt1.SelLength = Len(UserForm1.txt1.Text)
'set the focus to the drawing title and highlight it

'fill the block with the attribute values

UserForm1.totala.Text = UserForm1.txt0.Text + UserForm1.txt1.Text
UserForm1.totalb.Text = 4 + 4
UserForm1.totalkw.Text = 5 + 5
UserForm1.totalamp.Text = 6 + 6

'retrieve the calculated attribute values

Set axlapp = Nothing
'clean up

UpdateAttrib 0, UserForm1.txt0.Text
UpdateAttrib 1, UserForm1.txt1.Text
UpdateAttrib 4, UserForm1.txt2.Text
UpdateAttrib 5, UserForm1.txt3.Text
UpdateAttrib 8, UserForm1.txt4.Text
UpdateAttrib 9, UserForm1.txt5.Text
UpdateAttrib 12, UserForm1.txt6.Text
UpdateAttrib 13, UserForm1.txt7.Text
UpdateAttrib 16, UserForm1.txt8.Text
UpdateAttrib 17, UserForm1.txt9.Text
UpdateAttrib 20, UserForm1.txt10.Text
UpdateAttrib 21, UserForm1.txt11.Text
UpdateAttrib 24, UserForm1.txt12.Text
UpdateAttrib 25, UserForm1.txt13.Text
UpdateAttrib 28, UserForm1.txt14.Text
UpdateAttrib 29, UserForm1.txt15.Text
UpdateAttrib 32, UserForm1.txt16.Text
UpdateAttrib 33, UserForm1.txt17.Text
UpdateAttrib 36, UserForm1.txt18.Text
UpdateAttrib 37, UserForm1.txt19.Text
UpdateAttrib 40, UserForm1.txt20.Text
UpdateAttrib 41, UserForm1.txt21.Text
UpdateAttrib 2, UserForm1.txt22.Text
UpdateAttrib 3, UserForm1.txt23.Text
UpdateAttrib 6, UserForm1.txt24.Text
UpdateAttrib 7, UserForm1.txt25.Text
UpdateAttrib 10, UserForm1.txt26.Text
UpdateAttrib 11, UserForm1.txt27.Text
UpdateAttrib 14, UserForm1.txt28.Text
UpdateAttrib 15, UserForm1.txt29.Text
UpdateAttrib 18, UserForm1.txt30.Text
UpdateAttrib 19, UserForm1.txt31.Text
UpdateAttrib 22, UserForm1.txt32.Text
UpdateAttrib 23, UserForm1.txt33.Text
UpdateAttrib 26, UserForm1.txt34.Text
UpdateAttrib 27, UserForm1.txt35.Text
UpdateAttrib 30, UserForm1.txt36.Text
UpdateAttrib 31, UserForm1.txt37.Text
UpdateAttrib 34, UserForm1.txt38.Text
UpdateAttrib 35, UserForm1.txt39.Text
UpdateAttrib 38, UserForm1.txt40.Text
UpdateAttrib 39, UserForm1.txt41.Text
UpdateAttrib 42, UserForm1.totala.Text
UpdateAttrib 43, UserForm1.totalb.Text
UpdateAttrib 44, UserForm1.totalkw.Text
UpdateAttrib 45, UserForm1.totalamp.Text


'get the attribute values

ssnew.Item(0).Update
'update the attribute block
ssnew.Delete
'removes the selection set
End
Else
'if no attribute title block is found

MsgBox "Sorry - No Material List Attributes....", vbCritical, "Panel A not in drawing"
'inform the user that there is no attribute title block
ssnew.Delete
End
'end the application

End If
End Sub
 
Hi,

I take it this......

Code:
'fill the block with the attribute values
UserForm1.totala.Text = UserForm1.txt0.Text + UserForm1.txt1.Text
Code:
UserForm1.totalb.Text = 4 + 4
UserForm1.totalkw.Text = 5 + 5
UserForm1.totalamp.Text = 6 + 6

.....is the line that's giving you trouble??

I'm not sure if this will work but try using the .value property of the textbox instead of the .text property. It should handle the textbox content differently.....like this......

[/code]UserForm1.totala.Value = UserForm1.txt0.Value + UserForm1.txt1.Value
Code:
Or better still, assign three variables; 2 for the two value textbox results and 1 for the total..

ie: [code]
Dim Main_Total, resultA, resultB  as double
' Calculate variables..
resultA = UserForm1.txt0.Value
resultB = UserForm1.txt1.Value
' Get total..
Main_Total = resultA + resultB

Just insert this bit instead of the line....

Code:
UserForm1.totala.Text = UserForm1.txt0.Text + UserForm1.txt1.Text[code]


I know it's a bit obvious but I hope it helps..



     Cheers,

           Paul @ [b]basepoint designz[/b]..


[b]basepoint designz[/b]
renegade@bpdesignz.com
 
the .value did not work but this code did.

Dim Main_Total, resultA, resultB as double
' Calculate variables..
resultA = UserForm1.txt0.Value
resultB = UserForm1.txt1.Value
' Get total..
userform1.totala.value = resultA + resultB

next question. i need to add 23 numbers to place in the userform1.totala.value textbox. do i need to set up resultA, resultB, resultC....etc?
 
Change this:

UserForm1.totala.Text = UserForm1.txt0.Text + UserForm1.txt1.Text


To This:

UserForm1.totala.Text = val(UserForm1.txt0.Text) + val(UserForm1.txt1.Text)

You should also check to make sure the values in the textbox are numeric (IsNumeric).

Good Luck,

Scott
 
can i add a public statement to check if all of the attributes are numeric? I have been trying to add an IF THEN ELSE statement to check if the attribute equals "-". i want it to place the dash if the placeholder if it is blank. and the dash needs to be treated as if it was equal to zero.
 
i have the dashes working properly now. i added another sub routine to take care of that problem. Is there a simple way to add a range of the numbers together to get the total in the totala textbox. Do i have to put in the code like this?UserForm1.totala.Text = val(UserForm1.txt0.Text) + val(UserForm1.txt1.Text)+ val(user form1.txt2.text)+ ....etc? is there a range function i am missing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top