• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Slavik81

Member
Hmm... the inability to seamlessly cast a C++ std::function or lambda expression into a C-style function pointer is legitimately problematic. Really limits the ability to abstract away callbacks, since the only way to do the cast effectively is to abuse static variables.

Oh well. Maybe in C++2x.
mBEbGgn.png


/blog
I don't think that would generally even be possible. std::function has a dynamic, runtime value. C functions are static, compile-time values. You could do it easily with self-modifying code, but I don't think that's allowed by modern systems.
 
I don't think that would generally even be possible. std::function has a dynamic, runtime value. C functions are static, compile-time values. You could do it easily with self-modifying code, but I don't think that's allowed by modern systems.
C++ would have to address it via clever hackery in the standard that abstracts the pain and sadness away.

I don't have anything in mind for that at the moment, but my own hackery will be to make the class where the statics live a template, so if I need multiple instances I can spin up a different home for them.
 
Okay, Programming GAF. Trying to split a list by even/odd numbers here is what I have so far. I have been using the Standard Template Library to build the list. The problem is the odds print yet the evens don't. Any tips??

Code:
#include <iostream>
#include <list>
using namespace std;
struct is_even
{
    bool operator() (const int& value)
    {
        return (value % 2) == 0;
    }
};
struct is_odd
{
    bool operator() (const int& value)
    {
        return (value % 2) == 1;
    }
    
};


int main()
{
    list<int> number_list;
    number_list.push_back(10);
    number_list.push_back(9);
    number_list.push_back(8);
    number_list.push_back(7);
    number_list.push_back(6);
    number_list.push_back(5);
    number_list.push_back(4);
    number_list.push_back(3);
    number_list.push_back(2);
    number_list.push_back(1);
    number_list.sort();
    
    cout <<"Printing odds...." << endl;
    number_list.remove_if (is_even());
    for (list<int>::iterator it=number_list.begin(); it!=number_list.end(); it++)
        cout << ' ' << *it;
    cout << '\n';
    
    
    cout <<"Printing evens...." << endl;
    number_list.remove_if(is_odd());
    for (list<int>::iterator it=number_list.begin(); it!=number_list.end(); ++it)
        cout << ' ' << *it;
    cout << '\n';



    
    return 0;
}
 

Chris R

Member
What do you plan to do?

If it's a (fairly) simple GUI you can use Swing. I haven't used JavaFX myself.


You can use objects, to better organize your types. Though you may want to keep using numeric keys, I used text (apple, orange, etc).

Hmmn, I'll have to try this.
 

Ambitious

Member
I just remembered a project I worked on many years ago, and thought I could share a few things about it:

In the fourth year of highscool, we were supposed to do a year-long project in a group of three. There was no restriction for the kind of project, it was just to learn how to do a software project in a team. It had to be in Java, though. We decided to work on a Super Mario Bros clone - more specifically, a mix between SMB1 and Syobon Action (the first level was a modified SMB level 1 to ease players into the game, the others were created by us).

One of my teammates found a simple Java 2D engine, which took us a while to get used to. While we were trying to figure out physics and movement, we used a small test level created manually in code. Unfortunately I don't have access to the source code anymore, but it was something like this:

Code:
Mario m = new Mario(2, 1);
for(i=0; i<screenWidth; i++)
  new Block(i, 0);
  
new Coin(10, 5)
//and so on

Of course, creating the actual levels like this would have been ridiculous. As I was in charge of level design, I needed a simple method to quickly create and modify levels so I could use an iterative, experimental approach and quickly adjust any component of the level. And here's what I came up with kinda looked like:

Code:
LevelBuilder levelBuilder = LevelBuilder.startBuildingLevel("smb_level1");

// b = block, m = Mario, x = coin block, g = Goomba, c = coin, p = flag pole, f = flag

levelBuilder.buildRow("                                                       g     g                           "); // not the whole level, obviously
levelBuilder.buildRow("                                                     bbbbbbbbbbbb   bbbbx         f      ");
levelBuilder.buildRow("                          x                                                       p      ");
levelBuilder.buildRow("                                                        ccccc                     p      ");
levelBuilder.buildRow("                   x    bxbxb                   bxb                   bxb         p      ");
levelBuilder.buildRow("                                                                                  p      ");
levelBuilder.buildRow("  m                        g                                                      p      ");
levelBuilder.buildRow("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");

