Hi Been trying for 5 hours now. Lots of tries from things on various places. I have database. Table and forms. on form is a cPoints text box set to integer Have another text box txt_AddRemove set to integer. Need to take the value from txt_AddRemove and add it to cPoints with the push of a button.

this is what I got.

REM  *****  BASIC  *****

Sub Main ( Event as Object )
rem MsgBox "You pressed Me!"

DIM oForm as Object
DIM oField as object
DIM oPointsField as object
DIM oTotalPoints as object

'gets the form
oForm = Event.Source.Model.Parent

' oField.Text = "500"

oPointsField = oForm.getByName("cPoints")

oTotalPoints = oField + oPointsField

oPointsField.Text =  oTotalPoints

oPointsField.commit()

End Sub


first error only in debug oForm = Event.Source.Model.Parent Argument is not optional.

when running by clicking on button oTotalPoints = oField + oPointsField incorrect property value

tried to find convert text to int and int to text. cannot find anything.

if I can get this working I am done.

Thanks all

Not sure how to reply to a comment on my post

Can you not convert text to int, then add, then convert to text. Also all boxes are integers. Can I not pull the value off as an integer.

(Slighly edited by @Lupp for better readability.)

edit retag close merge delete

Text = "500"

While it might be possible (I don't know), in principle it is not advisable to do arithmatic on text. A bit like checking numbers for literary expression. Can you find a different approach?

( 2020-01-24 16:56:01 +0200 )edit

@Michellia: Please use the tool 'preformatted text' for code.
Please anwer to questions in return posted correctly using 'add a comment' using the same feature.

This is not a forum supporting ongoing discussions post after post, but a Q&A site.

( 2020-01-24 18:55:06 +0200 )edit

Sort by » oldest newest most voted

Hello,

Edit: Not to step on answer by @Lupp, but you also need to retrieve the values and not use the object.

End Edit

Sub Main ( Event as Object )
DIM oForm as Object
DIM oField as object
DIM oPointsField as object
DIM oTotalPoints as object
DIM iPoints as Integer
oForm = Event.Source.Model.Parent
oPointsField = oForm.getByName("cPoints")
iPoints = oPointsField.Text
oPointsField.commit()
End Sub


Basic does convert text to integer fairly well provided the data is actually a number. You, however were trying to do math with an object. Instead you first need to retrieve the data into a proper variable. Once you have this add them and then place back into wanted control.

Instead of text boxes, for this type of functionality you should be using a numeric control and retrieving the "Value". Much safer process.

more

Grummel... I have to adtmit that I hadn't read the code posted in the question thoroughly. Should have done.

( 2020-01-24 22:30:07 +0200 )edit

Happens to all of us. I have certainly been guilty of this enough times. :)

( 2020-01-24 22:50:25 +0200 )edit

If the numbers you got as texts are in correct syntax (using decimal digits and everything) you can use the appropriate conversion function CInt() or CDbl() to get the value. (These functions are buggy concerning the + as positive sign. So also is IsNumeric().)
You may also rely on the automatic conversion using expressions like
theValue = 0 + theText where text needs to be a string of correct number syntax.
(Make sure NOT to write "0" there. It would make the "+" interpreted as a concatenation operator. Yes. this Basic is sometimes really silly. Always use & for concatenation to disambiguate.)
Trying theSum = theText1 + theText2 would also concatenate instead of doing arithmetic.
Best you explicitly Dim a varibale for the result As Long or As Double and assign the expression to it in advance of passing the result to the next step. Either automatic conversion works then as expected, or you get an error message and will know what changes are needed.

more

Can you not convert text to int, then add, then convert to text. Also all boxes are integers. Can I not pull the value off as an integer.

more