Formatting a Textbox to Currency

Started by Gary Stout, January 11, 2015, 03:09:21 AM

Previous topic - Next topic

Gary Stout

Trying to figure out why one of these works and the other doesn't  ???

I have always had better luck using FORMAT$ to get the desired results for currency, but when I try entering 100, the text set to the textbox is always 100 instead of 100.00
             
        FF_TextBox_SetText(Form1.Text1.hWnd, Format$(Val(Trim$(FF_TextBox_GetText(Form1.Text1.hWnd), "#.00"))))


Now, if I use the same formatting with the USING$ command, when I enter 100, the text is set to 100.00.


        FF_TextBox_SetText(Form1.Text1.hWnd, Using$("#.00",Val(Trim$(FF_TextBox_GetText(Form1.Text1.hWnd)))))


Not sure if I am missing something or what is going on. I have used FORMAT$ in many other programs and have never noticed any issues.

David Kenny

#1
Your arguments don't line up properly :)
Try this:FF_TextBox_SetText(Form1.Text1.hWnd, Format$(Val(Trim$(FF_TextBox_GetText(Form1.Text1.hWnd))), "#.00"))

Edited 2 times:I had also included what I thought was happening, but it didn't match the results.  My explanation said it should have changed the "100" to "1"

Gary Stout


David,

Thanks!!! Right you are....I have stared at those lines over and over and just didn't see any problems jumping out. I guess I am surprised the compiler didn't have an issue trying to trim a string with a comma in it. It's easy to do when there are that many sets of parentheses  ???

Thanks again...
Gary

David Kenny

Well, I concluded that the way you had it, the argument "#.00" was actually going to the trim$ (which has an optional string CharsToTrim$).  The Format$ command's fmt$ is also optional, meaning it would compile fine.  But the output from it should have been "1" instead of "100" because the trim$ command should have removed all the zero's (as well as all # and .(periods)).  I didn't spend any more time trying to figure why it compiled and produced the results it does.

If FF had the feature some other editors have of highlighting matching parenthesis, this type of problem would be much more easy to avoid.  I'm not sure if I've seen anyone ask for this feature. 

Gary Stout

Thanks David and Paul,

So far after a few little glitches like this one, I am making good progress on the re-write! Things are definitely getting easier. I really like having the designer and editor all integrated versus the way I use to do things....make changes in visual editor, copy, paste to IDE. I have been shielded from the API for so long, that the thought of trying to learn something new was daunting...but for some reason, it seems easier this time around.

Gary