Level level1 = levelBuilder.build();

The entire level, visually depicted in source code. Need to add a new block or coin? Just add another letter at the position you want. Back then, I though this was pretty neat.

But obviously, there are many issues with this code. Off the top of my head:
  • Levels are data. Independent of how their content is actually represented, they should be in separate files, not in the source code.
  • Depending on the editor font, the aspect ratio may be off.
  • An upper limit on how many different objects you can use (number of different characters allowed in a Java string)
  • No way to directly reference specific objects. If, for example, one Goomba should walk to the right instead of left, you'd need to use another letter.
  • It assumes that every object has the size 1x1. If you want to create bigger objects, like the castle at the end of SMB1's first level, you'd either need different letters for each part, or just use a single letter and draw the object around it, which would like weird in the level code above.
  • Changing anything in a level requires recompilation.

However, for the scope of our game, this was perfectly fine. None of the points above was an issue for neither me nor my teammates. But nowadays I certainly wouldn't do it this way.
 

Water

Member
How do you feel about Windows/Linux dual booting vs Windows + Linux VM?
I've been dualbooting to Windows a bit from my primary OS X machine, and I don't like it. I want to stick to a "home environment" with all my key data, communications, etc. - different jobs, studies, personal stuff - without having to shut it down or sync with another OS.

I haven't needed to run Linux on my personal computers thus far, or run anything in a VM, but virtualized Linux seems to me like a sane and maintainable way to get good and solid console and dev tools running. I'm supposing it isn't hard to set up. My limited experience with git app -packaged shells and cygwin on Windows has been that they feel bad to use and stuff doesn't quite work as expected. Without virtualization I don't think Windows-based solutions have access to fresh programming tools like Linux or OS X do.

Still I'm not convinced I want to fully jump into Windows. A conservative approach would be to plan on keeping my Air for now, and buy another laptop that is at least initially only for graphics + game dev and handle gaming as a bonus. Something like a Lenovo Y50 or Gigabyte P34G v2 could work.
 

traveler

Not Wario
I'm thinking of trying to pick up a bunch of the web design basic tools. If someone were to want to learn Javascript, HTML, and CSS, what would be the most optimal order for learning them? (I ask because I've looked at resources before but found the tutorials for each assuming some knowledge of the other- is there a good progression or is there going to be some interdependence no matter what?)
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I've heard HTML --> CSS --> Javascript

But I'm not sure how reliable that is.
 

Rapstah

Member
CSS is much more tied to HTML than Javascript, but you won't understand what the hell you're doing in CSS until you know HTML. HTML -> CSS -> Javascript makes sense.
 
I'm lucky I had enough HTML/CSS under my belt for this project cause I was thrown into creating a dynamic website with a database in php. Without knowledge of html I would have been fucked.
 

Garcia

Member
I suppose I could say that the very first "game" I coded was a text based Slot Machine (which I did last night). Extremely basic, but it works!

Things keep getting harder and more complex, but at the same time I'm enjoying things more and more with each new tool learned.

