No question that Applescript can be frustrating to learn. Many things about it have to be figured out by trial and error and when dealing with scripting applications all bets are off. The application designer can pretty much do as they want so what works in one app might not work in another even though you are using the same and correct applescript 😕
I find Introduction to AppleScript Language Guide by Apple to be a good source of answers and usually always have it open when I'm scripting for quick reference.
Spend some time getting familiar with the script editor. It is intelligent and can usually steer you in the right direction when it comes to debugging. Especially get use to and pay attention to the colors it assigns to items in your script.
For example in your original script notice the colors of Button_Returned and CompanyName (your variables) and compare those to result and button returned. Also notice how text returned is a different color from button returned even though both are essentially the same thing. This is an indication that something is not right and it is where the error message occurred. (for a list of the default colors used open the Script Editors preferences and look at the Formatting tab).
Notice also how the editor formats your scripts, again the way the script gets formatted can tell you a lot if there is an error.
Finally the error messages while cryptic can offer some clues. In your case the error message was
error "Can’t get text returned of \"Company\"." number -1728 fromtext returnedof "Company"
generated by the line
setCompanyNametotext returnedoftheresult
The last part of the error message is essentially the line that caused the error after evaluation. So here result evaluated to “Company” which doesn't seem right, display dialog returns a record.
Finally there is the log statement which will print its value to the log window
Hope this helps
regards