Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

Yeah, being a software engineer is constant fight against obsolescence. I go to a lot of tech meetups to keep up on whats coming down the pipe. I learn well from books so I buy a lot of those (which you can write off btw), but everyone’s different. I know some guys who watch training videos or do online courses.

You could try making a simple little video game or something. It’s fun, the problems are interesting, and you might even end up with something you can put on the resume.

Cheers!

i am having trouble sorting an arraylist inside of the listbox. i have to sort stocks with their ticker symbol, price and price to earnings ratio. i also have to sort them in descending order when i check a checkbox, but when i click the sort button it sorts the stocks but cuts out what i am not sorting by (ie. sort by ticker, price and pe ratio get cut off). they do not get sorted in descending order when i check the checkbox either. this is in visual basic 2010

here’s how i’m trying to sort it


If chkDescend.Checked = True Then
            Dim query = From aStock In stockList
                Select aStock.Ticker
                Order By Ticker Descending
 
            ListBox1.DataSource = query.ToList()
        ElseIf chkDescend.Checked = False Then
            Dim query = From aStock In stockList
                Select aStock.Ticker
                Order By Ticker Ascending
 
            ListBox1.DataSource = query.ToList()
        End If

Edit: nevermind

Improve scripts. That’s a great start. The best thing to do is to first start with a simple program and make improvements to it, and.create more abstraction in your code. Or take pre written code which has a lot of hard coded value and try to find ways of hiding data in the code.

For example if I had a script that took server addresses in a list a ssh each address, you can find ways to find ways of indexing the list and substituting the values with variable.

First learn how to automate stuff you do manually. So think more like a sys admin/system engineer. Then learn how to make your scripts more open. Also optimization is a thing you can work on to make your code more efficient.

A good way to start is to find code with bugs, and learn how to debug. Then improve certain modules in code to get rid of the bugs. Once you start doing this you will find you’ll get your juices flowing.

Sent from my HTC VLE_U using Tapatalk 2

If you like games, try making simple ones. You don’t have to make anything original, just do what’s been done before. Try making a card game like poker or something.

Yo, I’ve got a sort-of relevant question…
I have an excel spreadsheet with a bunch of names and addresses, and an invitation in a word document. I need to print out invitations to an event, and have it insert the correct name/address in each invitation. How can I do this without copypasta all 200+ invitations?

Cheers!

