Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

SELECT * FROM posts WHERE tid = 'PA PROGRAMMING THREAD'

16465676970100

Posts

  • bowenbowen Registered User regular
    Highball question, anyone familiar with querying and processing results with CDatabase back in MFC? I can't really recall, I apparently am using CDatabase properly (I can connect just fine) but I can't figure out how to pass a query and process the results.

    I'm assuming it uses CRecordset ? But how?

  • bowenbowen Registered User regular
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?

  • urahonkyurahonky Registered User regular
    I don't know if you guys listen to music while you program, but I do. And this song came on my Pandora radio station and had to share.
    Spoiler:

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • admanbadmanb the bored genie Seattle, WARegistered User regular
    Daft Punk is great coding music.

    twitter, github, resume/portfolio, if you like to play or host boardgames online, check out handtracker
  • bowenbowen Registered User regular
    Mozart and Bach all up ins.

    I'm classy motherfuckers.

  • urahonkyurahonky Registered User regular
    bowen wrote: »
    Mozart and Bach all up ins.

    I'm classy motherfuckers.

    I have it set to shuffle all which includes my classical station. Just great to have a variety of music to code to.

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • IncindiumIncindium Registered User regular
    edited April 2012
    bowen wrote: »
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?


    You need to derive a custom class from CRecordset from what I remember doing... Here is something from some legacy code I pulled up...

    from the .h file
    Spoiler:

    from .cpp file
    Spoiler:


    From where you'd actually use it in code.
    Spoiler:

    Incindium on
    steam_sig.png
    Diablo 3 Profile
    Nintendo ID: Incindium
    Hex TCG: Incindium
  • GnomeTankGnomeTank Registered User regular
    My coding music varies from American hard rock like Chevelle, 10 Years and Breaking Benjamin, to heavy metal like Killswitch Engage, Pantera and Atreyu, to softer alt rock like Coldplay and Young the Giant, to darker, harder electronic stuff like dub step, drum and bass and electro house.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, D3: Brainling#1998, NintendoID: Brainling
  • urahonkyurahonky Registered User regular
    GnomeTank wrote: »
    My coding music varies from American hard rock like Chevelle, 10 Years and Breaking Benjamin, to heavy metal like Killswitch Engage, Pantera and Atreyu, to softer alt rock like Coldplay and Young the Giant, to darker, harder electronic stuff like dub step, drum and bass and electro house.

    There's a 90's hip hop station that I've started listening to that is pretty awesome to program to. I tried Smooth Jazz, but it was TOO relaxing. I need something to keep me going.

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • urahonkyurahonky Registered User regular
    Just got wind that I'll be shifting over to another project. Sounds like we don't think we'll be getting any more money out of my current project to keep 3 people working on it until September.

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • iTunesIsEviliTunesIsEvil Registered User regular
    "Wellllllllp, looks like this unwieldly, out-of-hand project's going down the crapper! Thanks for your hard work, honky. Now, on to this completely different project where that TOTALLY will NOT happen this time. Promise. Scout's honor."

  • admanbadmanb the bored genie Seattle, WARegistered User regular
    At least that's the best way for a "we don't have enough money..." situation to go.

    twitter, github, resume/portfolio, if you like to play or host boardgames online, check out handtracker
  • bowenbowen Registered User regular
    edited April 2012
    Incindium wrote: »
    bowen wrote: »
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?


    You need to derive a custom class from CRecordset from what I remember doing... Here is something from some legacy code I pulled up...

    Thanks @Incidndium I actually got it before I checked back here. Here's what I did:
    CDatabase db;
    LPCTSTR connectionString = _T("... My database stuff here...");
    db.OpenEx(connectionString, CDatabase::openReadOnly | CDatabase::noOdbcDialog);
    
    wchar_t query[256];
    swprintf(query,L"SELECT dnStr FROM personnel WHERE emp_user ='%s'",user);
    
    CRecordset rs(&db);
    rs.Open(CRecordset::forwardOnly,query);
    CDBVariant varValue;
    
    if(!rs.IsEOF())
    {
        rs.GetFieldValue((short)0,varValue);
    }
    
    MultiByteToWideChar(CP_ACP,0,*varValue.m_pstringA,strlen(*varValue.m_pstringA),userDN,sizeof(userDN));
    
    rs.Close();
    db.Close();
    

    Also, yes, I live dangerously.

    bowen on
  • bowenbowen Registered User regular
    Count your blessings honky, count them.

  • IncindiumIncindium Registered User regular
    LPCTSTRs and wchar_ts and CDBVariants, Oh My!

    Ha... I'm glad I don't actively work with C++/MFC anymore.

    steam_sig.png
    Diablo 3 Profile
    Nintendo ID: Incindium
    Hex TCG: Incindium
  • bowenbowen Registered User regular
    I was judiciously using wchar_t too to save from the random smattering of MFC types. I gave up at this point though. On the plus side my interfacing DLL is functioning properly in place of the old one that was broken and good golly do I not want to deal with MFC ever again.

    It's like throwing up, you go 10 years without doing it and suddenly you're like hey why not, and then you realize that's a terrible idea.

  • bowenbowen Registered User regular
    And for some reason it wouldn't give me an ASCII string no matter how hard I tried to get it without the DBVariant, seriously fuck you MFC, fuck you.

  • wildwoodwildwood Registered User regular
    @Cantido - check out this link - stackoverflow.com/questions/6969841/adding-enum-type-to-a-list - there's an example response partway down that shows you how to declare the ArrayList so that you can add any kind of enum to it. Hopefully that helps.

    (All I did to find that link was google "java enum arraylist", and scan the results for answers from StackExchange. Develop your google-fu... feel the power... :) )

  • Jimmy KingJimmy King Registered User regular
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • CantidoCantido Registered User regular
    Solid Steel Podcast, Blind Guardian, Amon Amarth, Portal (the Aussie cthulu band, not the game
    wildwood wrote: »
    @Cantido - check out this link - stackoverflow.com/questions/6969841/adding-enum-type-to-a-list - there's an example response partway down that shows you how to declare the ArrayList so that you can add any kind of enum to it. Hopefully that helps.

    (All I did to find that link was google "java enum arraylist", and scan the results for answers from StackExchange. Develop your google-fu... feel the power... :) )

    Okay, that's what my problem was: you can't ArrayList an enum, instead that example shows that you can make an ArrayList of strings composed of enum values. That's fantastic, and just what I need.

    steam_sig.png
  • VerboseVerbose Registered User regular
    edited April 2012
    Does anyone know anything about Java Applets? I'm making a few board games as part of a project for school, and I am tearing my hair out right now trying to understand why my applet wont display any graphics. On a small testing scale I can get it do draw grids and pieces easily enough but when I implement it into my game program it just doesn't display anything.
    If anyone can help, I can provide more details.

    Verbose on
    steam_sig.png
  • SaerisSaeris Chronogestaltist Trinity, New MexicoRegistered User regular
    edited April 2012
    Jimmy King wrote: »
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

    Oh wow. I didn't think something as useful as /r would be so new. On the other hand, maybe I'm missing some more common idiom for what I'm doing.

    What's the usual Perl way to pull a single pattern match? For instance, if you have the string "abcdef", how would you get the single capture from the pattern "bc(.)e" as a return value, such that you can use it when defining a hash?

    In Lua this would be:
    local hash = { d = string.match("abcdef", "bc(.)e") }
    

    But the closest I've gotten in Perl 5.8.8 is two lines:
    my ($d) = ("abcdef" =~ m/bc(.)e/);
    my $hash = { d => $d };
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    Saeris on
    Nlgya.png
  • InfidelInfidel Too easy. PiltoverRegistered User regular
    Saeris wrote: »
    Jimmy King wrote: »
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

    Oh wow. I didn't think something as useful as /r would be so new. On the other hand, maybe I'm missing some more common idiom for what I'm doing.

    What's the usual Perl way to pull a single pattern match? For instance, if you have the string "abcdef", how would you get the single capture from the pattern "bc(.)e" as a return value, such that you can use it when defining a hash?

    In Lua this would be:
    local d = { capture = string.match("abcdef", "bc(.)e") }
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    I don't think I'm understanding you right, can you explain again or give a different example?

    TwitchTV channel: OrokosPA check.php?c=OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • SaerisSaeris Chronogestaltist Trinity, New MexicoRegistered User regular
    edited April 2012
    Yeah, I edited in some more details. Basically, I'm trying to combine those two Perl lines above into one, like in the Lua example, but I don't know how to get a scalar return value out of that pattern match. I can only get it to return either a list (as it does now, with the surrounding parentheses) or the number of matches (without the parentheses).


    edit: Oh, duh. I didn't even realize you could subscript an anonymous array context:
    my $hash = { d => ("abcdef" =~ m/bc(.)e/)[0] };
    

    That works exactly as I was hoping it would.

    Saeris on
    Nlgya.png
  • InfidelInfidel Too easy. PiltoverRegistered User regular
    edited April 2012
    dp

    Infidel on
    TwitchTV channel: OrokosPA check.php?c=OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • InfidelInfidel Too easy. PiltoverRegistered User regular
    edited April 2012
    Saeris wrote: »
    But the closest I've gotten in Perl 5.8.8 is two lines:
    my ($d) = ("abcdef" =~ m/bc(.)e/);
    my $hash = { d => $d };
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    Does something like this work?
    my %hash = ( "d" => ("abcdef" =~ m/bc(.)e/g)[0] )
    

    Infidel on
    TwitchTV channel: OrokosPA check.php?c=OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • SaerisSaeris Chronogestaltist Trinity, New MexicoRegistered User regular
    This was one of those cases where just the act of describing the problem in writing helped to solve it. Thanks!

    What a nifty little language, though. Hard to believe that something as ugly as PHP was "inspired" by it.

    Nlgya.png
  • GnomeTankGnomeTank Registered User regular
    Have you seen any bad Perl? Because from that post, I don't think you have.

    Should we burst his bubble now guys, or let him marinate in it for a while before we link to the Perl obfuscation competition?

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, D3: Brainling#1998, NintendoID: Brainling
  • SaerisSaeris Chronogestaltist Trinity, New MexicoRegistered User regular
    Indeed, I fear I'm unindoctrinated in the horrors of the language. I imagine that will come crashing down upon me soon enough.

    Nlgya.png
  • Jimmy KingJimmy King Registered User regular
    admanb wrote: »
    At least that's the best way for a "we don't have enough money..." situation to go.

    Yeah, that's how I try to look at those things. I don't care if you ever use the code I write or not as long as you're willing to pay me to keep writing it.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • Jimmy KingJimmy King Registered User regular
    Saeris wrote: »
    Indeed, I fear I'm unindoctrinated in the horrors of the language. I imagine that will come crashing down upon me soon enough.
    I spent about 5 years as a full time Perl developer. I love Perl. Well written Perl is awesome. Bad Perl is a thing of horrors that you cannot imagine, though. It's also really easy to accidentally write bad Perl because it has so much awesome voodoo that is easy to abuse and assume everyone will be able to follow.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • admanbadmanb the bored genie Seattle, WARegistered User regular
    edited April 2012
    It is important to distinguish between languages like Perl (and C) which is a fine language that makes it easy to do bad things, and PHP, which is a bad language.

    admanb on
    twitter, github, resume/portfolio, if you like to play or host boardgames online, check out handtracker
  • Jimmy KingJimmy King Registered User regular
    Yeah, definitely. Some languages, like PHP, are just poo. I die a little inside every time I have to go do some nonsense in PHP at work. It's being phased out, but for now there's a bit there... on Windows IIS servers, just to make it extra fun.

    import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.stringreturners.StringStringReturner;
  • EvigilantEvigilant Registered User regular
    edited April 2012
    I'm having difficulty solving this. Without having to copy all the code, this is what I understand to be the basics:
    Socket clientReader = new Socket(//predetermined port that server is listening to);
    Socket clientWriter = new Socket(//predetermined port that server is listening to);
    //in client
    ObjectInputStream in = new ObjectInputStream(clientReader.getInputStream());
    run(){
      while(true){
        String message = (String)in.readObject();
        System.out.println(message);
      }
    }
    
    
    //server
    Socket serverReader = new Socket(//client write socket);
    Socket serverWriter = new Socket(//client read socket);
    //in server
    sendMessage(String message){
       ObjectOutputStream out = new ObjectOutputStream(serverWriter.getOutputStream());
       out.flush();
       out.writeObject(message);
    }
    
    
    //service fetcher
    Socket ServiceFetchWrtier SFW = new Socket(//server reader socket);
    Socket ServiceFetchReader SFR = new Socket(//server write socket);
    
    //In service fetcher
    sendMessage(String message){
        ObjectOutPutStream out = new ObjectOutputStream(SFW.getOutputStream());
        out.flush();
        out.writeObject(message);
    }
    
    Will that print out service fetcher's message to client? My question then is, how would I take the input from the client and pass it to a module the service fetcher has fetched and executing and awaiting input? Is the answer to pass along serverReader and ServerWriter sockets to a module that's being executed and use those for input and output? So a constructor would look like:
    //Service Fetcher Constructor
    public ServiceFetcher(Socket serverReader, Socket serverWriter, int command){
      ObjectInputStream in = new ObjectInputStream(serverReader.getInputStream());
      ObjectOutputStream out = new ObjectOutputStream(serverWriter.getOutputStream());
      out.flush();
    
      if(//command == service number){
            service(serverReader, serverWriter);
       }
       in.close();
       out.close();
    }
    

    Would something like that work?

    Or do I just put them all in a package and pass the server object to the service fetcher, and then do something like:
    Public ServiceFetcher(Server MAINSERVER, int command){
      this.server = MAINSERVER;
      if(//command == service number){
          service(MAINSERVER);
          sendMessage("Executing service: "+command);
      }
    }
    sendMessage(String message){
       server.sendMessage(message);
    }
    

    Evigilant on
    "I hate war as only a soldier who has lived it can, only as one who has seen its brutality, its futility, its stupidity." Dwight D. Eisenhower
    Google+ Profile Origin: 13Evigilant Steam: Evigilant
  • SaerisSaeris Chronogestaltist Trinity, New MexicoRegistered User regular
    edited April 2012
    admanb wrote: »
    It is important to distinguish between languages like Perl (and C) which is a fine language that makes it easy to do bad things, and PHP, which is a bad language.

    I cannot resist linking to PHP: a fractal of bad design.
    I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.

    You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.

    You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

    You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.

    And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.

    Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.

    That’s what’s wrong with PHP.

    For extra fun, search that page for "INT_MAX".

    Saeris on
    Nlgya.png
  • Mike DangerMike Danger "Diane..." a place both wonderful and strangeRegistered User regular
    So, here's where I'm at right now with this project.

    I have a little Ruby program that takes in two files: a "degree" spec and a list of the user's courses. A degree is broken up into requirements. A requirement has a name ("200 level courses"), a quantity (4), and a list of courses which can satisfy that requirement. (CSCI210, CSCI250, CSCI280, etc) The Ruby program reads the degree spec and the list of courses and figures out what's left.

    My vision is that the user comes to the app, picks their major, and then clicks a button for each course they've completed in the major, then gets a message showing them what they have left to do.

    So, looking at what I have set up for myself, it seems like I'm going to need to be storing stuff in a database for later retrieval? Show the page for the user, hit the DB to get the degree spec, display the course options, do the logic, display the result.

  • admanbadmanb the bored genie Seattle, WARegistered User regular
    Yup. Luckily, adding DB tables/Models to Rails is super easy and elegant.

    twitter, github, resume/portfolio, if you like to play or host boardgames online, check out handtracker
  • Mike DangerMike Danger "Diane..." a place both wonderful and strangeRegistered User regular
    One more Rails question: so I want to do a bunch of migrations that will set up a table for each degree. Is there a way to do this without having to type "rails generate model" over and over again? I tried doing this, but it didn't work:
    02:07: ~/rails_projects/specs $ rails console
    Loading development environment (Rails 3.2.3)
    >> fil = File.new("list.txt", "r")
    => #<File:list.txt>
    >> fil.each_line do |l|
    ?> rails generate model #{l.strip} name:string quantity:integer courses:array
    >> end
    NameError: undefined local variable or method `model' for main:Object
    	from (irb):3
    	from (irb):2:in `each_line'
    	from (irb):2
    

  • InfidelInfidel Too easy. PiltoverRegistered User regular
    The schema is the same for each degree so you shouldn't have a bunch of tables storing the same kind of thing on this scale. Add a degree ID and have them in one table?

    TwitchTV channel: OrokosPA check.php?c=OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • bowenbowen Registered User regular
    @Evigilant

    Kind of, get rid of the two sockets and get two separate streams from one socket. Then, after a client connects, wait until there's data. Check how many bytes, read it, Append it to an array or string until you get a delimiter -- you need a delimiter of sorts to know your message is done -- and then do whatever you need to do when you reach that delimiter (call a function and pass the string maybe?). I usually use something like 0xff for the delim which isn't really an ascii character (assuming we're using ascii and not unicode).

    Sending binary data becomes the fun part.

This discussion has been closed.