(I also did that C++ sneaky peek once more and things look even clearer than the last time. Won't look any further into that language until I reach a really proficient level in Java.)
 

BreakyBoy

o_O @_@ O_o
For those of you looking to run development environments in a VM, I highly recommend looking into Vagrant.

I do DevOps, and we build/manage a customized PaaS solution, which means supporting a lot of different apps built across many different environments. At this point, I can use Vagrant to spin up a micro version of whatever I want on my laptop, with little fuss. We even use the same tool to spin up mock multi-node clusters in AWS for testing.

I don't even keep the VMs around when I close up for the end of the day. I generally just destroy them and rebuild whatever I need in the morning. Other tools around Vagrant like Veewee make that easy.

The site I linked should be enough to get started, but if anyone wants some pointers, I'd be happy to point you in the right direction.
 

Jackben

bitch I'm taking calls.
I have no idea what the hell is going wrong here and it's really frustrating me, as I am stuck on only the first and most simplistic step of my current project. Visual Studio keeps giving me errors that say:

error LNK2019: unresolved external symbol "public: int __thiscall Race::GetValidIntegerConsole(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?GetValidIntegerConsole@Race@@QAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Race::promptForContestantNumbers(void)" (?promptForContestantNumbers@Race@@QAEXXZ)

&

error LNK1120: 1 unresolved externals
I have no idea what these mean and google has not been helpful. I'm certain I selected the right project type at the start so I'm kind of just stuck.

Problem code header file and cpp pasted here.
 
I have no idea what the hell is going wrong here and it's really frustrating me, as I am stuck on only the first and most simplistic step of my current project. Visual Studio keeps giving me errors that say:

I have no idea what these mean and google has not been helpful. I'm certain I selected the right project type at the start so I'm kind of just stuck.

Problem code header file and cpp pasted here.

uh, you declared GetValidIntegerConsole to be a method of class Race in the header, but you couldn't tell that from the implementation. Hence, there's an unresolved external symbol of Race::GetValidIntegerConsole since the implementation does not define GetValidIntegerConsole in the scope of the Race class.
 

Jackben

bitch I'm taking calls.
Wow and I just spent two hours rewriting those methods in different ways thinking the way I was using the methods was invalid in some way. This is why I am terrible at programming.

Thank you for catching that error, I'm stupid but grateful.
 

Exuro

Member
This isn't a programming question per say but I was wondering if anyone could give me tips on improving a dumb/simple algorithm for elevators. My current program starts every elevator on floor one, and people are generated 1/3 1-r, 1/3 r-1, and 1/3 r-r(generation floor-destination floor, r is random). The elevators simply go from floor 1 to the top and back down, checking to see if anyone if going in the same direction and lets them on. Then when it reaches someones destination floor they get let off. Each elevator is unlimited. Just need some general ideas. Right now I'm thinking that I'll want some number of elevators to stay near the bottom floor since 1/3 are generated there alone but I don't know how much if any of an improvement that'll provide. Any ideas would be appreciated.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Keep some elevators on the bottom floor, some at the middle.

Theoretically, given an actual office building you could model when employees are going to which floors from where, then put elevators near those places ahead of time to minimize deadtime.

Since you're using a simple function to create occupants, you can probably graph out the distribution in Wolfram Alpha to visualize the average floor that occupants enter the elevator. I'm not a stats guy so I can't get any more specific than that. Alternatively, you can code a genetic learning algorithm that randomly generates floors for the elevators to start on, runs it a hundred times while recording the number of moves made from floor to floor, and then does it again, until you distill the golden numbers that maximize elevator efficiency.
 
This isn't a programming question per say but I was wondering if anyone could give me tips on improving a dumb/simple algorithm for elevators. My current program starts every elevator on floor one, and people are generated 1/3 1-r, 1/3 r-1, and 1/3 r-r(generation floor-destination floor, r is random). The elevators simply go from floor 1 to the top and back down, checking to see if anyone if going in the same direction and lets them on. Then when it reaches someones destination floor they get let off. Each elevator is unlimited. Just need some general ideas. Right now I'm thinking that I'll want some number of elevators to stay near the bottom floor since 1/3 are generated there alone but I don't know how much if any of an improvement that'll provide. Any ideas would be appreciated.

Basicly use fuzzy-logic in your elevator control algorithm - assuming that more people come from the bottom is like saying "right before lunch break" more people will be on floor X.
 

Ya no

Member
Could someone possibly walk through what exactly this chunk of code is doing? It's from a program to encrypt a string using the vigenere cipher the user inputs along with a key.

Code:
               for (int i = 0, j = 0; i < upperText.length(); i++)
               {
                  char c = upperText.charAt(i);
                  
                  if (c < 'A' || c > 'Z') continue;
                     result += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
                     
                  j = ++j % key.length();
               }

Thanks
 

BreakyBoy

o_O @_@ O_o
Could someone possibly walk through what exactly this chunk of code is doing? It's from a program to encrypt a string using the vigenere cipher the user inputs along with a key.

I've never worked with a vigenere cypher, but this seems pretty straightforward. The loop seems to iterate over each character of upperText, and also iterates over each character of the key to encrypt it with the cypher. For clarity, I'm assuming that the system is using ASCII for numerical representation of characters, although this seems to be written in a way to not depend on that specifically.

- line 1: - iterates over each character of upperText

Your counter 'i' is used to point to the index of the character being evaluated in upperText, and is incremented by one for each iteration.

- line 3: - isolates the current character of upperText being evaluated into the variable 'c'
- line 5: - Checks to see if the current character is outside of the range [A-Z]

If so, it skips any further evaluation of the character by skipping the rest of the loop body, and goes to the next character/iteration of the loop (back to line 1, to increment the counter 'i', and evaluate the conditional statement)

- line 6:

Let's break it down:

Code:
[b](c + key.charAt(j) - 2 * 'A')[/b]
This looks like it adds the numerical value of the evaluated character 'c' to the numerical value of the current 'j' index of the 'key' string, and then subtracts the product of 2 and the numerical value of 'A' (e.g. in ASCII, 'A' == 65).

This would effectively encrypt the character, but to make sure that the resulting value falls within range of the characters needed (i.e. [A-Z])...

Code:
((c + key.charAt(j) - 2 * 'A')[b] % 26 + 'A'[/b])
...the value is modded by 26 (the length of the range), which will always give you a number between 0 and 25.

The numerical value of 'A' is then added to your modded value to make sure that it falls within the appropriate range of characters (e.g. in ASCII, [A-Z] == [65-90]).

The resultant value, at this point, is still an integer, so to get the character value of this,

Code:
[b](char)[/b]((c + key.charAt(j) - 2 * 'A') % 26 + 'A')

the resultant value is casted into a char type.

Code:
[b]result += [/b](char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');

This char value is then concatenated to the end of the 'result' string.

- line 8:

Here is where it increments the counter 'j', which is used to iterate over each character in the 'key' string. Note that it not only increments the counter by one, but it also mods this value against the length of the 'key' string.

What this does, is makes sure that if the index 'j' goes beyond the length of the key, it will loop the index 'j' back to the beginning of the 'key' string.

The result of this should be your encrypted string in the variable 'result'.

I'm sure if I missed something, or completely misinterpreted some logic, one of the other fine people here will jump on to help clarify.
 

Slo

Member
Most NoSQL databases are not ACID compliant if that's what you want to know. Some are eventually consistent, and there is FoundationDB which takes a different approach to it's scaling which allows ACID transactions.

Thanks for the response. Most of the questions I had were explained after reading up on sharding and the distribution of data. After doing some reading it makes more sense.
 

Ya no

Member
Very helpful post (didn't want to quote the whole thing just a post later)

Thank you! This is exactly what I was hoping for. I'd never used the continue after an if statement before, but I get what it's purpose there is now. Your entire explanation was incredibly helpful, especially line 6, many thanks!
 

Slavik81

Member
Could someone possibly walk through what exactly this chunk of code is doing? It's from a program to encrypt a string using the vigenere cipher the user inputs along with a key.

Code:
               for (int i = 0, j = 0; i < upperText.length(); i++)
               {
                  char c = upperText.charAt(i);
                  
                  if (c < 'A' || c > 'Z') continue;
                     result += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
                     
                  j = ++j % key.length();
               }

Thanks
That's some brutal indenting on result. I didn't even notice the continue the first time I read that code.
 
Thanks for the response. Most of the questions I had were explained after reading up on sharding and the distribution of data. After doing some reading it makes more sense.
Missed this the first time around, but I kinda know a lot about NoSQL. Have worked on it for the better part of 4 years of my professional career, and I'm writing an open source one (distributed key-value store) right now. So if you have further questions, feel free to holler.
 

BreakyBoy

o_O @_@ O_o
That's some brutal indenting on result. I didn't even notice the continue the first time I read that code.

Agreed. It's terrible, and completely counterintuitive, as it indicates that the line follows from a true result on the conditional.

Remove the indenting and it's instantly much easier to read at first glance.
 
Hey Neogaf, I'm prepping for job interviews that require Java, SQL, Ruby on Rails.

How do I stand out as a competent candidate? I'm not so great at interviews, but I would like to learn the trivial questions and skills so I at least have something to show for.
 

BreakyBoy

o_O @_@ O_o
Hey Neogaf, I'm prepping for job interviews that require Java, SQL, Ruby on Rails.

How do I stand out as a competent candidate? I'm not so great at interviews, but I would like to learn the trivial questions and skills so I at least have something to show for.

Unfortunately, I don't actually have much experience with technical interviews, but I would think it depends on if the job is entry level or higher.

Did the posting ask for the applicant to have a certain amount of experience with those? Or are they expecting someone with just a general skill set straight out of school?
 

maeh2k

Member
Hey Neogaf, I'm prepping for job interviews that require Java, SQL, Ruby on Rails.

How do I stand out as a competent candidate? I'm not so great at interviews, but I would like to learn the trivial questions and skills so I at least have something to show for.

I'm not sure there are any trivial questions you can really prepare for. In my recent round of job interviews, each interview was completely different. There was virtually no overlap and no 'typical' interview questions.

I'd suggest you read the book Clean Code. I think it helps a lot with seeming competent at Java and might give you an edge for any programming tasks.
 
Hey Neogaf, I'm prepping for job interviews that require Java, SQL, Ruby on Rails.

How do I stand out as a competent candidate? I'm not so great at interviews, but I would like to learn the trivial questions and skills so I at least have something to show for.

In person or phone?

Either way just review the OO concepts and be able to explain those. I've had them come up a few times.
 
Stupid question but I can't find it easily online. How do you search for only partial match of a string? Basically I have a string for a file path and based on one section of the file path I want a certain action to happen. I know how to compare full strings but not when I just want a match in the middle of the string. I know I've done it before but I forget.
 

phoenixyz

Member
Stupid question but I can't find it easily online. How do you search for only partial match of a string? Basically I have a string for a file path and based on one section of the file path I want a certain action to happen. I know how to compare full strings but not when I just want a match in the middle of the string. I know I've done it before but I forget.

The language agnostic way would be using a regular expression I think. But for example in python you could just do
Code:
>>> "is" in "this is a string!"
True
>>> "not" in "this is a string!"
False
so there might be an easier way depending on what you're using.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Wow, that reads like a real sentence.

No wonder so many people get wet at the mention of Python.
 
Wow, that reads like a real sentence.

No wonder so many people get wet at the mention of Python.

Yup, its what makes python so appealing to many.

The language agnostic way would be using a regular expression I think. But for example in python you could just do
Code:
>>> "is" in "this is a string!"
True
>>> "not" in "this is a string!"
False
so there might be an easier way depending on what you're using.

I don't know if you can help but I'm using VBA. They choose a file, I use that file path to update the data based on that month. So I have to take a variant and turn it into a string and then look for a specific value. InStr exists but it just returns the index value for where the match starts if it finds a match so I'm kind of confused now.
 

BreakyBoy

o_O @_@ O_o
I don't know if you can help but I'm using VBA. They choose a file, I use that file path to update the data based on that month. So I have to take a variant and turn it into a string and then look for a specific value. InStr exists but it just returns the index value for where the match starts if it finds a match so I'm kind of confused now.

http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx

Like you said, InStr returns the index value for where the match starts. The index value would be in the range of 1 to the length of the string being checked. If no match is found, then it will return 0.

So, your best bet is to test if the return value of your InStr call is 0. If it's 0, no match found. If it's greater than 0, a match was found.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Wow, that reads like a real sentence.

No wonder so many people get wet at the mention of Python.

It's pretty damn easy to read and write.

Generic question though, what are the main disadvantages in using Python?
 
http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx

Like you said, InStr returns the index value for where the match starts. The index value would be in the range of 1 to the length of the string being checked. If no match is found, then it will return 0.

So, your best bet is to test if the return value of your InStr call is 0. If it's 0, no match found. If it's greater than 0, a match was found.

Sorry for another question but I wanted to do cases. Say there twelve, one for each month... How would I go about it? I was thinking easiest is to see if there's a match, if there is save the actual string that matches and then use that string to compare to cases to have certain functions run. am I going about this the wrong way?
 
It's pretty damn easy to read and write.

Generic question though, what are the main disadvantages in using Python?
I assume flexibility? High programming languages usually give less flexibility in how to do things no? I'm pretty sure it also takes a lot more overhead to run because its high level and not low level that you can control more but is more time consuming to write.
 

phoenixyz

Member
It's pretty damn easy to read and write.

Generic question though, what are the main disadvantages in using Python?

It's an interpreted language, so it's not exactly lightning fast. Also while dynamic typing is a godsend in smaller programs, it makes stuff unnecessarily error prone in bigger projects.
 

BreakyBoy

o_O @_@ O_o
Sorry for another question but I wanted to do cases. Say there twelve, one for each month... How would I go about it? I was thinking easiest is to see if there's a match, if there is save the actual string that matches and then use that string to compare to cases to have certain functions run. am I going about this the wrong way?

I'm not intimately familiar with VBA (last time I wrote VB anything was VB6), but off the top of my head, it sounds like your method would have the program:

- Search the file for a name for a month
-- 1-12 conditional checks, depending on if it finds it on the first try, or the last try

- If there's a match:
-- Save the matched substring
-- Determine which month name matches the substring
--- 1-12 conditional checks, depending on if it finds it on the first try, or the last try

-- If there's a match:
--- Run the associated function

It seems like you're doubling your potential work there. Why not just have a series of conditionals that from the get go run the function you want if it matches a specific month?

Again, I don't remember my VB syntax, but more or less:
Code:
if InStr(StringToSearch, 'January') > 0 then
  call JanuaryFunction();
else if InStr(StringToSearch, 'February') > 0 then
  call FebruaryFunction();
else if InStr(StringToSearch, 'March') > 0 then
  call MarchFunction();
...
else if InStr(StringToSearch, 'December') > 0 then
  call DecemberFunction();
end

That way you limit the possible number of searches to one set of [1-12]. Not to mention it should be less code to write?

I mean, there could be reasons this wouldn't work, but based on the information you've given, I think that might be a better method.
 
That definitely works, it just felt like I was missing something to automate it more than just doing a bunch of if statements. It's not even bad for if statements since I can use the instr and any >0 is a match to execute the code. Thought maybe that many ifs was too much overhead vs a loop or case structure.
 

tokkun

Member
It's pretty damn easy to read and write.

Generic question though, what are the main disadvantages in using Python?

-Python code relies a lot on libraries, and in the past Python has been more willing to change built-in library APIs in ways that break legacy code.
-More reliance on dynamic error checking and less on static analysis.
-Performance and memory use may be worse than languages that compile to native machine code.
-Attaching semantic significance to whitespace can cause problems if you are not careful.
 
God dammit I hat ethics program. It's just an entry building block and will not fucking work.

Code:
linkcash = application.GetOpenFilename(, , "please choose file")

linkcash = Cstr(linkcash)

If temp = Instr(linkcash, "2014-04") Then
   Msgbox ("April 2014")

I have more else if for other months but it comes back April 2014 even if the file path has 2014-05... I even had it print the string after it and it says 2014-05 in the link but returns April 2014. I'm at a loss.
 

BreakyBoy

o_O @_@ O_o
That definitely works, it just felt like I was missing something to automate it more than just doing a bunch of if statements. It's not even bad for if statements since I can use the instr and any >0 is a match to execute the code. Thought maybe that many ifs was too much overhead vs a loop or case structure.

Yeah, you can definitely wrap that sort of thing in a loop or case structure too. If it were in Ruby for instance, you could do something like this:

Code:
def runMonth(month)
  case month
  when 'January'
    JanuaryFunction
  when 'February'
    FebruaryFunction
  when 'March'
    MarchFunction
  ...
  when 'December'
    DecemberFunction
  end
end

# Main logic
MONTHS = %w[January February March April May June July August September October November December]

MONTHS.each do |month| 
  runMonth(month) if stringToSearch.include?(month)
end

Again though, that makes it do twice as many conditional checks. However, this might be a more maintainable/legible solution, and the impact on actual real-world performance might be negligible.

What works best for you is highly dependent on your situation. Legibility vs. performance, etc. If you're working on a small program, with a non-enormous data set though, I find that the KISS method (Keep It Simple, Stupid), is usually the best approach.
 
Code:
linkcash = application.GetOpenFilename(, , "please choose file")

linkcash = Cstr(linkcash)

If temp = Instr(linkcash, "2014-04") Then
   Msgbox ("April 2014")

What are you trying to do with temp? If it's an uninitialized variable and you don't have Option Explicit on, it will default to 0 and your comparison be true when linkcash doesn't contain 2014-04. You're essentially saying

Code:
If 0 = 0 Then
    MsgBox "April 2014"
End If
 
Top Bottom