Looks like you’d want to use WordprocessingML (http://msdn.microsoft.com/en-us/library/office/aa212812(v=office.11).aspx), which basically lets you create an XML document that word parses into a .doc

I’d think if you created a template, and just leave content controls as markers, you could just iterate through the document and populate all the names/addresses and save

public int getItemsPerBox(String itName){
[INDENT=1]int itPerBox=0;[/INDENT]

[INDENT=1]if(itName.equalsIgnoreCase(“Yoyo”))[/INDENT]
[INDENT=1]{[/INDENT]
[INDENT=2]itPerBox = 32;[/INDENT]
[INDENT=3]if(itName.equalsIgnoreCase(“Puzzle”))[/INDENT]
[INDENT=3]{[/INDENT]
[INDENT=4]itPerBox = 10;[/INDENT]
[INDENT=3]}[/INDENT]
[INDENT=4]else{[/INDENT]
[INDENT=5]if(itName.equalsIgnoreCase(“Top”))[/INDENT]
[INDENT=5]{[/INDENT]
[INDENT=6]itPerBox = 100;[/INDENT]
[INDENT=5]}[/INDENT]
[INDENT=6]else[/INDENT]
[INDENT=6]{[/INDENT]
[INDENT=7]itPerBox = 12;[/INDENT]
[INDENT=6]}[/INDENT]
[INDENT=5]}[/INDENT]
[INDENT=1]}[/INDENT]

return itPerBox;
}

did I do this nested if-else statement right?

From what I see, itperbox =12 occurs if top isn’t found, was that for if yoyo wasn’t found?

Sent from my SPH-D700 using Tapatalk 2

Since all that your doing is just assigning a value to the variable itPerBox after a condition is met, I would use trailing else-if’s. Logically that may work but else-if’s ended with an else looks a lot neater. Like
if condition {
//do stuff
} else if this condition{
//do more stuff
} else if this condition {
//do this stuff
}else {
//do this stuff
}

return your stuff

But like king9999 told me a while back if, you got too many of these, you need to use a loop and array.

No, because if you pass anything in other than yoyo, you’ll get 0 as the output

From what I can see, the if-else statements shouldn’t be nested. And like Pimp Willy said, the only results you can ever get from this code is 0 or 32…those nested statements will never be true.

As a general rule of thumb, if you ever find yourself nesting your code like this, chances are you can write it better somehow. Nested code gets ugly quickly.

yeah, I just assumed it was some sort of assignment to learn nested if/elses. Nested If/Elses generally can be written better. In this case, the nested if/elses are entirely pointless

Would switch-case work there too?

Yeah, switch-case would also work, though I think you would have to change itName to lowercase beforehand. You can’t use switch statements to test a boolean expression (I think).

Yeah a switch is pretty much exactly for what this sort of thing was created for, a long list of if elses

some languages only allow switch-case to be used on primitive types such as chars or ints, though. what language are you using?

Isn’t that java or C#?

judging by the functions in String used there, yeah its java. so a switch statement would be best

Job posting caught my eye, not that I’d do it, but…
http://www.linkedin.com/jobs?viewJob=&jobId=4071949&trk=rj_em&ut=0FltFAcmW18lw1

So I’m reading, ‘scripting, technical writing, C/C++, formal methods, blah blah blah,
**proficiency with Prolog **’

Seriously?

OK guys, I need some web development help. Apparently my site is messed up, so I need some help figuring out what’s wrong.

First of all, take a look at my site: http://mmking9999.com. The issue appears to be with the text. I’m going to show the code that I used to make the page, and I want some web experts to help me figure out what I’m doing wrong. Actually, if there’s any other issues that you notice, point it out to me. I’m not a pro at web development.

main page

Spoiler


<!-- Web home page by Mike Murray-->
<!-- This is the home page for my mmking9999 site.  My goal is to design the site as if was a menu from a video game.-->
<!-- I would like to have a scrolling background, but if it eats up CPU resources then I will abandon the idea. -->
 
<html>
<head>
<link rel="stylesheet"
type="text/css" href="http://mmking9999.com/css/style.css" />
 
</head>
<body>
 
<!--Site logo. Clicking on it will redirect to this page.-->
<div class="logo">
<a href="http://mmking9999.com/"><img src="http://mmking9999.com/Images/SiteLogo.png" /></a>
</div>
 
<!-- Menu window goes here. The text are images that link to other pages.-->
 
<div class="menu">
<img src="http://mmking9999.com/Images/MenuWindow.png" />
</div>
 
 
<div class="portfolio_url">
<a href="http://mmking9999.com/portfoliopage.html"><img src="http://mmking9999.com/Images/portfoliourl.png"  /></a>
</div>
 
<div class="blog_url">
<img src="http://mmking9999.com/Images/blogurl.png"  />
</div>
 
<div class="random_url">
<a href="http://mmking9999.com/randomstuff.html"><img src="http://mmking9999.com/Images/randomurl.png"  /></a>
</div>
 
<div class="email">
<a href="mailto:mmking9999@gmail.com" target="_blank"><img src="http://mmking9999.com/Images/emailicon.png"  /></a>
</div>
 
<div class="linkedin">
<a href="http://ca.linkedin.com/in/mikeadmurray" target="_blank"><img src="http://mmking9999.com/Images/linkedinicon.png"  /></a>
</div>
 
<div class="twitter">
<a href="http://twitter.com/MikeADMurray" target="_blank"><img src="http://mmking9999.com/Images/twittericon.png"  /></a>
</div>
 
 
<div class="window"><br><br><p>Welcome to my website!  My name is Mike Murray, a rookie game developer/designer. Here, you'll find stuff about what I do and what I hope to become in the future.  I am an avid gamer, and it was that passion that led me to want to create the video games that people like to play.  Having played video games for over 20 years, I figure I should be able to create something cool with the knowledge I have!</p></div>
 
</body>
</html>
 
 


CSS

Spoiler


/*The code for the body sets the default settings for all pages */
body 
{
background-image:url('http://mmking9999.com/Images/sitewallpaper.png');
}
 
/* Link colours. I use bright colours to contrast the black window. */
a:link {
COLOR: #86C6FE;
}
a:visited {
COLOR: #FF0000;
}
a:hover {
COLOR: #FFFF00;
}
a:active {
COLOR: #00FF00;
}
 
/* Main window. Used to display text and images */
img
{
margin: 2px;
height: auto;
width: auto;
float: left;
}
 
h1
{
color:red;
text-align:center;
font-family:calibri;
}
 
p
{
/* font */
color:rgb(255,255,255);
font-family:"Small Fonts", calibri, arial, "Times New Roman";
font-size:18px;
text-align:left; width:700px; margin-left:200px;
}
 
/* Main window. All info is displayed in here */
div.window
{
background-image:url('http://mmking9999.com/Images/IframeWindow.png');
background-repeat:no-repeat;
position:relative;
width:60%;
height:70%;
top:80px;
left:500px;
 
/*text*/
/*color:rgb(255,255,255);
font-family:"Small Fonts", calibri, arial, "Times New Roman";
font-size:18px;*/
 
}
 
/* Menu */
div.menu
{
position:relative;
width:40%;
height:10%;
}
 
/*Site logo */
div.logo
{
position:relative;
width:40%;
height:5%;
left:500px;
}
 
/*Images (so they aren't constrained by the attributes defined in div.window)*/
div.image
{
position:absolute;
left:20px;
}
 
/* In case I need another row of images */
div.image2
{
position:relative;
left:-150px;
width:90%;
height:90%;
}
 
/*Menu urls*/
div.portfolio_url
{
position:relative;
left:-175px;
top:30px;
}
 
div.blog_url
{
position:relative;
left:-305px;
top:90px;
}
 
div.random_url
{
position:relative;
left:-445px;
top:150px;
}
 
div.email
{
position:relative;
top:250px;
left:-600px;
}
 
div.linkedin
{
position:relative;
top:250px;
left:-580px;
}
 
div.twitter
{
position:relative;
top:250px;
left:-560px;
}
 
/*iframe
{
 
position:relative;
top:80px;
left:280px;
width:60%; height:70%;
}*/