Initial disclaimers: The code presented here is not my own. My goal is to fill in some of the blanks when it comes to learning to create a simple report from a listbox in Xojo. There isn't a lot about Xojo out there and I feel the more information that is presented in various formats, the more likely people are discover the beauty of Xojo (formerly known as RealBasic or Real Studio).
Step 1:
Put something in the listbox! The code I used comes from here. I imported a csv file so I didn't need the code to write to the listbox, just to read it. As a result, I just skipped the write portion of the code. I also added a button called "Load" to the window and put this code under the Load action event.
Step 2:
Watch this video and read the Examples folder under Printing and Reporting. That's where the rest of my code came from. The Examples folder is in Xojo and you'll see it on the sidebar when Xojo first opens.
Step 3:
Under App, choose the appropriate window. Otherwise, you won't see anything. It's a small step and one I overlooked. I drove myself nuts trying to figure out why nothing was displaying as planned.
Step 4:
As one of my Xojo friends explained, if you have a Mac, you will be able to preview the report as a PDF. Pretty cool since that's mostly what you'll want to do - preview the pdf, email the pdf. But in Windows, that functionality isn't present and, unfortunately, it's still a work in progress in Xojo itself, although, high up on the to-do list. There are a couple of options, besides just literally printing out the entire report.
a) Use the Dyna plugin but it's not free. However, if you're creating an app to make money and not just for fun, it might be worth the cost. Like the Xojo license, it's not unreasonably priced.
b) Create your own pdf framework. This is outside my realm of knowledge.
c) Use OneNote. It came with my laptop on Windows 8 and I accidentally discovered that while I can't view the report as a pdf, I can view it in OneNote and that has the same effect. This isn't the prettiest report but it gives you an idea of what you can do. You'll see the Address and Subdivision fields from the report that are the column headings here. ***Note that the DataFields in the Inspector should use the same name as the original fields. The CSV report I used named the fields, "Address" and "Subd" and those are the names in the DataFields. In the text property in the Inspector, you can enter whatever text you want.
You can see how I put all the code together in GitHub. If anyone feels it would be useful, I will write down step-by-step what I did. It didn't seem necessary as I wouldn't have really added anything to the sources cited above. So unless I hear otherwise, Happy Reporting!
Sharing my journey as I go from knowing almost nothing to, hopefully, a whole lot more.
Monday, November 17, 2014
What I love about Xojo - Part 2: GUIs, Multiplatform, Databases
In the first part, I loved the fact that Xojo's online book explained caching. So simple yet so important and often overlooked by instructors. It made me think that the people behind Xojo really thought things through in the development process.
The other reason Xojo(fka RealBasic, Real Studio) is so lovable is that it makes difficult things simple.
While I have a thing for C#, creating GUIs in Windows Forms is a major pain. With Xojo, you drag and drop. Seriously, that's it. Drag and drop and go to the Inspector to set values for the properties. Then you can actually work on your code instead of spending a ton of time coding for the GUI. Listbox? No problem! Labels? No biggie!
Then there is the real reason for Xojo's existence in the first place - multiplatform. Do I love Apple? Not really. Am I planning to learn Objective-C? No. I'm a Windows kind of girl. But now I want to create an app for a friend who happens to use a Mac. What's the answer? Xojo. Write it in Xojo and it can be used on Windows, Linux or Mac. (If I ever find time to finish said app, I'll write about that.)
Last, but not least, the database. It's a mistake to think you can become a real programmer without loving the database life. SQLite is part of Xojo and you can actually create the database in Xojo using the insert menu. Feel free to do it programmatically, too.
I think Xojo is a great business solution for companies/individuals who have limited resources in terms of being able to write code for multiple operating systems and maintain that code. You do have to pay for the license to deploy your app, but you can build it for free to see how you like Xojo. The license is not unreasonably priced either. Check it out here.
The other reason Xojo(fka RealBasic, Real Studio) is so lovable is that it makes difficult things simple.
While I have a thing for C#, creating GUIs in Windows Forms is a major pain. With Xojo, you drag and drop. Seriously, that's it. Drag and drop and go to the Inspector to set values for the properties. Then you can actually work on your code instead of spending a ton of time coding for the GUI. Listbox? No problem! Labels? No biggie!
Then there is the real reason for Xojo's existence in the first place - multiplatform. Do I love Apple? Not really. Am I planning to learn Objective-C? No. I'm a Windows kind of girl. But now I want to create an app for a friend who happens to use a Mac. What's the answer? Xojo. Write it in Xojo and it can be used on Windows, Linux or Mac. (If I ever find time to finish said app, I'll write about that.)
Last, but not least, the database. It's a mistake to think you can become a real programmer without loving the database life. SQLite is part of Xojo and you can actually create the database in Xojo using the insert menu. Feel free to do it programmatically, too.
I think Xojo is a great business solution for companies/individuals who have limited resources in terms of being able to write code for multiple operating systems and maintain that code. You do have to pay for the license to deploy your app, but you can build it for free to see how you like Xojo. The license is not unreasonably priced either. Check it out here.
Thursday, November 6, 2014
Java - equals vs. ==
Finally, I found an article that explains this in terms that are understandable.
In a previous post, my explanation for C# reference type vs. value type is the difference between your painting ,which is an original masterpiece, getting destroyed (no more painting for anyone) and your painting, which is a print, getting destroyed (more copies can be made).
However, I still had trouble understanding the concept that underlies the issue here of when to use equals method instead of the == operator.
Here's a synopsis of the article:
In a previous post, my explanation for C# reference type vs. value type is the difference between your painting ,which is an original masterpiece, getting destroyed (no more painting for anyone) and your painting, which is a print, getting destroyed (more copies can be made).
However, I still had trouble understanding the concept that underlies the issue here of when to use equals method instead of the == operator.
Here's a synopsis of the article:
- == compares memory addresses.
- equals, as inherited from Object, does, too.
- If you want equals to compare data, then you have to override the equals method inherited from Object.
So that explains not only the difference (or similarity, as the case may be) between == and equals. It also explains that what is being compared is either the address or the data. Hence, in the example in the article, A == C //false because they have different memory addresses. But A.equals(D), once the equals method is overriden, is true because the data is being compared. Thank you, Kurt Mammen!
Friday, September 26, 2014
What I love about Xojo - Part I - Caching and optimization
Caching - Have you even done a programming exercise, in any language, and done something like this?
int x = array.length
int average = 10/x
Have you wondered why you didn't just do this?
int average = 10/array.length
Because they both work, but one requires more lines of code. Aren't we supposed to use as few lines of code as possible (within reason)?
The answer is explained in Xojo's book, Introduction to Programming, by Brad Rhine. On pages 89-90, Mr. Rhine explains that if you use a built-in function and you're using a loop, for example, the entire function has to run every time the loop iterates. If you assign the function to a variable, in other words, if you cache it, your app will speed up by accessing the value of the built-in function instead of running the function each iteration.
Seriously. To date, I've taken several programming classes and done some self-teaching and never has this been explained. See also this article that goes into a lot more depth.
Xojo gets the first thumbs up from me for explaining a common concept that should be explained in every intro class for any language.
int x = array.length
int average = 10/x
Have you wondered why you didn't just do this?
int average = 10/array.length
Because they both work, but one requires more lines of code. Aren't we supposed to use as few lines of code as possible (within reason)?
The answer is explained in Xojo's book, Introduction to Programming, by Brad Rhine. On pages 89-90, Mr. Rhine explains that if you use a built-in function and you're using a loop, for example, the entire function has to run every time the loop iterates. If you assign the function to a variable, in other words, if you cache it, your app will speed up by accessing the value of the built-in function instead of running the function each iteration.
Seriously. To date, I've taken several programming classes and done some self-teaching and never has this been explained. See also this article that goes into a lot more depth.
Xojo gets the first thumbs up from me for explaining a common concept that should be explained in every intro class for any language.
Tuesday, September 9, 2014
Break out of a sentinel-controlled loop in Java/C#
The issue is the same in Java and C# . To exit a loop with a sentinel-controlled value, you need a break statement.
Example:
while(someValue != "Q"){
//code for loop to execute while sentinel value not entered
if(someValue.equals("Q"){
break;//MUST USE THIS OR YOU WILL LOOP FOREVER
}
I think MSDN does a much better and simpler job explaining break. But I did manage to find some Oracle documentation that included code examples here.
In general, I am finding any documentation on Java to be spotty and not well written in the sense of not providing a substantive explanation with code examples. (Sorry to all the Java die-hards I offend.) In this case, you can see that MSDN uses one sentence to explain the break statement while the title of the Oracle documentation will make it difficult to even find this in a search using keyword "break".
The moral of the story: Java is a competitor to C# so they are very similar. If you can't find info on your Java issue, you might find it in MSDN and be able to apply it to Java.
Example:
while(someValue != "Q"){
//code for loop to execute while sentinel value not entered
if(someValue.equals("Q"){
break;//MUST USE THIS OR YOU WILL LOOP FOREVER
}
I think MSDN does a much better and simpler job explaining break. But I did manage to find some Oracle documentation that included code examples here.
In general, I am finding any documentation on Java to be spotty and not well written in the sense of not providing a substantive explanation with code examples. (Sorry to all the Java die-hards I offend.) In this case, you can see that MSDN uses one sentence to explain the break statement while the title of the Oracle documentation will make it difficult to even find this in a search using keyword "break".
The moral of the story: Java is a competitor to C# so they are very similar. If you can't find info on your Java issue, you might find it in MSDN and be able to apply it to Java.
Sunday, August 17, 2014
Python Classes and the__init__ method (not the _init_ method)
Can you tell the difference between "init"s in the title? It's hard to see and in some cases, impossible.
On Codecademy, you can't tell the difference between single and double underscores by looking at the screen. Only because of StackOverflow did I figure out the problem. If you don't believe StackOverflow, check out MIT's Python MOOC as well.
So what is __init__? Codecademy refers to it as a function and someone in StackOverflow differentiated between init as a method and a constructor. Call it whatever you want. In the Python documentation, it's referred to as a "special method" which initializes the object. In C#, that would be a constructor.
Unfortunately, I could not find any other documentation to highlight the fact that double underscores are required. If you search for this problem, you'll see many people have been hindered by this issue. For now, I'll accept that this is the way it is and I'll append a note to this post if I ever find anything official on the matter.
Saturday, August 2, 2014
Python, floating points and range()
MIT's MOOC, "A Gentle Introduction to Programming Using Python" has just taught me that Python's range() does not like integers. Actually, it didn't teach me this at all. The reading discussed getting a range of random floating points and then testing that function to determine how many times each random number occurred. The reading didn't say anything about not being able to use range() with floating points. I figured that out when I tried it myself and it didn't work.
Then, as usual, I hopped over to StackOverflow which was full of suggestions that I perceived to be too unduly complex for the reading. Plus, most of the solutions involved integers in range(). This is precisely what I was trying to avoid.
I am completely new to Python but I continue with my mission of making the unnecessarily complex discernable to newbies. Keep that in mind when you read my solution below.
The reading I refer to is here. I don't use those examples. Here are mine:
#first, get some random numbers
import random #kindof like "using" in C#
randList = [] # we'll need this list soon; make it empty for now
def randomness:
hi = 2.0
lo = 1.0
for i in range(10): #this will print out 10 random numbers
x = random.uniform(lo, hi)
#generates random floating point between the lo and hi range
randList.append(x) # this adds the value in x to the list
print randList
#test randomness() to see how many times each range of random numbers occur
def test(randList):
count = 0
for num in randList:
if num < 1.5: #I want to see how many numbers less than 1.5 are generated
count += 1
print ("There are/is"), count, ("occurrences of floating points less than 1.5.")
Call randomness() and then call test().
I will also post this in GitHub. More info on range() here.
Then, as usual, I hopped over to StackOverflow which was full of suggestions that I perceived to be too unduly complex for the reading. Plus, most of the solutions involved integers in range(). This is precisely what I was trying to avoid.
I am completely new to Python but I continue with my mission of making the unnecessarily complex discernable to newbies. Keep that in mind when you read my solution below.
The reading I refer to is here. I don't use those examples. Here are mine:
#first, get some random numbers
import random #kindof like "using" in C#
randList = [] # we'll need this list soon; make it empty for now
def randomness:
hi = 2.0
lo = 1.0
for i in range(10): #this will print out 10 random numbers
x = random.uniform(lo, hi)
#generates random floating point between the lo and hi range
randList.append(x) # this adds the value in x to the list
print randList
#test randomness() to see how many times each range of random numbers occur
def test(randList):
count = 0
for num in randList:
if num < 1.5: #I want to see how many numbers less than 1.5 are generated
count += 1
print ("There are/is"), count, ("occurrences of floating points less than 1.5.")
Call randomness() and then call test().
I will also post this in GitHub. More info on range() here.
Subscribe to:
Posts (Atom)
